From b12d156a567d052fa39366418c9a7d0637e3751e Mon Sep 17 00:00:00 2001 From: Christoph Sieber Date: Wed, 16 Oct 2024 17:26:26 +0200 Subject: [PATCH 1/5] add `renew_anon_volumes` parameter to `docker compose up` --- plugins/modules/docker_compose_v2.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/modules/docker_compose_v2.py b/plugins/modules/docker_compose_v2.py index 5ed873bb1..77156bb72 100644 --- a/plugins/modules/docker_compose_v2.py +++ b/plugins/modules/docker_compose_v2.py @@ -93,6 +93,12 @@ - always - never - auto + renew_anon_volumes: + description: + - Whether to recreate instead of reuse anonymous volumes from previous containers + - V(true) is equivalent to the C(--renew-anon-volumes) or C(-V) option of C(docker compose up) + type: bool + default: false remove_images: description: - Use with O(state=absent) to remove all images or only local images. @@ -437,6 +443,7 @@ def __init__(self, client): self.remove_images = parameters['remove_images'] self.remove_volumes = parameters['remove_volumes'] self.remove_orphans = parameters['remove_orphans'] + self.renew_anon_volumes = parameters['renew_anon_volumes'] self.timeout = parameters['timeout'] self.services = parameters['services'] or [] self.scale = parameters['scale'] or {} @@ -479,6 +486,8 @@ def get_up_cmd(self, dry_run, no_start=False): args.append('--force-recreate') if self.recreate == 'never': args.append('--no-recreate') + if self.renew_anon_volumes: + args.append('--renew-anon-volumes') if not self.dependencies: args.append('--no-deps') if self.timeout is not None: @@ -621,6 +630,7 @@ def main(): pull=dict(type='str', choices=['always', 'missing', 'never', 'policy'], default='policy'), build=dict(type='str', choices=['always', 'never', 'policy'], default='policy'), recreate=dict(type='str', default='auto', choices=['always', 'never', 'auto']), + renew_anon_volumes=dict(type='bool',default=False), remove_images=dict(type='str', choices=['all', 'local']), remove_volumes=dict(type='bool', default=False), remove_orphans=dict(type='bool', default=False), From 039449f9d1dc0e36d914ab433e6fdf4e6b52e862 Mon Sep 17 00:00:00 2001 From: Christoph <43646576+z-bsod@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:44:09 +0200 Subject: [PATCH 2/5] Apply suggestions from code review Apply suggested changes to Documentation Co-authored-by: Felix Fontein --- plugins/modules/docker_compose_v2.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/docker_compose_v2.py b/plugins/modules/docker_compose_v2.py index 77156bb72..1a7cb1987 100644 --- a/plugins/modules/docker_compose_v2.py +++ b/plugins/modules/docker_compose_v2.py @@ -95,10 +95,11 @@ - auto renew_anon_volumes: description: - - Whether to recreate instead of reuse anonymous volumes from previous containers - - V(true) is equivalent to the C(--renew-anon-volumes) or C(-V) option of C(docker compose up) + - Whether to recreate instead of reuse anonymous volumes from previous containers. + - V(true) is equivalent to the C(--renew-anon-volumes) option of C(docker compose up). type: bool default: false + version_added: 4.0.0 remove_images: description: - Use with O(state=absent) to remove all images or only local images. From e7b468c0ae9faa7423842d50780294e4d1d2aae9 Mon Sep 17 00:00:00 2001 From: Christoph <43646576+z-bsod@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:44:47 +0200 Subject: [PATCH 3/5] Fix sanity check error apply suggestion from code review Co-authored-by: Felix Fontein --- plugins/modules/docker_compose_v2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/docker_compose_v2.py b/plugins/modules/docker_compose_v2.py index 1a7cb1987..146424580 100644 --- a/plugins/modules/docker_compose_v2.py +++ b/plugins/modules/docker_compose_v2.py @@ -631,7 +631,7 @@ def main(): pull=dict(type='str', choices=['always', 'missing', 'never', 'policy'], default='policy'), build=dict(type='str', choices=['always', 'never', 'policy'], default='policy'), recreate=dict(type='str', default='auto', choices=['always', 'never', 'auto']), - renew_anon_volumes=dict(type='bool',default=False), + renew_anon_volumes=dict(type='bool', default=False), remove_images=dict(type='str', choices=['all', 'local']), remove_volumes=dict(type='bool', default=False), remove_orphans=dict(type='bool', default=False), From c77ae1008d85c674b807e4b0a78e0a967b48d9c4 Mon Sep 17 00:00:00 2001 From: Christoph Sieber Date: Sat, 19 Oct 2024 13:39:49 +0200 Subject: [PATCH 4/5] add changelog fragment for PR #977 --- changelogs/fragments/977-renew_anon_volumes.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/977-renew_anon_volumes.yaml diff --git a/changelogs/fragments/977-renew_anon_volumes.yaml b/changelogs/fragments/977-renew_anon_volumes.yaml new file mode 100644 index 000000000..a035289d8 --- /dev/null +++ b/changelogs/fragments/977-renew_anon_volumes.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - docker_compose_v2 - add renew_anon_volumes parameter for docker compose up From b54c6be1fbfb3e602a371120940cb30668dfc42c Mon Sep 17 00:00:00 2001 From: Christoph <43646576+z-bsod@users.noreply.github.com> Date: Sat, 19 Oct 2024 14:13:36 +0200 Subject: [PATCH 5/5] apply suggested changes to changelog fragment Co-authored-by: Felix Fontein --- changelogs/fragments/977-renew_anon_volumes.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/977-renew_anon_volumes.yaml b/changelogs/fragments/977-renew_anon_volumes.yaml index a035289d8..a457203e4 100644 --- a/changelogs/fragments/977-renew_anon_volumes.yaml +++ b/changelogs/fragments/977-renew_anon_volumes.yaml @@ -1,3 +1,3 @@ --- minor_changes: - - docker_compose_v2 - add renew_anon_volumes parameter for docker compose up + - docker_compose_v2 - add ``renew_anon_volumes`` parameter for ``docker compose up`` (https://github.com/ansible-collections/community.docker/pull/977).