Skip to content

Commit 33c7731

Browse files
authored
Merge pull request #156 from DefangLabs/linda-config-tutorial-v2
Added config tutorial (good version)
2 parents eb96b62 + f6b5591 commit 33c7731

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

docs/concepts/compose.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,21 @@ One thing to keep in mind is that, at the time of this writing, Defang identifie
2020

2121
## Configuration
2222

23-
If you have a service that depends on a secret like an api key, you can set that [secret](./configuration.md) using the CLI:
23+
If you have a service that depends on a [config value](./configuration.md) (such as an API key), you can set it using the CLI:
2424

2525
```
26-
defang config set --name MY_API_KEY
26+
defang config set MY_API_KEY
2727
```
2828

2929
and then connect it to the service by specifying it in the `compose.yaml`:
3030

3131
```yaml
3232
services:
3333
my-service:
34-
secrets:
34+
environment:
3535
- MY_API_KEY
36-
37-
secrets:
38-
MY_API_KEY:
39-
external: true
4036
```
4137
42-
:::info Configuration & Secrets
43-
Read more about configuration in the [configuration page](./configuration.md).
38+
:::info
39+
Read more about configuration in the [Configuration page](./configuration.md).
4440
:::

docs/concepts/configuration.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar_position: 225
88

99
Defang allows you to configure your application using environment variables. You can set environment variables in your [`compose.yaml` file](./compose.md), or in your [Pulumi program](#using-config-with-pulumi).
1010

11-
# Sensitive Config (aka Secrets)
11+
# Sensitive Config Values
1212

1313
The Defang CLI allows you to securely store sensitive information such as API keys, passwords, and other credentials. To do so, run:
1414

@@ -46,7 +46,7 @@ You can find a sample of how to set sensitive config values [here](https://githu
4646

4747
## Interpolation
4848

49-
Environment variables are set within the *environment* section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container.
49+
Environment variables are set within the `environment` section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container.
5050

5151
Variables can be set by assigning a literal value, a reference to a configuration value, or a mix of literal and variable references. Variable references are declared using either **\$\{variable_name\}** or **$variable_name** forms. It is recommended to use the bracketed form. By interpolating over variable references within a string we can construct complex strings. Interpolation may be particularly useful when constructing connection strings to other services.
5252

@@ -81,5 +81,6 @@ Here are the different ways sensitive config values are stored depending on the
8181
* [DigitalOcean](../providers/digitalocean#secrets)
8282
* [GCP](../providers/gcp#secrets)
8383
84-
85-
84+
:::info
85+
Please note that while Defang supports setting sensitive config, it does not support the [`secrets`](https://docs.docker.com/reference/compose-file/secrets/) top-level element as seen in the Compose specification. Please see our [Compose](/docs/concepts/compose) page for more details.
86+
:::
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
sidebar_position: 400
3+
title: Configure Environment Variables
4+
description: How to configure sensitive environment variables in Defang.
5+
---
6+
7+
# Configure Environment Variables
8+
9+
10+
This tutorial will show you how to configure sensitive environment variables in Defang.
11+
12+
## Pre-requisites
13+
* [A `compose.yaml` file in your project](https://docs.docker.com/compose/gettingstarted/)
14+
* [A Defang Account](/docs/concepts/authentication)
15+
* [The Defang CLI](/docs/getting-started#install-the-defang-cli)
16+
17+
## Step 1 - Go to your `compose.yaml` file
18+
:::info
19+
If you are using [Pulumi](/docs/concepts/pulumi) instead of Compose files to define your services, please see [Using Config With Pulumi](/docs/concepts/configuration#using-config-with-pulumi) instead.
20+
:::
21+
22+
In your Compose file, you can define a sensitive config variable for your service by leaving it as a **blank or `null` value**. Defang will recognize it as a sensitive value.
23+
24+
In the example below, let's define `API_KEY` as an environment variable.
25+
26+
```yaml
27+
services:
28+
service1:
29+
image: image1:latest
30+
environment:
31+
- API_KEY
32+
```
33+
34+
The type of notation shown above is called *list notation*. Alternatively, you can use *map notation*, which is also acceptable:
35+
```yaml
36+
services:
37+
service1:
38+
image: image1:latest
39+
environment:
40+
API_KEY:
41+
```
42+
43+
## Step 2 - Set the actual value in the Defang CLI
44+
To store the actual (sensitive) value of the variable, open up a terminal and type the command:
45+
```bash
46+
defang config set API_KEY=actualvalue
47+
```
48+
Remember to replace `API_KEY` with your variable name and `actualvalue` with your actual value.
49+
50+
:::tip
51+
You can view all the config variables you are storing in Defang by doing: `defang config ls`.
52+
:::
53+
54+
### Editing a config value
55+
To edit a value, you can run the command again with an updated value to overwrite the current value:
56+
```bash
57+
defang config set API_KEY=newvalue
58+
```
59+
60+
### Removing a config value
61+
To remove a value, run the command:
62+
```bash
63+
defang config rm API_KEY
64+
```
65+
:::tip
66+
Remember to update your Compose file if you remove an environment variable.
67+
:::
68+
69+
## Step 3 - Deploy
70+
```bash
71+
defang compose up
72+
```
73+
74+
---
75+
For a deeper discussion on how configuration works in Defang, see our [Configuration docs](/docs/concepts/configuration).

0 commit comments

Comments
 (0)