Skip to content

Commit 9cffc43

Browse files
Split up docs into more pages
Closes #63
1 parent a787304 commit 9cffc43

File tree

7 files changed

+154
-134
lines changed

7 files changed

+154
-134
lines changed

docs/src/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
# User Guide
88

99
- [Key Concepts](./user_guide/key_concepts.md)
10-
- [Setting Environment Variables](./user_guide/setting_environment_variables.md)
10+
- [Setting Environment Variables](./user_guide/env/README.md)
11+
- [Dynamic Values (Files & Shell Commands)](./user_guide/env/dynamic.md)
12+
- [Multiple Values from a Single Source](./user_guide/env/multi.md)
13+
- [Adding to the PATH Variable](./user_guide/env/path.md)
14+
- [Load Values from Kubernetes](./user_guide/env/kubernetes.md)
1115
- [Inheritance & Cascading Configs](./user_guide/inheritance.md)
1216
- [Side Effects](./user_guide/side_effects.md)
1317
- [Troubleshooting](./user_guide/troubleshooting.md)

docs/src/user_guide/env/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Setting Environment Variables
2+
3+
The primary purpose of env-select is to configure environment variables. The most common way to do this is to provide static values:
4+
5+
```toml
6+
[applications.server.profiles.dev]
7+
variables = {SERVICE1 = "dev", SERVICE2 = "also-dev"}
8+
9+
[applications.server.profiles.prd]
10+
variables = {SERVICE1 = "prd", SERVICE2 = "also-prd"}
11+
```
12+
13+
Beyond these simple values, there are several ways to customize how values are computed. Read on to learn more.

docs/src/user_guide/env/dynamic.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Dynamic Values
2+
3+
If your values are not statically known, there are several ways to load dynamic values. Fore more detailed information on each option, see [the API reference](../../api/value_source.md).
4+
5+
## Shell Command
6+
7+
You can specify a shell command to generate a value. This allows you to provide values that can change over time, or secrets that you don't want appearing in the file. For example:
8+
9+
```toml
10+
[applications.db.profiles.dev.variables]
11+
DATABASE = "dev"
12+
DB_USER = "root"
13+
DB_PASSWORD = {type = "command", command = "curl https://www.random.org/strings/?format=plain&len=10&num=1&loweralpha=on", sensitive = true}
14+
```
15+
16+
When the `dev` profile is selected for the `db` app, the `DB_PASSWORD` value will be randomly generated from a URL. The `sensitive` field is an _optional_ field that will mask the value in informational logging.
17+
18+
The command is executed in the shell detected by env-select as your default (or the shell passed with `--shell`).
19+
20+
## File
21+
22+
You can also load values from a file:
23+
24+
```toml
25+
[applications.db.profiles.dev.variables]
26+
DATABASE = {type = "file", path = "database.txt"}
27+
```
28+
29+
`database.txt`:
30+
31+
```
32+
dev
33+
```
34+
35+
And now run it:
36+
37+
```sh
38+
> es run db dev -- printenv
39+
DATABASE=dev
40+
```
41+
42+
The file path will be relative to **the config file in which the path is defined**. For example, if you have two `.env-select.toml` files:
43+
44+
```toml
45+
# ~/code/.env-select.toml
46+
[applications.server.profiles.dev.variables]
47+
SERVICE1 = {type = "file", path = "service1.txt"}
48+
```
49+
50+
```toml
51+
# ~/.env-select.toml
52+
[applications.server.profiles.dev.variables]
53+
SERVICE2 = {type = "file", path = "service2.txt"}
54+
```
55+
56+
In this scenario, `SERVICE1` will be loaded from `~/code/service1.txt` while `SERVICE2` will be loaded from `~/service2.txt`, **regardless of where env-select is invoked from**.
57+
58+
This value source combines well with the `multiple` field to load `.env` files (see next section).

docs/src/user_guide/env/kubernetes.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Load Values from Kubernetes
2+
3+
If you want to load one or more values from a Kubernetes pod, you can do that with the `command` value source:
4+
5+
```toml
6+
[applications.my-service.profile.dev]
7+
variables.DB_PASSWORD = {type = "command", sensitive = true, command = "kubectl exec -n development api -- printenv DB_PASSWORD"}
8+
```
9+
10+
Loading multiple variables is easy too:
11+
12+
```toml
13+
[applications.my-service.profile.dev]
14+
variables.db_creds = {type = "command", sensitive = true, multiple = ["DB_USERNAME", "DB_PASSWORD"], command = "kubectl exec -n development api -- printenv"}
15+
```

docs/src/user_guide/env/multi.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Multiple Values from a Single Source
2+
3+
If you want to load multiple values from a single source, you can use the `multiple = true` flag. This will tell env-select to expect a mapping of `VARIABLE=value` as output from the value source, with one entry per line. Whitespace lines and anything preceded by a `#` will be ignored (this is the standard `.env` file format).
4+
5+
This means that **the key associated with this entry in the `variables` map will be ignored**.
6+
7+
```toml
8+
[applications.db.profiles.dev.variables]
9+
DATABASE = "dev"
10+
creds = {type = "file", path = "creds.env", multiple = true}
11+
```
12+
13+
`creds.env`:
14+
15+
```sh
16+
DB_USER=root
17+
DB_PASSWORD=hunter2
18+
```
19+
20+
`creds` will now be expanded into multiple variables:
21+
22+
```sh
23+
> es run db dev -- printenv
24+
DATABASE=dev
25+
DB_USER=root
26+
DB_PASSWORD=hunter2
27+
```
28+
29+
Notice the `creds` key never appears in the environment; this is just a placeholder. You can use any key you want here.
30+
31+
## Filtering Loaded Values
32+
33+
If you want to load only _some_ values from a source, you can filter which are loaded by passing a list of variables to `multiple`. This is useful in scenarios where you dump an entire environment. For example:
34+
35+
```toml
36+
[applications.db.profiles.dev.variables]
37+
DATABASE = "dev"
38+
creds = {type = "command", command = "ssh me@remote printenv", multiple = ["DB_USER", "DB_PASSWORD"]}
39+
```
40+
41+
This will only load the `DB_USER` and `DB_PASSWORD` variables:
42+
43+
```sh
44+
> es run db dev -- printenv
45+
DATABASE=dev
46+
DB_USER=root
47+
DB_PASSWORD=hunter2
48+
```

docs/src/user_guide/env/path.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Adding to the PATH Variable
2+
3+
If you want to modify the `PATH` variable, typically you just want to add to it, rather than replace it. Because of this, env-select will treat the variable `PATH` specially. It will append to the beginning, using `:` as a separator:
4+
5+
```toml
6+
[applications.server.profiles.dev.variables]
7+
PATH = "~/.bin"
8+
```
9+
10+
```sh
11+
> printenv PATH
12+
/bin:/usr/bin
13+
> es run server dev -- printenv PATH
14+
~/.bin:/bin:/usr/bin
15+
```

docs/src/user_guide/setting_environment_variables.md

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)