Skip to content

Commit

Permalink
Rewrite docker_container to use Docker API directly (#422)
Browse files Browse the repository at this point in the history
* Begin experiments for docker_container rewrite.

* Continued.

* We support API >= 1.25 only anyway.

* Continued.

* Fix bugs.

* Complete first basic implementation.

* Continuing.

* Improvements and fixes.

* Continuing.

* More 'easy' options.

* More options.

* Work on volumes and mounts.

* Add more options.

* The last option.

* Copy over.

* Fix exposed ports.

* Fix bugs.

* Fix command and entrypoint.

* More fixes.

* Fix more bugs.

* ci_complete

* Lint, fix Python 2.7 bugs, work around ansible-test bug.

ci_complete

* Remove no longer applicable test.

ci_complete

* Remove unnecessary ignore.

ci_complete

* Start with engine driver.

* Refactoring.

* Avoid using anything Docker specific from self.client.

* Refactor.

* Add Python 2.6 ignore.txt entries for ansible-core < 2.12.

* Improve healthcheck handling.

* Fix container removal logic.

* ci_complete

* Remove handling of older Docker SDK for Pyhon versions from integration tests.

* Avoid recreation if a pure update is possible without losing the diff data.

* Cover the case that blkio_weight does not work.

* Update plugins/module_utils/module_container/docker_api.py

Co-authored-by: Brian Scholer <[email protected]>

* Improve memory_swap tests.

* Fix URLs in changelog fragment.

Co-authored-by: Brian Scholer <[email protected]>
  • Loading branch information
felixfontein and briantist authored Jul 15, 2022
1 parent 04121b5 commit 77e63e2
Show file tree
Hide file tree
Showing 21 changed files with 4,127 additions and 3,243 deletions.
11 changes: 11 additions & 0 deletions changelogs/fragments/docker_container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
major_changes:
- "docker_container - no longer uses the Docker SDK for Python. It requires ``requests`` to be installed,
and depending on the features used has some more requirements. If the Docker SDK for Python is installed,
these requirements are likely met (https://github.com/ansible-collections/community.docker/pull/422)."
- "docker_container - the module was completely rewritten from scratch (https://github.com/ansible-collections/community.docker/pull/422)."
breaking_changes:
- "docker_container - ``publish_all_ports`` is no longer ignored in ``comparisons`` (https://github.com/ansible-collections/community.docker/pull/422)."
- "docker_container - ``exposed_ports`` is no longer ignored in ``comparisons``. Before, its value was assumed to be identical with the value of ``published_ports`` (https://github.com/ansible-collections/community.docker/pull/422)."
- "docker_container - ``log_options`` can no longer be specified when ``log_driver`` is not specified (https://github.com/ansible-collections/community.docker/pull/422)."
- "docker_container - ``restart_retries`` can no longer be specified when ``restart_policy`` is not specified (https://github.com/ansible-collections/community.docker/pull/422)."
- "docker_container - ``stop_timeout`` is no longer ignored for idempotency if told to be not ignored in ``comparisons``. So far it defaulted to ``ignore`` there, and setting it to ``strict`` had no effect (https://github.com/ansible-collections/community.docker/pull/422)."
3 changes: 3 additions & 0 deletions plugins/module_utils/_api/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ def delete_call(self, pathfmt, *args, **kwargs):
def delete_json(self, pathfmt, *args, **kwargs):
return self._result(self._delete(self._url(pathfmt, *args, versioned_api=True), **kwargs), json=True)

def post_call(self, pathfmt, *args, **kwargs):
self._raise_for_status(self._post(self._url(pathfmt, *args, versioned_api=True), **kwargs))

def post_json(self, pathfmt, *args, **kwargs):
data = kwargs.pop('data', None)
self._raise_for_status(self._post_json(self._url(pathfmt, *args, versioned_api=True), data, **kwargs))
Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ def inspect_distribution(self, image, **kwargs):
class AnsibleDockerClient(AnsibleDockerClientBase):

def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclusive=None,
required_together=None, required_if=None, required_one_of=None, min_docker_version=None,
min_docker_api_version=None, option_minimal_versions=None,
required_together=None, required_if=None, required_one_of=None, required_by=None,
min_docker_version=None, min_docker_api_version=None, option_minimal_versions=None,
option_minimal_versions_ignore_params=None, fail_results=None):

# Modules can put information in here which will always be returned
Expand Down Expand Up @@ -588,6 +588,7 @@ def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclu
required_together=required_together_params,
required_if=required_if,
required_one_of=required_one_of,
required_by=required_by or {},
)

self.debug = self.module.params.get('debug')
Expand Down
3 changes: 2 additions & 1 deletion plugins/module_utils/common_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def pull_image(self, name, tag="latest", platform=None):
class AnsibleDockerClient(AnsibleDockerClientBase):

def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclusive=None,
required_together=None, required_if=None, required_one_of=None,
required_together=None, required_if=None, required_one_of=None, required_by=None,
min_docker_api_version=None, option_minimal_versions=None,
option_minimal_versions_ignore_params=None, fail_results=None):

Expand Down Expand Up @@ -498,6 +498,7 @@ def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclu
required_together=required_together_params,
required_if=required_if,
required_one_of=required_one_of,
required_by=required_by or {},
)

self.debug = self.module.params.get('debug')
Expand Down
Loading

0 comments on commit 77e63e2

Please sign in to comment.