Environment variable from terminal overwriting .env.erb value
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
Version
Kamal 1.7.1
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.
this is working as expected. Kamal uses
dotenvunder 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.
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