Commit Graph
68 Commits
Author SHA1 Message Date
2950337e48 Add command_as_args option for docker_swarm_service CLI-compatible mapping (#1307)
* fix: map docker_swarm_service command/args to ContainerSpec.Args

docker service create IMAGE [COMMAND] [ARG...] places post-image tokens
into ContainerSpec.Args so the image ENTRYPOINT is preserved. The module
previously wrote command to ContainerSpec.Command, which replaced the
entrypoint and broke flag-style commands such as -config.file=...

Fixes #1044
Fixes #212

* Add command_as_args option for CLI-compatible command mapping

Keep the historical default (command -> ContainerSpec.Command,
args -> ContainerSpec.Args) to avoid a breaking change. When
command_as_args=true, map command+args to ContainerSpec.Args to
match docker service create and preserve the image ENTRYPOINT.

Update docs, examples, unit tests for both modes, and the changelog
fragment. Addresses review feedback on #1307 / #1044.

* Update changelogs/fragments/1044-swarm-service-command-args.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update changelogs/fragments/1044-swarm-service-command-args.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: VedantMadane <vedant@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
2026-08-17 21:32:57 +02:00
Felix FonteinandGitHub ce69e51d73 Fix/improve unit tests (#1281)
* Fix conditional import.

* Don't count lines for code coverage which should never execute.

* Fix tests to use pytest.raises.
2026-06-06 21:27:09 +02:00
Felix FonteinandGitHub 57549c8c73 Add ImageName helper class. (#1210) 2025-12-25 22:41:09 +00:00
Felix Fontein 712d920941 Re-sort imports. 2025-12-25 23:27:25 +01:00
Felix FonteinandGitHub 174c0c8058 Docker Compose 5+: improve image layer event parsing (#1219)
* Remove long deprecated version fields.

* Add first JSON event parsing tests.

* Improve image layer event parsing for Compose 5+.

* Add 'Working' to image working actions.

* Add changelog fragment.

* Shorten lines.

* Adjust docker_compose_v2_run tests.
2025-12-06 17:48:17 +01:00
Felix FonteinandGitHub dbc7b0ec18 Cleanup with ruff check (#1182)
* Implement improvements suggested by ruff check.

* Add ruff check to CI.
2025-10-28 06:58:15 +01:00
Felix FonteinandGitHub be000755fc Python code modernization, 8/n (#1179)
* Use to_text instead of to_native.

* Remove no longer needed pylint ignores.

* Remove another pylint ignore.

* Remove no longer needed ignore.

* Address redefined-outer-name.

* Address consider-using-with.
2025-10-25 00:36:04 +00:00
Felix FonteinandGitHub 6ad4bfcd40 Add typing information, 2/n (#1178)
* Add typing to Docker Stack modules. Clean modules up.

* Add typing to Docker Swarm modules.

* Add typing to unit tests.

* Add more typing.

* Add ignore.txt entries.
2025-10-25 01:16:04 +02:00
Felix FonteinandGitHub 3350283bcc Add typing information, 1/2 (#1176)
* Re-enable typing and improve config.

* Make mypy pass.

* Improve settings.

* First batch of types.

* Add more type hints.

* Fixes.

* Format.

* Fix split_port() without returning to previous type chaos.

* Continue with type hints (and ignores).
2025-10-23 07:05:42 +02:00
Felix FonteinandGitHub 597162b153 Avoid Python 2 compat (conditional) imports. (#1167) 2025-10-13 22:31:59 +02:00
Felix Fontein 6f9ebc3f14 Fix issues with pylint 4.0. 2025-10-13 22:09:31 +02:00
Felix FonteinandGitHub c75aa5dd64 Python code modernization, 5/n (#1165)
* Address raise-missing-from.

* Address simplifiable-if-expression.

* Address unnecessary-dunder-call.

* Address unnecessary-pass.

* Address use-list-literal.

* Address unused-variable.

* Address use-dict-literal.
2025-10-12 16:02:27 +02:00
Felix FonteinandGitHub cad22de628 Python code modernization, 4/n (#1162)
* Address attribute-defined-outside-init.

* Address broad-exception-raised.

* Address broad-exception-caught.

* Address consider-iterating-dictionary.

* Address consider-using-dict-comprehension.

* Address consider-using-f-string.

* Address consider-using-in.

* Address consider-using-max-builtin.

* Address some consider-using-with.

* Address invalid-name.

* Address keyword-arg-before-vararg.

* Address line-too-long.

* Address no-else-continue.

* Address no-else-raise.

* Address no-else-return.

* Remove broken dead code.

* Make consider-using-f-string changes compatible with older Python versions.

* Python 3.11 and earlier apparently do not like multi-line f-strings.
2025-10-11 23:06:50 +02:00
Felix Fontein 892e9d9cbd Reorganize imports due to https://github.com/ansible-community/antsibull-nox/pull/136. 2025-10-10 21:19:28 +02:00
Felix FonteinandGitHub e8ec22d3b1 Python code modernization, 3/n (#1157)
* Remove __metaclass__ = type.

for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do
  sed -e '/^__metaclass__ = type/d' -i $i;
done

* Remove super arguments, and stop inheriting from object.
2025-10-10 08:11:58 +02:00
Felix FonteinandGitHub 741c318b1d Python code modernization, 2/n (#1156)
* Adjust all __future__ imports:

for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do
  sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i;
done

* Remove all UTF-8 encoding specifications for Python source files:

for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do
  sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i;
done

* Reformat.
2025-10-09 20:46:48 +02:00
Felix FonteinandGitHub a3efa26e2e Address some pylint issues (#1155)
* Address cyclic-import.

* Address redefined-builtin.

* Address redefined-argument-from-local.

* Address many redefined-outer-name.

* Address pointless-string-statement.

* No longer needed due to separate bugfix.

* Address useless-return.

* Address possibly-used-before-assignment.

* Add TODOs.

* Address super-init-not-called.

* Address function-redefined.

* Address unspecified-encoding.

* Clean up more imports.
2025-10-09 20:11:36 +02:00
Felix FonteinandGitHub acf18f0ade Add more CI checks (#1150)
* Enable mypy.

* Add flake8.

* Add pylint with a long list of ignores to be removed.
2025-10-07 19:37:16 +02:00
Felix FonteinandGitHub 117271579e Make all doc fragments, module utils, and plugin utils private (#1144)
* Make all doc fragments, module utils, and plugin utils private.

* Remove some unused and no longer needed imports.

This hopefully also fixes the CI issues, which do not happen locally for me...

* Fix formatting.

* Try to make CI happy, again.

* Fix imports.

* Lint.
2025-10-07 07:32:33 +02:00
Felix Fontein d65d37e9e9 Reformat code with black and isort. 2025-10-06 18:34:59 +02:00
Felix FonteinandGitHub f45232635c Python code modernization, 1/n (#1141)
* Remove unicode text prefixes.

* Replace str.format() uses with f-strings.

* Replace % with f-strings, and do some cleanup.

* Fix wrong variable.

* Avoid unnecessary string conversion.
2025-10-06 18:30:54 +02:00
Felix FonteinandGitHub 1f2817fa20 Prepare 5.0.0 (#1123)
* Bump version to 5.0.0-a1.

* Drop support for ansible-core 2.15 and 2.16.

* Remove Python 2 and early Python 3 compatibility.
2025-10-05 20:22:50 +02:00
Felix FonteinandGitHub ebe42308cc Replace ansible.module_utils.six with own module utils in some cases (#1138)
* Replace ansible.module_utils.six with own module utils in some cases.

* Add ignore.txt entires.
2025-10-04 23:45:27 +02:00
Felix FonteinandGitHub 1902e0fdf2 Avoid six in plugin code. (#1137) 2025-10-04 21:51:59 +02:00
Felix FonteinandGitHub ad989c1942 docker_container_copy_into: add mode_parse option (#1074)
* Add mode_parse option.

* Make yamllint config strict.

* Lint.
2025-04-28 20:46:11 +02:00
Felix Fontein 2487d1a0bf Fix linting errors. 2025-04-26 12:39:00 +02:00
Felix FonteinandGitHub a1e9412bed Use new tools from community.internal_test_tools. (#1061) 2025-03-22 11:59:27 +01:00
Felix FonteinandGitHub 9730b2a3c3 Use shared unit test utils from community.internal_test_tools. (#1056) 2025-03-12 21:39:05 +01:00
Felix FonteinandGitHub fdb97428a3 Fix/improve tests (#1052)
* Improve unit test condition.

* Improve/fix tests.
2025-03-08 09:54:41 +01:00
Felix FonteinandGitHub 3b6068e44b Add docker_context_info module (#1039)
* Vendor parts of the Docker SDK for Python

This is a combination of the latest git version
(https://github.com/docker/docker-py/tree/db7f8b8bb67e485a7192846906f600a52e0aa623)
with some fixes to make it compatible with Python 2.7
and adjusting some imports.

* Polishing.

* Fix bug that prevents contexts to be found when no Docker config file is present.

Ref: https://github.com/docker/docker-py/issues/3190

* Linting.

* Fix typos.

* Adjust more to behavior of Docker CLI.

* Add first iteration of docker_context_info module.

* Improvements.

* Add basic CI.

* Add caveat on contexts[].config result.
2025-02-10 21:59:05 +01:00
Felix FonteinandGitHub bcd6e57450 Vendored Docker SDK for Python code: remove unused constants (#1037)
* Remove constants that are never used.

* Adjust unit tests.
2025-02-01 23:14:19 +01:00
Felix FonteinandGitHub 8616e7f6f2 docker_image_build: work around strange behavior of docker buildx build when --output is provided (#1006)
* Work around strange behavior of docker buildx build when --output is provided.

* Adjust tests.

* Allow to pass multiple image names; correctly quote --output values.

* Return executed command.

* Adjust tests.
2024-12-14 21:32:33 +01:00
Felix FonteinandGitHub a740cfa0c4 Add more tests. (#980) 2024-10-19 22:07:06 +02:00
d8cefc4190 Fix typo in Docker connection tests. (#964)
Co-authored-by: x4e-jonas <x4e-jonas@users.noreply.github.com>
2024-09-09 15:28:17 +02:00
Felix FonteinandGitHub 3cc27ecd65 Handle yet another random unstructured error output. (#949) 2024-08-07 15:58:23 +02:00
Felix FonteinandGitHub 48c0cdf2c5 Imporve parsing of skipped messages. (#916) 2024-07-06 21:10:39 +02:00
Felix FonteinandGitHub 2eb2c9febf Add test for unsafe plugin util. (#856) 2024-05-12 01:00:50 +02:00
Felix FonteinandGitHub 8ad45286a3 Remove unused code that relies on functionality deprecated in Python 3.12. (#834) 2024-04-15 11:21:46 +00:00
Felix FonteinandGitHub 6aea7efed9 Improve parsing of warnings and errors (#811)
* Add logfmt message parser.

* Parse logfmt formatted warnings.

* Follow-up for #810.

* Fix handling of warning and error messages.

* Make Python 2 compatible.

* Linting. Improving tests.
2024-03-03 13:38:55 +00:00
Felix FonteinandGitHub 7b554082ea Improve parsing. (#786) 2024-02-01 17:52:31 +00:00
Felix FonteinandGitHub b5d085bb88 Parse build events from stderr. (#779) 2024-01-25 06:40:32 +01:00
Felix FonteinandGitHub f429017d94 Add inventory filter capability (#698)
* Add inventory filter capability.

* Use community.library_inventory_filtering_v1 collection.

* Bump dependency to 1.0.0.

* Mention the new dependency in the changelog.
2024-01-13 15:51:02 +01:00
Felix FonteinandGitHub 97a0610f25 Docker Compose v2: extend/improve event parsing tests (#752)
* Normalize ansible-docker-test-xxx in stderr logs.

* Deduplicate.

* Add new testcases including the new module.
2024-01-13 15:49:30 +01:00
Felix FonteinandGitHub cb4dd2fed1 docker_compose_v2: move some code to module_utils (#747)
* Move some code to module_utils.

* Add unit tests.

Test cases are auto-generated from integration test logs.

* Rename ResourceEvent → Event.
2024-01-07 16:17:31 +01:00
4d9b85c975 Update vendored Docker SDK for Python code (#694)
* vendored Docker SDK for Python code: volume: added support for bind propagation

https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation

Cherry-picked from https://github.com/docker/docker-py/commit/bea63224e028226085c85caecace6480fe0aa6b0

Co-authored-by: Janne Jakob Fleischer <janne.fleischer@ils-forschung.de>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* vendored Docker SDK for Python code: fix: eventlet compatibility

Check if poll attribute exists on select module instead of win32 platform check

The implementation done in #2865 is breaking usage of docker-py library within eventlet.
As per the Python `select.poll` documentation (https://docs.python.org/3/library/select.html#select.poll) and eventlet select removal advice (eventlet/eventlet#608 (comment)), it is preferable to use an implementation based on the availability of the `poll()` method that trying to check if the platform is `win32`.

Fixes https://github.com/docker/docker-py/issues/3131

Cherry-picked from https://github.com/docker/docker-py/commit/78439ebbe1aae77ff0fd9b666894d80807182e28

Co-authored-by: Mathieu Virbel <mat@meltingrocks.com>

* vendored Docker SDK for Python code: fix: use response.text to get string rather than bytes

Adjusted from https://github.com/docker/docker-py/commit/0618951093bf3116af482c6dfb983219c5684343

Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>

* vendored Docker SDK for Python code: Fix missing asserts or assignments

Cherry-picked from https://github.com/docker/docker-py/commit/0566f1260cd6f89588df2128ec4e86e8266e5d74

Co-authored-by: Aarni Koskela <akx@iki.fi>

---------

Co-authored-by: Janne Jakob Fleischer <janne.fleischer@ils-forschung.de>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>
Co-authored-by: Mathieu Virbel <mat@meltingrocks.com>
Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: Aarni Koskela <akx@iki.fi>
2023-10-08 18:16:27 +02:00
Felix FonteinandGitHub 92fc542c00 Make unit tests work with Python 3.12. (#673) 2023-07-23 22:33:07 +02:00
Felix FonteinandGitHub 74b70f81c8 Switch to Ansible Galaxy compatible requirements files for tests. (#633) 2023-05-21 13:54:35 +02:00
Felix FonteinandGitHub 449b91d489 Remove unnecessary test imports. (#583) 2023-02-12 20:59:51 +01:00
e198e4ab43 Add docker_container_copy_into module (#545)
* Move copying functionality to module_utils.

* Add docker_container_copy_into module.

* Use new module in other tests.

* Fix copyright and attributes.

* Improve idempotency, improve stat code.

* Document and test when a stopped container works.

* Improve owner/group detection error handling when container is stopped.

* Fix formulation.

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

* Improve file comparison.

* Avoid reading whole file at once.

* Stream when fetching files from daemon.

* Fix comment.

* Use read() instead of read1().

* Stream files when copying into container.

* Linting.

* Add force parameter.

* Simplify library code.

* Linting.

* Add content and content_is_b64 options.

* Make force=false work as for copy module: only copy if the destination does not exist.

* Improve docs.

* content should be no_log.

* Implement diff mode.

* Improve error handling.

* Lint and improve.

* Set owner/group ID to avoid ID lookup (which fails in paused containers).

* Apply suggestions from code review

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
2023-01-09 11:52:29 +01:00
iamjpottsandGitHub 166d485216 Make image archive/save idempotent, using image id and repo tags as keys (#500) 2022-11-30 23:45:36 +01:00