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

add support for environment files #598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mpldr
Copy link

@mpldr mpldr commented Jun 2, 2024

At times, it is necessary or at least easier to set environment variables using a file.

Add a function that augments the environment of the spawned process with the provided variables.

Tested to work on Linux. Not sure on how to write a test for it without either passing in the content as a reader or basically testing stdlib IO functions.

runner/environment.go Outdated Show resolved Hide resolved
runner/environment.go Show resolved Hide resolved
At times, it is necessary or at least easier to set environment
variables using a file.

Add a function that augments the environment of the spawned process with
the provided variables.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
@mpldr
Copy link
Author

mpldr commented Jun 2, 2024 via email

@mpldr
Copy link
Author

mpldr commented Jun 2, 2024 via email

@xiantang
Copy link
Collaborator

xiantang commented Jun 3, 2024

why do u just pass env var like this:

A=B air

@ccoVeille
Copy link
Contributor

ccoVeille commented Jun 3, 2024

why do u just pass env var like this:

A=B air

@xiantang I was also wondering when I read the PR for the first time.

For me the environment variables are what they are supposed to be something outside the binary that exists prior the binary is launched, they are added by the shell.

I was surprised by what @mpldr added, but I was like, never mind 🤷, but as you raise the point 🤨 too. I feel like my first thought was right.

I wouldn't expect this to be added to air

It's usually the role of:

  • a runner tool that will import the variables, then launch air
  • a shell script
  • a global environment variable added to the shell
  • any virtualenv tool
  • a command-line scoped environment variable as you spotted @xiantang
  • the equivalent of what is implemented should be a part of the config file of air

@mpldr
Copy link
Author

mpldr commented Jun 3, 2024

why do u just pass env var like this:

A=B air

mainly two reasons:

  • No way to change the environment between restart, which at times can be necessary (for example when changing parsing logic or moving on to a different task)
  • This gets ridiculously long for some docker services, where you have to set a dozen or more environment variables.

they are supposed to be something outside the binary that exists prior the binary is launched

Since air acts as the launcher (it calls sh), this seems like an appropriate place to do it, to me.

@ccoVeille
Copy link
Contributor

What about using the air config file to set the env variables, so not the location of an env file?

@mpldr
Copy link
Author

mpldr commented Jun 3, 2024

That was an approach I was considering, but ultimately abandoned it because .env files or some variation of them are usually already present. And having two places to maintain environment variables might be a tough sell :)

@ccoVeille
Copy link
Contributor

Thanks for your reply.

It won't change the points I already raised, it's surprising to see such implementation.

#598 (comment)

For me, it's over the role of an app to do that

I look at what supervisord was doing and it was providing such a feature and the reply and arguments were very similar

Supervisor/supervisor#771

But anyway, why not… but I would discourage you doing it.

@ccoVeille
Copy link
Contributor

ccoVeille commented Jun 4, 2024

I'm still not convinced, but it's not a problem 😅. I'm a random voice among others. I can live with this feature being in the app, but I won't use it.

But if you want to keep the feature please look at #598 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants