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

Environment variable from terminal overwriting .env.erb value #860

Closed
fabiendv opened this issue Jun 24, 2024 · 3 comments
Closed

Environment variable from terminal overwriting .env.erb value #860

fabiendv opened this issue Jun 24, 2024 · 3 comments

Comments

@fabiendv
Copy link

fabiendv commented Jun 24, 2024

There is an issue where the value of an environment variable set in the terminal is overwriting the value specified in the .env.erb file. The expected behavior is that the value defined in .env.erb should take precedence and overwrite any value set in the terminal.

Desired behavior

The value specified in the .env.erb file should overwrite the value set in the terminal.

How to Reproduce

Define a value in your .env.erb file:

MY_VALUE=test

In the terminal, export a different value for the same variable:

export MY_VALUE=wrongvalue

To make sure your terminal knows the value, you can edit the .bashrc.

Run the following command:

kamal envify

Check the value of the environment variable on the host machine (.kamal/env/roles/myfile.rb)

The environment variable on the host machine retains the terminal value (wrongvalue).

Expected outcome

The environment variable on the host machine should have the value from .env.erb (test).

Root cause

Screenshot 2024-06-24 at 2 29 46 PM

Version

Kamal 1.7.1

@acidtib
Copy link
Contributor

acidtib commented Jun 24, 2024

this is working as expected. Kamal uses dotenv under the hood, and being able to grab environment variables from an export is a default behavior.

@fabiendv
Copy link
Author

this is working as expected. Kamal uses dotenv under the hood, and being able to grab environment variables from an export is a default behavior.

It can be surprising for developers when a value specified in .env.myenv is not reflected on the host machine. I believe that variables in .env.myenv should take precedence over terminal values.

However, if this behavior is indeed intended, let's close this issue.

@djmb
Copy link
Collaborator

djmb commented Sep 30, 2024

This should be resolved in Kamal 2, though the secrets are now in .kamal/secrets rather than .env.

You can get either behaviour:

#.kamal/secrets

FOO=$FOO # reads from environment
FOO=value # reads value directly

@djmb djmb closed this as completed Sep 30, 2024
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

No branches or pull requests

3 participants