Editing components getting started

This commit is contained in:
Ori Zohar 2021-01-19 15:01:34 -08:00
parent bb8286ca6c
commit f70e76f515
3 changed files with 32 additions and 12 deletions

View File

@ -5,7 +5,7 @@ linkTitle: "Use the Dapr API"
weight: 30
---
After running the `dapr init` command in the previous step, your local environment has the Dapr sidecar binaries as well as default component definitions for both state management and a message broker (both using Redis). You can now try out some of what Dapr has to offer by using the Dapr CLI to run a Dapr sidecar and try out the state API that will allow you to store and retrieve a state. You can learn more about the state building block and how it works in [these docs]({{< ref state-management >}}).
After running the `dapr init` command in the [previous step]({{<ref install-dapr-selfhost.md>}}), your local environment has the Dapr sidecar binaries as well as default component definitions for both state management and a message broker (both using Redis). You can now try out some of what Dapr has to offer by using the Dapr CLI to run a Dapr sidecar and try out the state API that will allow you to store and retrieve a state. You can learn more about the state building block and how it works in [these docs]({{< ref state-management >}}).
You will now run the sidecar and call the API directly (simulating what an application would do).
@ -19,6 +19,8 @@ Run the following command to launch a Dapr sidecar that will listen on port 3500
dapr run --app-id myapp --dapr-http-port 3500
```
With this command, no custom component folder was defined so the Dapr uses the default component definitions that were created during the init flow (these can be found under `$HOME/.dapr/components` on Linux or MacOS and under `%USERPROFILE%\.dapr\components` on Windows). These tell Dapr to the local Redis Docker container as a state store and message broker.
## Step 2: Save state
In a separate terminal run:

View File

@ -5,18 +5,22 @@ linkTitle: "Define a component"
weight: 40
---
After familiarizing yourself with the Dapr HTTP API and state building block in the previous step, you will now create your first Dapr component to try out the [secrets building block]({{< ref secrets >}}).
In the [previous step]({{<ref get-started-api.d>}}) you called the Dapr HTTP API to store and retrieve a state from a Redis backed state store. Dapr knew to use the Redis instance that was configured locally on your machine through default component definition files that were created when Dapr was initialized.
When building an app, you most likely would create your own component file definitions depending on the building block and specific component that you'd like to use.
As an example of how to define custom components for your application, you will now create a component definition file to interact with the [secrets building block]({{< ref secrets >}}).
In this guide you will:
- Create a local json secret store
- Register the secret store with Dapr using a component
- Create a local JSON secret store
- Register the secret store with Dapr using a component definition file
- Obtain the secret using the Dapr HTTP API
## Step 1: Create a json secret store
## Step 1: Create a JSON secret store
While Dapr supports [many types of secret stores]({{< ref supported-secret-stores >}}), the easiest way to get started is a local json file with your secret.
While Dapr supports [many types of secret stores]({{< ref supported-secret-stores >}}), the easiest way to get started is a local JSON file with your secret (note this secret store is meant for development purposes and is not recommended for production use cases as it is not secured).
Begin by saving the following json contents into a file named `mysecrets.json`:
Begin by saving the following JSON contents into a file named `mysecrets.json`:
```json
{
@ -26,9 +30,14 @@ Begin by saving the following json contents into a file named `mysecrets.json`:
## Step 2: Create a secret store Dapr component
Within your default Dapr components directory create a file named `localSecretStore.yaml` with the following contents:
- Linux/MacOS: `$HOME/.dapr/components`
- Windows: `%USERPROFILE%\.dapr\components`
Create a new directory named `my-components` to hold the new component file:
```bash
mkdir my-components
```
Inside this directory create a new file `localSecretStore.yaml` with the following contents:
```yaml
apiVersion: dapr.io/v1alpha1
@ -46,12 +55,14 @@ spec:
value: ":"
```
You can see that the above file definition has a `type: secretstores.local.file` which tells Dapr to use the local file component as a secret store. The metadata fields provide component specific information needed to work with this component (in this case, the path to the secret store JSON)
## Step 3: Run the Dapr sidecar
Run the following command to launch a Dapr sidecar that will listen on port 3500 for a blank application named myapp:
```bash
dapr run --app-id myapp --dapr-http-port 3500
dapr run --app-id myapp --dapr-http-port 3500 --components-path ./my-components
```
## Step 4: Get a secret
@ -71,5 +82,12 @@ curl http://localhost:3500/v1.0/secrets/my-secret-store/my-secret
Invoke-RestMethod -Uri 'http://localhost:3500/v1.0/secrets/my-secret-store/my-secret'
```
{{% /codetab %}}
{{< /tabs >}}
You should see output with the secret you stored in the JSON file.
```
"I'm Batman"
```
<a class="btn btn-primary" href="{{< ref quickstarts.md >}}" role="button">Next step: Explore Dapr quickstarts >></a>

View File

@ -7,7 +7,7 @@ aliases:
- /getting-started/install-dapr/
---
Now that you have the Dapr CLI installed, it's time to initialize Dapr on your local machine using the CLI.
Now that you have the [Dapr CLI installed]({{<ref install-dapr-cli.md>}}), it's time to initialize Dapr on your local machine using the CLI.
Dapr runs as a sidecar alongside your application, and in self-hosted mode this means it is a process on your local machine. Therefore, initializing Dapr includes fetching the Dapr sidecar binaries and installing them locally.