Skip to content

Commit 0839434

Browse files
committed
Merge branch 'main' of https://github.com/jetify-com/devbox into feature/json-plugin-schema
2 parents ab5053b + c0331c7 commit 0839434

35 files changed

+1091
-141
lines changed

docs/app/docs/cli_reference/devbox_completion_zsh.md

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

33
Generate the autocompletion script for the zsh shell.
44

5-
If shell completion is not already enabled in your environment you will need
6-
to enable it. You can execute the following once:
5+
If you are using Oh My Zsh, just run the following:
6+
7+
```bash
8+
mkdir -p ~/.oh-my-zsh/completions
9+
devbox completion zsh > ~/.oh-my-zsh/completions/_devbox
10+
```
11+
12+
If you are not using Oh My Zsh and shell completion is not already enabled in your environment you will need
13+
to enable it. You can execute the following once:
714

815
```bash
916
echo "autoload -U compinit; compinit" >> ~/.zshrc

docs/app/docs/configuration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ Currently, you can only set values using string literals, `$PWD`, and `$PATH`. A
182182

183183
### Env From
184184

185-
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.
185+
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.
186186

187187
#### .env Files
188188

189-
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`.
189+
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`.
190190

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

199199
#### Jetify Secrets
200200

201-
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.
201+
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.
202202

203203
```json
204204
{
205-
"env_from": "jetpack-cloud"
205+
"env_from": "jetify-cloud"
206206
}
207207
```
208208

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

211211
### Shell
212212

docs/app/docs/guides/secrets.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ For environment variables that you want to keep out of your `devbox.json` file,
2828
{
2929
"packages": {},
3030
"shell": {},
31-
"env_from": [
32-
"path/to/.env"
33-
]
31+
"env_from": "path/to/.env"
3432
}
3533
```
3634

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
let
1212
pkgs = nixpkgs.legacyPackages.${system};
1313

14-
lastTag = "0.13.5";
14+
lastTag = "0.13.6";
1515

