Skip to content

Commit

Permalink
[env] Fix env_from docs and improve error messaging (#2386)
Browse files Browse the repository at this point in the history
## Summary
See #2385 for context.

## How was it tested?
Not
  • Loading branch information
ipince authored Oct 28, 2024
1 parent b3f6847 commit 399b7f3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions docs/app/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ Currently, you can only set values using string literals, `$PWD`, and `$PATH`. A

### Env From

Env from takes a string or list of strings for loading environment variables into your shells and scripts. Currently it supports loading from two sources: .env files, and Jetify Secrsts.
Env from takes a string for loading environment variables into your shells and scripts. Currently it supports loading from two sources: .env files, and Jetify Secrets.

#### .env Files

You can load environment variables from a `.env` file by adding the path to the file in the `env_from` field. This is useful for loading secrets or other sensitive information that you don't want to store in your `devbox.json`.
You can load environment variables from a `.env` file by adding the path to the file in the `env_from` field (the file must end with `.env`). This is useful for loading secrets or other sensitive information that you don't want to store in your `devbox.json`.

```json
{
Expand All @@ -198,15 +198,15 @@ This will load the environment variables from the `.env` file into your shell wh

#### Jetify Secrets

You can securely load secrets from Jetify Secrets by running `devbox secrets init` and creating a project in Jetify Cloud. This will add the `jetpack-cloud` field to `env_from` in your project.
You can securely load secrets from Jetify Secrets by running `devbox secrets init` and creating a project in Jetify Cloud. This will add the `jetify-cloud` field to `env_from` in your project.

```json
{
"env_from": "jetpack-cloud"
"env_from": "jetify-cloud"
}
```

Note that setting secrets securetly with Jetify Secrets requires a Jetify Cloud account. For more information, see the [Jetify Secrets](/docs/cloud/secrets/) guide.
Note that setting secrets securely with Jetify Secrets requires a Jetify Cloud account. For more information, see the [Jetify Secrets](/docs/cloud/secrets/) guide.

### Shell

Expand Down
4 changes: 1 addition & 3 deletions docs/app/docs/guides/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ For environment variables that you want to keep out of your `devbox.json` file,
{
"packages": {},
"shell": {},
"env_from": [
"path/to/.env"
]
"env_from": "path/to/.env"
}
```

Expand Down
5 changes: 3 additions & 2 deletions internal/devbox/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.jetpack.io/devbox/internal/devbox/envpath"
"go.jetpack.io/devbox/internal/devbox/generate"
"go.jetpack.io/devbox/internal/devconfig"
"go.jetpack.io/devbox/internal/devconfig/configfile"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
"go.jetpack.io/devbox/internal/envir"
Expand Down Expand Up @@ -1009,9 +1010,9 @@ func (d *Devbox) configEnvs(
}
} else if d.cfg.Root.EnvFrom != "" {
return nil, usererr.New(
"unknown from_env value: %s. Supported value is: %q.",
"unknown env_from value: %s. Supported values are: \"%q\" or a path to a file ending in \".env\"",
d.cfg.Root.EnvFrom,
"jetpack-cloud",
configfile.JetifyCloudEnvFromValue,
)
}
for k, v := range d.cfg.Env() {
Expand Down
4 changes: 3 additions & 1 deletion internal/devconfig/configfile/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"github.com/hashicorp/go-envparse"
)

var JetifyCloudEnvFromValue = "jetify-cloud"

func (c *ConfigFile) IsEnvsecEnabled() bool {
// envsec for legacy. jetpack-cloud for legacy
return c.EnvFrom == "envsec" || c.EnvFrom == "jetpack-cloud" || c.EnvFrom == "jetify-cloud"
return c.EnvFrom == "envsec" || c.EnvFrom == "jetpack-cloud" || c.EnvFrom == JetifyCloudEnvFromValue
}

func (c *ConfigFile) IsdotEnvEnabled() bool {
Expand Down

0 comments on commit 399b7f3

Please sign in to comment.