[GH-ISSUE #767] ENVIRONMENT and .env file: existing contents of .env is deleted on deployment #2412

Closed
opened 2026-04-11 10:19:38 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @nisrael on GitHub (Aug 25, 2025).
Original GitHub issue: https://github.com/moghtech/komodo/issues/767

Thanks for implementing #716. Unfortunately, we didn’t include the request to make the Environment section in the Web UI reflect changes to the .env file (and vice versa). So now the existing file is being replaced during the deploy step.

Steps to reproduce:

  1. Have an existing .env file with contents:
    SOME_VAR=old_value
    
  2. In the Environment section of the Web UI, add some contents, e.g. ANOTHER_VAR=1.
  3. Set Env File Path to: .env
  4. Set Config files to: .env
  5. Image
  6. Click Redeploy

Result:
The contents of the .env file are replaced with the contents of the Environment section.

Originally created by @nisrael on GitHub (Aug 25, 2025). Original GitHub issue: https://github.com/moghtech/komodo/issues/767 Thanks for implementing #716. Unfortunately, we didn’t include the request to make the **Environment** section in the Web UI reflect changes to the `.env` file (and vice versa). So now the existing file is being replaced during the deploy step. **Steps to reproduce:** 1. Have an existing `.env` file with contents: ```env SOME_VAR=old_value ``` 2. In the **Environment** section of the Web UI, add some contents, e.g. `ANOTHER_VAR=1`. 3. Set **Env File Path** to: `.env` 4. Set **Config files** to: `.env` 5. <img width="1210" height="945" alt="Image" src="https://github.com/user-attachments/assets/8e864694-f4fe-4e6a-961b-cb38985345ba" /> 6. Click **Redeploy** **Result:** The contents of the `.env` file are replaced with the contents of the **Environment** section.
Author
Owner

@mbecker20 commented on GitHub (Aug 25, 2025):

First, note that "Additional Env Files" / "Config Files" are available to edit from the Info tab. This is where the changes made to those files are reflected back, and you can use the refresh button to refresh contents from source immediately. Otherwise this is done on the resource_poll_interaval.

The behavior you describe is expected, due to the file name collision in this configuration. It says under "Env File Path" that it will write the contents there to that path, IE overriding existing contents. The 2 simple solutions are:

  • Change "Env File Path" (which Komodo writes) to a different path, like komodo.env, or
  • Change the "Additional Env File" to base.env or something like that, and change it on host / in repo to match

Just make sure these don't collide and you will be good which ever way you want to manage it, or use both features together.

Also, if you keep the Komodo Environment (under Config not Info) all commented out / empty, it won't try to write anything. In this case the file collision is OK.

<!-- gh-comment-id:3219141451 --> @mbecker20 commented on GitHub (Aug 25, 2025): First, note that "Additional Env Files" / "Config Files" are available to edit from the Info tab. This is where the changes made to those files are reflected back, and you can use the refresh button to refresh contents from source immediately. Otherwise this is done on the `resource_poll_interaval`. The behavior you describe is expected, due to the file name collision in this configuration. It says under "Env File Path" that it will write the contents there to that path, IE overriding existing contents. The 2 simple solutions are: - Change "Env File Path" (which Komodo writes) to a different path, like `komodo.env`, **or** - Change the "Additional Env File" to `base.env` or something like that, and change it on host / in repo to match Just make sure these don't collide and you will be good which ever way you want to manage it, or use both features together. Also, if you keep the Komodo Environment (under Config not Info) all commented out / empty, it won't try to write anything. In this case the file collision is OK.
Author
Owner

@TheLinuxGuy commented on GitHub (Aug 25, 2025):

+1 this behavior is working as expected and is not a bug. My recommendation is to solely edit and manage your .env within komodo - rather than having multiple .env files that you expect be magically combined.

<!-- gh-comment-id:3220465168 --> @TheLinuxGuy commented on GitHub (Aug 25, 2025): +1 this behavior is working as expected and is not a bug. My recommendation is to solely edit and manage your .env within komodo - rather than having multiple .env files that you expect be magically combined.
Author
Owner

@nisrael commented on GitHub (Aug 25, 2025):

Thanks for the clarification. I’m now using it as @mbecker20 suggested.

Image

My "problem" is that in our CI/CD pipeline the TAG value in the .env file gets replaced with the image’s commit SHA instead of latest. We do this so we can roll back to a previous image if needed. Also I’d like to keep restarting or redeploying the container easy from both the web UI and the CLI. And with this setup that's possible.

<!-- gh-comment-id:3220631327 --> @nisrael commented on GitHub (Aug 25, 2025): Thanks for the clarification. I’m now using it as @mbecker20 suggested. <img width="1218" height="983" alt="Image" src="https://github.com/user-attachments/assets/ebe1b2a3-8fee-4533-84ed-a336aeddc8be" /> My "problem" is that in our CI/CD pipeline the `TAG` value in the `.env` file gets replaced with the image’s commit SHA instead of `latest`. We do this so we can roll back to a previous image if needed. Also I’d like to keep restarting or redeploying the container easy from both the web UI and the CLI. And with this setup that's possible.
Author
Owner

@Twilek-de commented on GitHub (Aug 25, 2025):

I now can see the contents of the .env file under environment and change them

Image

But if I save the changes in the GUI the file will NOT be written back to the original .env file.
Is this a bug or expected behaviour???

<!-- gh-comment-id:3221528652 --> @Twilek-de commented on GitHub (Aug 25, 2025): I now can see the contents of the .env file under environment and change them <img width="415" height="161" alt="Image" src="https://github.com/user-attachments/assets/99870116-2485-4138-bf6c-6a89aa66b961" /> But if I save the changes in the GUI the file will NOT be written back to the original .env file. Is this a bug or expected behaviour???
Author
Owner

@TheLinuxGuy commented on GitHub (Aug 25, 2025):

Is this a bug or expected behaviour???

Thats WAI.

Komodo managed .env variables at injected at runtime and are NOT dumped into the .env file that gets committed to your repository. This way your secrets are not leaked.

Do note that your .env variables managed by komodo could be leaked if you have setup a ResourceSync job for main.toml - so dump that into a private repository if what you wanted was a backup or viewing the diffs between commits.

<!-- gh-comment-id:3221577468 --> @TheLinuxGuy commented on GitHub (Aug 25, 2025): > Is this a bug or expected behaviour??? Thats WAI. Komodo managed .env variables at injected at runtime and are NOT dumped into the .env file that gets committed to your repository. This way your secrets are not leaked. Do note that your .env variables managed by komodo could be leaked if you have setup a ResourceSync job for main.toml - so dump that into a private repository if what you wanted was a backup or viewing the diffs between commits.
Author
Owner

@mbecker20 commented on GitHub (Aug 25, 2025):

@TheLinuxGuy you use the Komodo Variables in the Komodo Environment to keep those out of your resource sync files / git

<!-- gh-comment-id:3221934922 --> @mbecker20 commented on GitHub (Aug 25, 2025): @TheLinuxGuy you use the Komodo Variables in the Komodo Environment to keep those out of your resource sync files / git
Author
Owner

@mbecker20 commented on GitHub (Aug 25, 2025):

@Twilek-de add repo committed env files to Additional Env Files, and leave Environment under Config commented out. You then edit the env file in the Info tab.

<!-- gh-comment-id:3221939344 --> @mbecker20 commented on GitHub (Aug 25, 2025): @Twilek-de add repo committed env files to Additional Env Files, and leave Environment under Config commented out. You then edit the env file in the Info tab.
Author
Owner

@Twilek-de commented on GitHub (Aug 26, 2025):

Ok, I think this is problem of the lingo. With repo you mean on the server where the compose file also sits, not some github shenanigans?! I just want to edit the .env file which is in the same directory as the compose file on the server without the comments being stripped.

<!-- gh-comment-id:3222822876 --> @Twilek-de commented on GitHub (Aug 26, 2025): Ok, I think this is problem of the lingo. With repo you mean on the server where the compose file also sits, not some github shenanigans?! I just want to edit the .env file which is in the same directory as the compose file on the server without the comments being stripped.
Author
Owner

@mbecker20 commented on GitHub (Aug 26, 2025):

Yes you are correct, just put it next to the compose file. Comments have not been stripped from env in some time.

<!-- gh-comment-id:3224618178 --> @mbecker20 commented on GitHub (Aug 26, 2025): Yes you are correct, just put it next to the compose file. Comments have not been stripped from env in some time.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/komodo#2412