1616
revision = if (self ? shortRev)
1717
then "${self.shortRev}"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require (
4242
github.com/zealic/go2node v0.1.0
4343
go.jetify.com/typeid v1.2.0
4444
go.jetpack.io/envsec v0.0.16-0.20240604163020-540ad12af899
45-
go.jetpack.io/pkg v0.0.0-20240815004735-7649b4283d51
45+
go.jetpack.io/pkg v0.0.0-20241025195518-152e59e26d5d
4646
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
4747
golang.org/x/mod v0.18.0
4848
golang.org/x/oauth2 v0.21.0

go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/boxcli/run.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ import (
1717
"go.jetpack.io/devbox/internal/devbox"
1818
"go.jetpack.io/devbox/internal/devbox/devopt"
1919
"go.jetpack.io/devbox/internal/redact"
20+
"go.jetpack.io/devbox/internal/ux"
2021
)
2122

2223
type runCmdFlags struct {
2324
envFlag
24-
config configFlags
25-
omitNixEnv bool
26-
pure bool
27-
listScripts bool
25+
config configFlags
26+
omitNixEnv bool
27+
pure bool
28+
listScripts bool
29+
recomputeEnv bool
2830
}
2931

3032
// runFlagDefaults are the flag default values that differ
@@ -62,6 +64,7 @@ func runCmd(defaults runFlagDefaults) *cobra.Command {
6264
"shell environment will omit the env-vars from print-dev-env",
6365
)
6466
_ = command.Flags().MarkHidden("omit-nix-env")
67+
command.Flags().BoolVar(&flags.recomputeEnv, "recompute", true, "recompute environment if needed")
6568

6669
command.ValidArgs = listScripts(command, flags)
6770

@@ -84,6 +87,7 @@ func listScripts(cmd *cobra.Command, flags runCmdFlags) []string {
8487
}
8588

8689
func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
90+
ctx := cmd.Context()
8791
if len(args) == 0 || flags.listScripts {
8892
scripts := listScripts(cmd, flags)
8993
if len(scripts) == 0 {
@@ -111,19 +115,32 @@ func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
111115
// Check the directory exists.
112116
box, err := devbox.Open(&devopt.Opts{
113117
Dir: path,
118+
Env: env,
114119
Environment: flags.config.environment,
115120
Stderr: cmd.ErrOrStderr(),
116-
Env: env,
117121
})
118122
if err != nil {
119123
return redact.Errorf("error reading devbox.json: %w", err)
120124
}
121125

122126
envOpts := devopt.EnvOptions{
123-
OmitNixEnv: flags.omitNixEnv,
124-
Pure: flags.pure,
127+
Hooks: devopt.LifecycleHooks{
128+
OnStaleState: func() {
129+
if !flags.recomputeEnv {
130+
ux.FHidableWarning(
131+
ctx,
132+
cmd.ErrOrStderr(),
133+
devbox.StateOutOfDateMessage,
134+
"with --recompute=true",
135+
)
136+
}
137+
},
138+
},
139+
OmitNixEnv: flags.omitNixEnv,
140+
Pure: flags.pure,
141+
SkipRecompute: !flags.recomputeEnv,
125142
}
126-
if err := box.RunScript(cmd.Context(), envOpts, script, scriptArgs); err != nil {
143+
if err := box.RunScript(ctx, envOpts, script, scriptArgs); err != nil {
127144
return redact.Errorf("error running script %q in Devbox: %w", script, err)
128145
}
129146
return nil

internal/boxcli/shell.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import (
1313
"go.jetpack.io/devbox/internal/devbox"
1414
"go.jetpack.io/devbox/internal/devbox/devopt"
1515
"go.jetpack.io/devbox/internal/envir"
16+
"go.jetpack.io/devbox/internal/ux"
1617
)
1718

1819
type shellCmdFlags struct {
1920
envFlag
20-
config configFlags
21-
omitNixEnv bool
22-
printEnv bool
23-
pure bool
21+
config configFlags
22+
omitNixEnv bool
23+
printEnv bool
24+
pure bool
25+
recomputeEnv bool
2426
}
2527

2628
// shellFlagDefaults are the flag default values that differ
@@ -53,17 +55,20 @@ func shellCmd(defaults shellFlagDefaults) *cobra.Command {
5355
"shell environment will omit the env-vars from print-dev-env",
5456
)
5557
_ = command.Flags().MarkHidden("omit-nix-env")
58+
command.Flags().BoolVar(&flags.recomputeEnv, "recompute", true, "recompute environment if needed")
5659

5760
flags.config.register(command)
5861
flags.envFlag.register(command)
5962
return command
6063
}
6164

6265
func runShellCmd(cmd *cobra.Command, flags shellCmdFlags) error {
66+
ctx := cmd.Context()
6367
env, err := flags.Env(flags.config.path)
6468
if err != nil {
6569
return err
6670
}
71+
6772
// Check the directory exists.
6873
box, err := devbox.Open(&devopt.Opts{
6974
Dir: flags.config.path,
@@ -91,9 +96,22 @@ func runShellCmd(cmd *cobra.Command, flags shellCmdFlags) error {
9196
return shellInceptionErrorMsg("devbox shell")
9297
}
9398

94-
return box.Shell(cmd.Context(), devopt.EnvOptions{
95-
OmitNixEnv: flags.omitNixEnv,
96-
Pure: flags.pure,
99+
return box.Shell(ctx, devopt.EnvOptions{
100+
Hooks: devopt.LifecycleHooks{
101+
OnStaleState: func() {
102+
if !flags.recomputeEnv {
103+
ux.FHidableWarning(
104+
ctx,
105+
cmd.ErrOrStderr(),
106+
devbox.StateOutOfDateMessage,
107+
"with --recompute=true",
108+
)
109+
}
110+
},
111+
},
112+
OmitNixEnv: flags.omitNixEnv,
113+
Pure: flags.pure,
114+
SkipRecompute: !flags.recomputeEnv,
97115
})
98116
}
99117

internal/boxcli/shellenv.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,23 @@ func shellEnvFunc(
116116
}
117117

118118
envStr, err := box.EnvExports(ctx, devopt.EnvExportsOpts{
119-
DontRecomputeEnvironment: !flags.recomputeEnv,
120119
EnvOptions: devopt.EnvOptions{
120+
Hooks: devopt.LifecycleHooks{
121+
OnStaleState: func() {
122+
if !flags.recomputeEnv {
123+
ux.FHidableWarning(
124+
ctx,
125+
cmd.ErrOrStderr(),
126+
devbox.StateOutOfDateMessage,
127+
box.RefreshAliasOrCommand(),
128+
)
129+
}
130+
},
131+
},
121132
OmitNixEnv: flags.omitNixEnv,
122133
PreservePathStack: flags.preservePathStack,
123134
Pure: flags.pure,
135+
SkipRecompute: !flags.recomputeEnv,
124136
},
125137
NoRefreshAlias: flags.noRefreshAlias,
126138
RunHooks: flags.runInitHook,

0 commit comments

Comments
 (0)