Skip to content

Commit 2df43bf

Browse files
authored
Add docs for --env and devbox run changes (#1366)
## Summary Docs for new features in 0.5.11 ## How was it tested? Localhost `yarn start`
1 parent 5e1b7e9 commit 2df43bf

14 files changed

+107
-20
lines changed

docs/app/docs/cli_reference/devbox_generate_direnv.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ devbox generate direnv [flags]
1212
| Option | Description |
1313
| --- | --- |
1414
| `-c, --config string` | path to directory containing a devbox.json config file |
15+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
16+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment. If the file does not exist, then this parameter is ignored |
1517
| `-h, --help` | help for generate |
1618
| `-q, --quiet` | Quiet mode: Suppresses logs. |
1719

docs/app/docs/cli_reference/devbox_global_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ devbox global add <pkg>... [flags]
1111
<!-- Markdown Table of Options -->
1212
| Option | Description |
1313
| --- | --- |
14+
| `--allow-insecure` | Allow adding packages marked as insecure |
1415
| `-h, --help` | help for add |
1516
| `-q, --quiet` | suppresses logs |
1617

docs/app/docs/cli_reference/devbox_global_run.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Run a script (defined as `"moo": "cowsay moo"`) in your devbox.json:
2929
<!-- Markdown Table of Options -->
3030
| Option | Description |
3131
| --- | --- |
32+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
33+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
3234
| `-h, --help` | help for global run |
3335
| `-q, --quiet` | suppresses logs |
3436

docs/app/docs/cli_reference/devbox_global_services.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ devbox global services [command]
1111
<!-- Markdown Table of Options -->
1212
| Option | Description |
1313
| --- | --- |
14+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
15+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
1416
| `-h, --help` | help for global services |
1517
| `-q, --quiet` | suppresses logs |
1618

docs/app/docs/cli_reference/devbox_run.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
Starts a new interactive shell and runs your target script in it. The shell will exit once your target script is completed or when it is terminated via CTRL-C. Scripts can be defined in your `devbox.json`.
44

5-
You can also run arbitrary commands in your devbox shell by passing them as arguments to `devbox run`. For example:
5+
You can also run arbitrary commands in your devbox shell by passing them as arguments to `devbox run`. For example:
66

77
```bash
88
devbox run echo "Hello World"
99
```
10-
Will print `Hello World` to the console from within your devbox shell.
10+
Will print `Hello World` to the console from within your devbox shell.
1111

1212
For more details, read our [scripts guide](../guides/scripts.md)
1313

@@ -22,7 +22,11 @@ For more details, read our [scripts guide](../guides/scripts.md)
2222
# Run a command directly:
2323
devbox add cowsay
2424
devbox run cowsay hello
25-
devbox run -- cowsay -d hello
25+
# Run a command that takes flags:
26+
devbox run cowsay -d hello
27+
# Pass flags to devbox while running a command.
28+
# All `devbox run` flags must be passed before the command
29+
devbox run -q cowsay -d hello
2630

2731
#Run a script (defined as `"moo": "cowsay moo"`) in your devbox.json:
2832
devbox run moo
@@ -34,6 +38,8 @@ For more details, read our [scripts guide](../guides/scripts.md)
3438
| Option | Description |
3539
| --- | --- |
3640
| `-c, --config string` | path to directory containing a devbox.json config file |
41+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
42+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
3743
| `-h, --help` | help for run |
3844
| `-q, --quiet` | Quiet mode: Suppresses logs. |
3945

docs/app/docs/cli_reference/devbox_services_restart.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ devbox services restart [service]... [flags]
1515
<!-- Markdown Table of Options -->
1616
| Option | Description |
1717
| --- | --- |
18+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
19+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
1820
| `-h, --help` | help for restart |
1921
| `-q, --quiet` | Quiet mode: Suppresses logs. |
2022

docs/app/docs/cli_reference/devbox_services_start.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ devbox services start [service]... [flags]
1515
<!-- Markdown Table of Options -->
1616
| Option | Description |
1717
| --- | --- |
18+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
19+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
1820
| `-h, --help` | help for start |
1921
| `-q, --quiet` | Quiet mode: Suppresses logs. |
2022

docs/app/docs/cli_reference/devbox_services_stop.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ devbox services stop [service]... [flags]
1111
<!-- Markdown Table of Options -->
1212
| Option | Description |
1313
| --- | --- |
14+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
15+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
1416
| `-h, --help` | help for stop |
1517
| `-q, --quiet` | Quiet mode: Suppresses logs. |
1618

docs/app/docs/cli_reference/devbox_services_up.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ devbox services up web
2828
| --- | --- |
2929
| `-b, --background` | Run service in background |
3030
| `-c, --config string` | path to directory containing a devbox.json config file |
31+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
32+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
3133
| `-h, --help` | help for up |
3234
| `--process-compose-file string` | path to process compose file or directory containing process compose-file.yaml|yml. Default is directory containing devbox.json |
3335
| `-q, --quiet` | Quiet mode: Suppresses logs. |

docs/app/docs/cli_reference/devbox_shell.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Start a new shell or run a command with access to your packages
44

55
## Synopsis
66

7-
Start a new shell or run a command with access to your packages. The interactive shell will use the devbox.json in your current directory, or the directory provided with `dir`.
7+
Start a new shell or run a command with access to your packages. The interactive shell will use the devbox.json in your current directory, or the directory provided with `dir`.
88

99
```bash
1010
devbox shell [<dir>] [flags]
@@ -15,6 +15,8 @@ devbox shell [<dir>] [flags]
1515
<!-- Markdown Table of Options -->
1616
| Option | Description |
1717
| --- | --- |
18+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
19+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
1820
| `--print-env` | Print a script to setup a devbox shell environment |
1921
| `-h, --help` | help for shell |
2022
| `-q, --quiet` | Quiet mode: Suppresses logs. |

docs/app/docs/cli_reference/devbox_shellenv.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ devbox shellenv [flags]
1212
| Option | Description |
1313
| --- | --- |
1414
| `-c, --config string` | path to directory containing a devbox.json config file |
15+
| `-e, --env stringToString` | environment variables to set in the devbox environment (default []) |
16+
| `--env-file string` | path to a file containing environment variables to set in the devbox environment |
1517
| `-h, --help` | help for shellenv |
1618
| `-q, --quiet` | suppresses logs |
1719

docs/app/docs/configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ To run multiple commands in a single script, you can pass them as an array:
147147
}
148148
```
149149

150-
### Includes
150+
### Include
151151

152152
Includes can be used to explicitly add extra configuration or plugins to your Devbox project. Currently this only supports adding our [built-in plugins](guides/plugins.md) to your project.
153153

154-
You should use this section to activate plugins when you install a package from a [Flake](guides/using_flakes.md) that uses a plugin. To ensure that a plugin is activated for your project, add it to the `includes` section of your `devbox.json`. For example, to explicitly activate the PHP plugin, you can add the following to your `devbox.json`:
154+
You should use this section to activate plugins when you install a package from a [Flake](guides/using_flakes.md) that uses a plugin. To ensure that a plugin is activated for your project, add it to the `include` section of your `devbox.json`. For example, to explicitly activate the PHP plugin, you can add the following to your `devbox.json`:
155155

156156
```json
157157
{
158-
"includes": [
158+
"include": [
159159
"plugin:php-config"
160160
]
161161
}

docs/app/docs/guides/scripts.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
title: Running Scripts
33
---
44

5-
This doc describes how to configure and run scripts using `devbox run`. Scripts started with `devbox run` are launched in a interactive `devbox shell` that terminates once the script finishes, or is interrupted by CTRL-C.
5+
This doc describes how to configure and run scripts using `devbox run`. Scripts started with `devbox run` are launched in a interactive `devbox shell` that terminates once the script finishes, or is interrupted by CTRL-C.
66

7-
Scripts will run after your packages finish installing, and after your `init_hook` completes.
7+
Scripts will run after your packages finish installing, and after your `init_hook` completes.
88

99
## Configuring scripts
1010

11-
Scripts can be added in your `devbox.json`. Scripts require a unique name, and a command or list of commands to run:
11+
Scripts can be added in your `devbox.json`. Scripts require a unique name, and a command or list of commands to run:
1212

1313
```json
1414
"shell": {
1515
"init_hook": "echo \"Hello \"",
1616
"scripts": {
17-
"echo_once": "echo \"World\"",
17+
"echo_once": "echo \"World\"",
1818
"echo_twice": [
1919
"echo \"World\"",
2020
"echo \"Again\""
@@ -25,7 +25,7 @@ Scripts can be added in your `devbox.json`. Scripts require a unique name, and a
2525

2626
## Running your scripts
2727

28-
To run a script, use `devbox run <script_name>`. This will start your shell, run your `init_hook`, and then run the script:
28+
To run a script, use `devbox run <script_name>`. This will start your shell, run your `init_hook`, and then run the script:
2929

3030
```bash
3131
$ devbox run echo_once
@@ -52,17 +52,37 @@ You can use `devbox run` to run any command in your Devbox shell, even if you ha
5252
devbox run echo "Hello World"
5353
```
5454

55-
For commands that use flags, you can use the `--` separator to tell Devbox that the rest of the command is a single command to run. For example, the following command will show you all the processes listening on port 80:
55+
You can also run commands that use flags as normal. For example:
5656

5757
```bash
58-
devbox run -- lsof -i :80
58+
devbox run lsof -i :80
5959
```
6060

61+
Note that if you want to pass flags to `devbox run`, you should pass them before the command. For example:
62+
63+
```bash
64+
# Run `lsof -i :80` in your devbox shell in quiet mode
65+
devbox run -q lsof -i :80
66+
```
67+
68+
## Run Scripts with Custom Environment Variables
69+
70+
You can use the `--env` flag to set custom environment variables in your Devbox shell. For example, the following command will set the `MY_VAR` environment variable to `my_value` when running the `echo` command:
71+
72+
```bash
73+
devbox run --env MY_VAR=my_value echo $MY_VAR
74+
```
75+
76+
You can also load environment variables from a .env file using the `--env-file` flag. For example, the following command will load the environment variables from the `.env.devbox` file in your current directory:
77+
78+
```bash
79+
devbox run --env-file .env.devbox echo $MY_VAR
80+
```
6181

6282
## Tips on using Scripts
6383

6484
1. Since `init_hook` runs everytime you start your shell, you should use primarily use it for setting environment variables and aliases. For longer running tasks like database setup, you can create and run a Devbox script
65-
2. You can use Devbox scripts to start and manage long running background processes and daemons.
85+
2. You can use Devbox scripts to start and manage long running background processes and daemons.
6686
1. For example -- If you are working on a LAMP stack project, you can use scripts to start MySQL and Apache in separate shells and monitor their logs. Once you are done developing, you can use CTRL-C to exit the processes and shells
6787
3. If a script feels too long to put it directly in `devbox.json`, you can save it as a shell script in your project, and then invoke it in your `devbox scripts`.
68-
4. For more ideas, see the LAMP stack example in our [Devbox examples repo](https://github.com/jetpack-io/devbox/tree/main/examples/stacks/lapp-stack).
88+
4. For more ideas, see the LAMP stack example in our [Devbox examples repo](https://github.com/jetpack-io/devbox/tree/main/examples/stacks/lapp-stack).

docs/app/docs/ide_configuration/direnv.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
2-
title: direnv
2+
title: direnv
33
---
44

55

66
## direnv
77
___
88
[direnv](https://direnv.net) is an open source environment management tool that allows setting unique environment variables per directory in your file system. This guide covers how to configure direnv to seamlessly work with a devbox project.
99

10-
:::note
10+
:::note
1111
Devbox 0.5.0 makes changes to how the environment is sourced in order to ensure better compatibility with the user's host shell. This may raise some errors if you generated your `.envrc` file with an older version of devbox.
12-
12+
1313
If you see any errors when activating your `.envrc` file, you will need to run `devbox generate direnv --force`, and then re-run `devbox shell` to apply the latest changes. Be sure to back up your old `.envrc` file before running this command.
1414
:::
1515

1616
### Prerequisites
17-
* Install direnv and hook it to your shell. Follow [this guide](https://direnv.net/#basic-installation) if you haven't done it.
17+
* Install direnv and hook it to your shell. Follow [this guide](https://direnv.net/#basic-installation) if you haven't done it.
1818

1919
### Setting up Devbox Shell and direnv
2020

@@ -45,6 +45,48 @@ direnv: loading ~/src/devbox/docs/.envrc
4545
direnv: using devbox
4646
```
4747

48+
#### Adding Custom Env Variables or Env Files to your Direnv Config
49+
50+
In some cases, you may want to override certain environment variables in your Devbox config when running it locally. You can add custom environment variables from the command line or from a file using the `--env` and `--env-file` flags.
51+
52+
If you would like to add custom environment variables to your direnv config, you can do so by passing the `--env` flag to `devbox generate direnv`. This flag takes a comma-separated list of key-value pairs, where the key is the name of the environment variable and the value is the value of the environment variable. For example, if you wanted to add a `MY_CUSTOM_ENV_VAR` environment variable with a value of `my-custom-value`, you would run the following command:
53+
54+
```bash
55+
devbox generate direnv --env MY_CUSTOM_ENV_VAR=my-value
56+
```
57+
58+
The resulting .envrc will have the following:
59+
60+
```bash
61+
# Automatically sets up your devbox environment whenever you cd into this
62+
# directory via our direnv integration:
63+
64+
eval "$(devbox generate direnv --print-envrc --env MY_CUSTOM_ENV_VAR=my-value)"
65+
66+
# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
67+
# for more details
68+
```
69+
70+
You can also tell direnv to read environment variables from a custom `.env` file by passing the `--env-file` flag to `devbox generate direnv`. This flag takes a path to a file containing environment variables to set in the devbox environment. If the file does not exist, then this parameter is ignored. For example, if you wanted to add a `.env.devbox` file located in your project root, you would run the following command:
71+
72+
```bash
73+
devbox generate direnv --env-file .env.devbox
74+
```
75+
76+
The resulting .envrc will have the following:
77+
78+
```bash
79+
# Automatically sets up your devbox environment whenever you cd into this
80+
# directory via our direnv integration:
81+
82+
eval "$(devbox generate direnv --print-envrc --env-file .env.devbox)"
83+
84+
# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
85+
# for more details
86+
```
87+
88+
Note that if Devbox cannot find the env file provided to the flag, it will ignore the flag and load your Devbox shell environment as normal
89+
4890
### Global settings for direnv
4991

5092
Note that every time changes are made to `devbox.json` via `devbox add ...`, `devbox rm ...` or directly editing the file, requires `direnv allow` to run so that `direnv` can setup the new changes.

0 commit comments

Comments
 (0)