-
Notifications
You must be signed in to change notification settings - Fork 356
feat(core): Add support for working with env files #684
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
Closed
Closed
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e6ed27f
feat(main): Add support to working with env files
Tranquility2 871c04f
Merge branch 'main' into with_env_file
Tranquility2 4816716
Merge branch 'main' into with_env_file
Tranquility2 3b0f8e1
Merge branch 'main' into with_env_file
Tranquility2 a5a6d5e
update lock
Tranquility2 d4754e5
Merge branch 'main' into with_env_file
Tranquility2 53f3e9d
fix
Tranquility2 def68e0
Merge branch 'main' into with_env_file
Tranquility2 36f1628
Merge branch 'main' into with_env_file
Tranquility2 a6d133e
Merge branch 'main' into with_env_file
Tranquility2 59e1dec
Merge branch 'main' into with_env_file
Tranquility2 ab0f839
fix lint
Tranquility2 ae3d162
Merge branch 'main' into with_env_file
Tranquility2 3f5f902
Merge branch 'main' into with_env_file
Tranquility2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| from testcontainers.core.container import DockerContainer | ||
|
|
||
|
|
||
|
|
@@ -17,3 +20,29 @@ def test_get_logs(): | |
| assert isinstance(stdout, bytes) | ||
| assert isinstance(stderr, bytes) | ||
| assert "Hello from Docker".encode() in stdout, "There should be something on stdout" | ||
|
|
||
|
|
||
| def test_docker_container_with_env_file(): | ||
| """Test that environment variables can be loaded from a file""" | ||
| with tempfile.TemporaryDirectory() as temp_directory: | ||
| env_file_path = Path(temp_directory) / "env_file" | ||
| with open(env_file_path, "w") as f: | ||
| f.write( | ||
| """ | ||
| TEST_ENV_VAR=hello | ||
| NUMBER=123 | ||
| DOMAIN=example.org | ||
| ADMIN_EMAIL=admin@${DOMAIN} | ||
| ROOT_URL=${DOMAIN}/app | ||
| """ | ||
| ) | ||
| container = DockerContainer("alpine").with_command("tail -f /dev/null") # Keep the container running | ||
| container.with_env_file(env_file_path) # Load the environment variables from the file | ||
| with container: | ||
| output = container.exec("env").output.decode("utf-8").strip() | ||
| assert "TEST_ENV_VAR=hello" in output | ||
| assert "NUMBER=123" in output | ||
| assert "DOMAIN=example.org" in output | ||
| assert "[email protected]" in output | ||
| assert "ROOT_URL=example.org/app" in output | ||
| print(output) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.