Skip to content

[services] Fix issue where env var is ignored #1570

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

Merged
merged 6 commits into from
Oct 19, 2023

Conversation

mikeland73
Copy link
Contributor

@mikeland73 mikeland73 commented Oct 18, 2023

Summary

Fixes #1565

The bugs:

  • env vars specified via --env-file (and possibly via other methods) are ignored in nginx config.
  • When inside a devbox shell or a direnv context, starting services would ignore env vars.

Intermediate causes:

  • envsubst binary was a bin wrapped binary. This was resetting the env vars. Fix: Never use bin wrappers when inside a devbox run (This was previously only scoped to using the CLI command explicitly, but now we do it any time we use RunScript function)
  • Previously we would only run services in new shell if we were not already in a shell or direnv. But this causes us to ignore environment variables that are set after the environment is created due to bin wrappers. Fix: always run services in new shell.

Root cause:

  • I'm not 100% sure what caused this. It's possible the PATH stack PR did, but I don't fully understand the mechanism. I'm still confident the changes in this PR are good and simplify uncertainty about how services are called.

Sorry in advance for all the boolean params. We should move to structs, but I didn't want to make those changes here.

How was it tested?

@mikeland73 mikeland73 force-pushed the landau/fix-services-regression branch from 0a855a8 to ecf452a Compare October 18, 2023 17:32
Copy link
Collaborator

@savil savil left a comment

Choose a reason for hiding this comment

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

Made a quick pass. No major concerns, except for the lepp-stack changes, which I don't follow.

I didn't quite understand how it all fits together, so need to make another review pass.
I need to pause for 🐕 walk and dinner. Will re-review soon...

@@ -19,7 +20,6 @@
"init_db": "initdb",
"run_test": [
"mkdir -p /tmp/devbox/lapp",
"export PGHOST=/tmp/devbox/lapp",
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO savil: come back to this change. Refer to slack convo b/w mike and john

@@ -22,6 +23,7 @@
"run_test": [
"mkdir -p /tmp/devbox/lepp",
"export PGHOST=/tmp/devbox/lepp",
"rm -rf .devbox/virtenv/postgresql/data",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just makes testing easier by making run_test more idempotent.

@@ -9,7 +9,8 @@
"env": {
"NGINX_WEB_PORT": "8089",
"NGINX_WEB_ROOT": "../../../my_app",
"PGPORT": "5433"
"PGPORT": "5433",
"PGHOST": "/tmp/devbox/lepp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this if we're exporting PGHOST in run_test?

Short: "Interact with devbox services",
Short: "Interact with devbox services.",
Long: "Interact with devbox services. Services start in a new shell. " +
"Plugin services use envrinment variables specified by plugin unless " +
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: envrinment

@@ -526,15 +538,22 @@ func (d *Devbox) Services() (services.Services, error) {
return result, nil
}

func (d *Devbox) StartServices(ctx context.Context, serviceNames ...string) error {
if !d.IsEnvEnabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 I did re-implement this function in the PathStack PR. I wonder if that update caused this bug.

@@ -35,3 +36,22 @@ func JoinPathLists(pathLists ...string) string {
}
return strings.Join(cleaned, string(filepath.ListSeparator))
}

func RemoveFromPath(path, pathToRemove string) string {
paths := strings.Split(path, string(os.PathListSeparator))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can use filepath.SplitList

}

// Join the modified paths using ":" as the delimiter
newPath := strings.Join(newPaths, string(os.PathListSeparator))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can use filepath.Join

Copy link
Collaborator

Choose a reason for hiding this comment

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

line 37 too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

filepath.Join is for directory paths! not for path lists!

e.g. /path/to/my/file vs path1:path2:path3

Copy link
Collaborator

Choose a reason for hiding this comment

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

lol

}

// Join the modified paths using ":" as the delimiter
newPath := strings.Join(newPaths, string(os.PathListSeparator))
Copy link
Collaborator

Choose a reason for hiding this comment

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

lol

@mikeland73 mikeland73 merged commit 9444bae into main Oct 19, 2023
@mikeland73 mikeland73 deleted the landau/fix-services-regression branch October 19, 2023 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: NGINX envsubst regression in 0.7.0
2 participants