Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[envsec] Ensure build environment is the same #1703

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/devbox/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,7 @@ func (d *Devbox) computeEnv(ctx context.Context, usePrintDevEnvCache bool) (map[
env["PATH"],
)

env["PATH"], err = d.addUtilitiesToPath(ctx, env["PATH"])
if err != nil {
if err = d.addUtilitiesToEnv(ctx, env); err != nil {
return nil, err
}

Expand Down
21 changes: 13 additions & 8 deletions internal/devbox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"

"github.com/pkg/errors"
"go.jetpack.io/devbox/internal/build"
"go.jetpack.io/devbox/internal/integrations/envsec"
"go.jetpack.io/devbox/internal/nix/nixprofile"

Expand All @@ -34,22 +35,26 @@ func (d *Devbox) addDevboxUtilityPackage(ctx context.Context, pkg string) error
})
}

// addDevboxUtilityPackages adds binaries that we want the user to have access
// to (e.g. envsec).
// addUtilitiesToEnv adds binaries that we want the user to have access
// to (e.g. envsec) and associated env vars.
// Question: Should we add utilityBinPath here? That would allow user to use
// process-compose, etc
func (d *Devbox) addUtilitiesToPath(
func (d *Devbox) addUtilitiesToEnv(
ctx context.Context,
path string,
) (string, error) {
env map[string]string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the function comment to match the new function name?

) error {
if d.cfg.IsEnvsecEnabled() {
envsecPath, err := envsec.EnsureInstalled(ctx)
if err != nil {
return "", err
return err
}
env["PATH"] = env["PATH"] + string(os.PathListSeparator) + filepath.Dir(envsecPath)
if build.IsDev {
// Ensure that devbox and envsec build envs are the same
env["ENVSEC_BUILD_ENV"] = "dev"
}
path = path + string(os.PathListSeparator) + filepath.Dir(envsecPath)
}
return path, nil
return nil
}

func utilityLookPath(binName string) (string, error) {
Expand Down
7 changes: 6 additions & 1 deletion internal/integrations/envsec/envsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func EnsureInstalled(ctx context.Context) (string, error) {
return binPathCache, nil
}

paths, err := pkgtype.RunXClient().Install(ctx, "jetpack-io/envsec@v0.0.14")
paths, err := pkgtype.RunXClient().Install(ctx, "jetpack-io/envsec@v0.0.15")
if err != nil {
return "", errors.Wrap(err, "failed to install envsec")
}
Expand Down Expand Up @@ -87,6 +87,11 @@ func envsecList(
"--environment", environment,
"--json-errors")
cmd.Dir = projectDir
if build.IsDev {
// Ensure that devbox and envsec build envs are the same
cmd.Env = append(os.Environ(), "ENVSEC_BUILD_ENV=dev")
}

var bufErr bytes.Buffer
cmd.Stderr = &bufErr
out, err := cmd.Output()
Expand Down
Loading