GoogleCloudPlatform / composer-local-dev

Apache License 2.0
74 stars 37 forks source link

ENV variable dropped with COMPOSER_CONTAINER_RUN_AS_HOST_USER #46

Open nbonnotte opened 5 months ago

nbonnotte commented 5 months ago

I'm using the latest version (eacc17c2c934b7873b7302f4d6b2dd9bdaf6d9d8)

In my variables.env I have

COMPOSER_CONTAINER_RUN_AS_HOST_USER=True
ENV=local
FOO=foo

Then the environment variables FOO is available to Airflow, but not ENV.

The variables are injected into the container:

$ docker exec -ti composer-local-dev-my-composer bash
airflow@ced4020ec909:~$ echo $FOO
foo
airflow@ced4020ec909:~$ echo $ENV
local

But the sudo -E (use in the entrypoint) drops the ENV variable.

Indeed, adding line sudo sudo -V in the entrypoint confirms this:

...
2024-04-18T14:57:18.251159989Z + sudo sudo -V
2024-04-18T14:57:18.251168450Z Running Airflow as user nicolas(1000)
2024-04-18T14:57:18.263092122Z Sudo version 1.8.31
...
2024-04-18T14:57:18.263487539Z Reset the environment to a default set of variables
2024-04-18T14:57:18.263495737Z Environment variables to check for sanity:
2024-04-18T14:57:18.263503981Z  TZ
2024-04-18T14:57:18.263512002Z  TERM
...
2024-04-18T14:57:18.263557707Z Environment variables to remove:
2024-04-18T14:57:18.263565589Z  *=()*
...
2024-04-18T14:57:18.263830321Z  BASH_ENV
2024-04-18T14:57:18.263837391Z  ENV
...
2024-04-18T14:57:18.263941930Z Environment variables to preserve:
...
ahidalgob commented 4 months ago

Hi, can you explain why is it important to keep the ENV variable? Thank you!

nbonnotte commented 4 months ago

ENV is not a reserved environment variable. The composer-local-dev documentation does not include a caveat saying the tool can't handle it either. So it looks like a bug to me...

nbonnotte commented 2 months ago

Note that we have the same issue with PYTHONPATH, see #60