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

docker_container_exec: improve handling of chdir option #243

Merged
merged 2 commits into from
Nov 30, 2021

Conversation

felixfontein
Copy link
Collaborator

SUMMARY

Only pass chdir on when it is provided, and prevent this option from being used for Docker SDK for Python < 3.0.0

The workdir option was added to exec_create in 3.0.0: docker/docker-py@abd60ae

Fixes #242.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

docker_container_exec

@felixfontein
Copy link
Collaborator Author

The same problem also happens for the docker_api connection plugin, though there the parameter is actually unnecessary since always None is passed. I've commented it out in 1430b7d.

@felixfontein
Copy link
Collaborator Author

Would be glad if anyone could review this :)

Comment on lines +166 to +168
option_minimal_versions = dict(
chdir=dict(docker_py_version='3.0.0'),
)
Copy link

Choose a reason for hiding this comment

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

holy ravioli, I hadn't seen this construct before, is it new? awesome :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's actually pretty old ;-) I originally created it for docker_container, since it has sooo many options and these have so many different requirements...

Copy link

Choose a reason for hiding this comment

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

Cool, will take a look at it!

@@ -164,7 +164,7 @@ def exec_command(self, cmd, in_data=None, sudoable=False):
stderr=True,
stdin=need_stdin,
user=self._play_context.remote_user or '',
workdir=None,
# workdir=None, - only works for Docker SDK for Python 3.0.0 and later
Copy link

Choose a reason for hiding this comment

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

shouldn't it be deprecated instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, right now this isn't used at all (None is the default value anyway, which means "use whatever working dir the container is using anyway"). Having this always present only breaks usage wiht Docker SDK for Python < 3.0.0, but doesn't have any effect on >= 3.0.0.

Copy link

@russoz russoz left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +166 to +168
option_minimal_versions = dict(
chdir=dict(docker_py_version='3.0.0'),
)
Copy link

Choose a reason for hiding this comment

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

Cool, will take a look at it!

@felixfontein felixfontein merged commit bed775c into ansible-collections:main Nov 30, 2021
@patchback
Copy link

patchback bot commented Nov 30, 2021

Backport to stable-1: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-1/bed775c4ea7be62ae3ffa620b478ffb67523fe7f/pr-243

Backported as #247

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein deleted the exec-workdir branch November 30, 2021 08:14
patchback bot pushed a commit that referenced this pull request Nov 30, 2021
* Only pass chdir on when it is provided, and prevent this option from being used for Docker SDK for Python < 3.0.0.

* Also fix docker_api connection plugin.

(cherry picked from commit bed775c)
@felixfontein
Copy link
Collaborator Author

@russoz thanks a lot for reviewing this!

felixfontein added a commit that referenced this pull request Nov 30, 2021
* Only pass chdir on when it is provided, and prevent this option from being used for Docker SDK for Python < 3.0.0.

* Also fix docker_api connection plugin.

(cherry picked from commit bed775c)

Co-authored-by: Felix Fontein <felix@fontein.de>
@felixfontein felixfontein mentioned this pull request Dec 1, 2021
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_Container_Exec - TypeError: exec_create() got an unexpected keyword argument 'workdir'
2 participants