-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Make local env vars available in non-local environments #20122
base: main
Are you sure you want to change the base?
Conversation
src/python/pants/engine/env_vars.py
Outdated
@@ -17,6 +17,9 @@ | |||
class CompleteEnvironmentVars(FrozenDict): | |||
"""CompleteEnvironmentVars contains all environment variables from the current Pants process. | |||
|
|||
For non-local environments like docker or remote execution we also include the local environment | |||
from the shell running pants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be careful with this. When executing in a remote environment, there is no guarantee that the local env will be compatible with the remote system.
Think we should require the user to be very explicit with which env vars they want forwarded to the remote system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 Do you think this could look like an extra field on the remote_environment
and/or docker_environment
target?
Something like
pass_through_env_vars=["ENV_VAR_1", "ENV_VAR_2"]
and would mean that those variables are safe to pass through from the local environment and made available in the non-local environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like that, yea. feels like a good bikeshed topic for slack, being a user facing thing.. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, definitely a per-environment-target option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, how is the progress on this one? Would be very nice to have this feature. |
Fixes #18577
Background and Motivation
Users like to be able to transmit environment variables from their running shell into processes run by pants.
This has not worked when using
docker_environment
or remote execution. In both cases, the universe of environment variables passed to the process is restricted to the environment within the docker container or the remote execution environment.Pants intentionally sets up the environment variables for the sandboxed processes it runs:
The
env
dictionary is built in rule code. Values from the user shell or the execution environments can get in here from rules that read and intentionally subsetCompleteEnvVars
, which represents the environment outside of pants.In main,
CompleteEnvVars
comes from one of the following sources, depending on the execution environment target:os.environ
from the shell running pants.env
to read and save the environment in the docker containerenv
and read the remote env.As a result, environment variables set in the user's shell do not make it into non-local environments
Intended change
the docker and remote environment targets have a new field
pass_through_env_vars
taking a list of variable names to take from the local running shell and merge with the non-local environment's environment variables when buildingCompleteEnvVars
. Pants can then use them when setting up theenv
for sandboxed processes.Testing example
https://github.com/gauthamnair/example-python/tree/docker-env-vars
BUILD
pants.toml
env_test.py constructed to fail but to reveal platform and environment:
currently showing the env var getting passed all the way into the test in both local and docker environments: