Skip to content

Commit

Permalink
Add new options for --ignore-buildable, --include-deps, and for provi…
Browse files Browse the repository at this point in the history
…ding services.
  • Loading branch information
felixfontein committed Jul 25, 2024
1 parent 45b2531 commit e4819f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/942-compose-v2-pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- "docker_compose_v2_pull - add new options ``ignore_buildable``, ``include_deps``, and ``services``
(https://github.com/ansible-collections/community.docker/issues/941, https://github.com/ansible-collections/community.docker/pull/942)."
35 changes: 35 additions & 0 deletions plugins/modules/docker_compose_v2_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@
- always
- missing
default: always
ignore_buildable:
description:
- If set to V(true), will not pull images that can be built.
type: bool
default: false
version_added: 3.12.0
include_deps:
description:
- If set to V(true), also pull services that are declared as dependencies.
- This only makes sense if O(services) is used.
type: bool
default: false
version_added: 3.12.0
services:
description:
- Specifies a subset of services to be targeted.
type: list
elements: str
version_added: 3.12.0
author:
- Felix Fontein (@felixfontein)
Expand Down Expand Up @@ -114,19 +133,32 @@ def __init__(self, client):
parameters = self.client.module.params

self.policy = parameters['policy']
self.ignore_buildable = parameters['ignore_buildable']
self.include_deps = parameters['include_deps']
self.services = parameters['services'] or []

if self.policy != 'always' and self.compose_version < LooseVersion('2.22.0'):
# https://github.com/docker/compose/pull/10981 - 2.22.0
self.fail('A pull policy other than always is only supported since Docker Compose 2.22.0. {0} has version {1}'.format(
self.client.get_cli(), self.compose_version))
if self.ignore_buildable and self.compose_version < LooseVersion('2.15.0'):
# https://github.com/docker/compose/pull/10134 - 2.15.0
self.fail('--ignore-buildable is only supported since Docker Compose 2.15.0. {0} has version {1}'.format(
self.client.get_cli(), self.compose_version))

def get_pull_cmd(self, dry_run, no_start=False):
args = self.get_base_args() + ['pull']
if self.policy != 'always':
args.extend(['--policy', self.policy])
if self.ignore_buildable:
args.append('--ignore-buildable')
if self.include_deps:
args.append('--include-deps')
if dry_run:
args.append('--dry-run')
args.append('--')
for service in self.services:
args.append(service)
return args

def run(self):
Expand All @@ -144,6 +176,9 @@ def run(self):
def main():
argument_spec = dict(
policy=dict(type='str', choices=['always', 'missing'], default='always'),
ignore_buildable=dict(type='bool', default=False),
include_deps=dict(type='bool', default=False),
services=dict(type='list', elements='str'),
)
argspec_ex = common_compose_argspec_ex()
argument_spec.update(argspec_ex.pop('argspec'))
Expand Down

0 comments on commit e4819f9

Please sign in to comment.