fix: pass env vars via Docker exec API instead of prepending to command#920
Open
gal432 wants to merge 1 commit intotestcontainers:mainfrom
Open
fix: pass env vars via Docker exec API instead of prepending to command#920gal432 wants to merge 1 commit intotestcontainers:mainfrom
gal432 wants to merge 1 commit intotestcontainers:mainfrom
Conversation
ContainerisedComposeCli::up() was prepending env vars as "KEY=VALUE" strings at the beginning of the exec command array. Docker's exec API treats the first element as the binary to run, so it tried to execute "KEY=VALUE" as a command, resulting in exit code 127. Instead of shell-wrapping, this fix adds env_vars support to ExecCommand and propagates it through to bollard's CreateExecOptions.env field, which is the native Docker exec API mechanism for passing environment variables to an exec process. Fixes testcontainers#919 Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Deploy Preview for testcontainers-rust ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
54238bf to
8ba7927
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ContainerisedComposeCli::up()failing with exit code 127 when env vars are passed viawith_env(). The root cause was that env vars were prepended asKEY=VALUEstrings to the exec command array, and Docker's exec API treats the first element as the binary to execute.sh -c, this fix adds nativeenv_varssupport toExecCommandand propagates it through to bollard'sCreateExecOptions.envfield, which is the Docker exec API's built-in mechanism for passing environment variables.ExecCommand::with_env_vars()available as a public API for any user ofexec(), not just the compose client.Changes
core/image/exec.rsenv_vars: HashMap<String, String>field andwith_env_vars()builder method toExecCommandcore/containers/async_container/raw.rsenv_varsfromExecCommandto the Docker clientcore/client.rsenv_varsparam inexec(), convert toKEY=VALUEformat, pass toCreateExecOptions.envcompose/client/containerised.rsExecCommand::with_env_vars()insteadTest plan
test_compose_with_build_and_down— exerciseswith_env()on local clienttest_containerised_client_mode— exercises containerised client pathtest_with_env_vars— unit test for the newExecCommand::with_env_vars()APItest_local_docker_compose,test_local_client_mode)Fixes #919
Made with Cursor