#Changing host environment variables

1 messages · Page 1 of 1 (latest)

candid wyvern
#

You can't change the host environment from python because even though you're using the python SDK, when you use the API it's actually being run by the engine. Eg., env_variable is being run by the engine (in Go), not by Python.

#

That client chainable thingy is just a client for the dagger API.

winged wasp
#

Thanks, if I want to be able to dynamically load env variables into the host (say, I have a container that uses sops to decrypt secrets and load them into host env), do I need to run two separate engines (clients) then?

candid wyvern
#

Can I ask what's the purpose of changing the host env? Is it to be used in other steps in the same pipeline, or something else outside of dagger?

winged wasp
#

it's to use in other steps in the same pipeline. Basically it's using sops to decrypt secrets which are being passed into future pipeline steps via environment variables

candid wyvern
#

You can just load the secret into a var and use it in container()...with_env_variable("MY_VAR", my_var) directly).

#

Instead of loading my_var from an host variable, just load from the SOPS step.

winged wasp
#

I see, assuming you had a container called "sops", and that container, "sops" had an environment variable containing the secret you wanted, you could use sops.env_variable("NAME_OF_MY_SECRET") to get at it

candid wyvern
#

If you have an exec step that decrypts using sops, you can use it's stdout, make a secret and mount it where you need it. Or don't make it a secret and load as an env var. So it depends on how your sops step works. No need to make an env var if you can just get the stdout of the command.

#

As another example, your sops step could also put the secret in a file, in which case just get that file and mount it where you need it. Secret or not, either the file or its contents (as a string).

winged wasp
#

Thanks, this helps. I do have access to the sops stdout via an exec, so that seems like the better way to go about it