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

Allow for multiple env-files #616

Merged

Conversation

einarwar
Copy link
Contributor

@einarwar einarwar commented Aug 1, 2024

Sorry for the mess with multiple PRs, not used to making PR's from forks :)

Closes #553

Keeps backwards compatibility with the compose_env_file parameter, but advises the user to use the new compose_env_files parameter instead. If both parameters are given, the compose_env_files will take presedence.

Added tests to verify behavior

Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good! Many thanks! I think we just need one additional test to be confident about the implementation

assert client_config.docker_compose_cmd[index + 1] == env_file


def test_compose_env_files_and_env_file():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are good, keep them :) I'd also like a test which actually runs the docker compose command and checks that the env files are loaded correctly. For example with docker.compose.config(). If for example, you made a typo in --env-file in the unit test and the main implementation, your tests can't currently detect it. Running the true command in test would detect such an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some more tests now that actually run the command by using the equivalent of docker compose run. Some temporary env-files are made, and the containers are then inspected to verify that the actual environment variables set in the container are as expected. Pretty verbose, and I am sure it can be done simpler, but let me know if this is what you wanted :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than running the containers, using https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/#python_on_whales.components.compose.cli_wrapper.ComposeCLI.config would have made the test simpler no? just switch docker.compose.run for docker.compose.config()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, yeah that is a lot simpler. Updated now :)

Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant to request changes

Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks!

@gabrieldemarmiesse gabrieldemarmiesse merged commit 69b2ac3 into gabrieldemarmiesse:master Aug 15, 2024
38 checks passed
@einarwar einarwar deleted the multiple-env-files branch August 15, 2024 10:02
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.

Docker compose support for multiple env files (--env-file, compose_env_file)
2 participants