basecamp / kamal

Deploy web apps anywhere.
https://kamal-deploy.org
MIT License
9.38k stars 357 forks source link

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

Open fabiendv opened 1 week ago

fabiendv commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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.