Skip to content

chore: Better handle the user-provided .env file - #35

Merged
rm3l merged 5 commits into
redhat-developer:mainfrom
rm3l:RHIDP-4263--independent-user-config--better-handling-of-.env
Apr 16, 2025
Merged

chore: Better handle the user-provided .env file#35
rm3l merged 5 commits into
redhat-developer:mainfrom
rm3l:RHIDP-4263--independent-user-config--better-handling-of-.env

Conversation

@rm3l

@rm3l rm3l commented Mar 21, 2025

Copy link
Copy Markdown
Member

Description

This PR updates the Compose manifest by declaring two env_files:

  • one is the default and is mandatory
  • the second one is optional and can be provided by the user

What's interesting here is that, per the Compose spec [1], the files would be evaluated in order and can override values set in previous files.
This means that the user-provided .env file does not need to be an exact copy of the default (previously env.sample), but can just contain overrides for the variables needed (or define new ones).

I confirmed this behavior locally with both Podman Compose and Docker Compose.

[1] https://github.com/compose-spec/compose-spec/blob/main/spec.md#env_file

Which issue(s) does this PR fix or relate to

PR acceptance criteria

  • Tests
  • Documentation

How to test changes / Special notes to the reviewer

Running podman compose up -d or docker compose up -d should work even if there is no local .env file. The .env file also does not need to be a copy of default.env - it can just contain the necessary overrides or define extra env vars.

/cc @kadel @benwilcock

@openshift-ci
openshift-ci Bot requested review from benwilcock and kadel March 21, 2025 17:32
rm3l added 3 commits March 21, 2025 18:38
@rm3l
rm3l force-pushed the RHIDP-4263--independent-user-config--better-handling-of-.env branch from bdb3eea to 9a86c30 Compare March 21, 2025 17:38
Otherwise, the env_file attribute is not used for variable substitution in the compose.yaml file, unless it is is a .env file
@rm3l
rm3l force-pushed the RHIDP-4263--independent-user-config--better-handling-of-.env branch from 0837d41 to 7cebea0 Compare March 21, 2025 17:52
Useless because there is a default fallback value
@rm3l
rm3l merged commit 96daed5 into redhat-developer:main Apr 16, 2025
@rm3l
rm3l deleted the RHIDP-4263--independent-user-config--better-handling-of-.env branch April 16, 2025 16:35
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.

2 participants