Skip to content

Commit 4505327

Browse files
committed
add config tutorial
1 parent dad7e65 commit 4505327

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
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 application, please see [Using Config With Pulumi](/docs/concepts/configuration#using-config-with-pulumi).
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 of your config variables 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)