Skip to content

Commit

Permalink
Add wait and wait_timeout options. (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Feb 14, 2024
1 parent b5de1fd commit e494464
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/796-docker_compose_v2-wait.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "docker_compose_v2 - allow to wait until containers are running/health when running ``docker compose up`` with the new ``wait`` option (https://github.com/ansible-collections/community.docker/issues/794, https://github.com/ansible-collections/community.docker/pull/796)."
20 changes: 20 additions & 0 deletions plugins/modules/docker_compose_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@
and the value is an integer count for the number of containers.
type: dict
version_added: 3.7.0
wait:
description:
- When running C(docker compose up), pass C(--wait) to wait for services to be running/healthy.
- A timeout can be set with the O(wait_timeout) option.
type: bool
default: false
version_added: 3.8.0
wait_timeout:
description:
- When O(wait=true), wait at most this amount of seconds.
type: int
version_added: 3.8.0
author:
- Felix Fontein (@felixfontein)
Expand Down Expand Up @@ -416,6 +428,8 @@ def __init__(self, client):
self.timeout = parameters['timeout']
self.services = parameters['services'] or []
self.scale = parameters['scale'] or {}
self.wait = parameters['wait']
self.wait_timeout = parameters['wait_timeout']

for key, value in self.scale.items():
if not isinstance(key, string_types):
Expand Down Expand Up @@ -463,6 +477,10 @@ def get_up_cmd(self, dry_run, no_start=False):
args.append('--no-build')
for key, value in sorted(self.scale.items()):
args.extend(['--scale', '%s=%d' % (key, value)])
if self.wait:
args.append('--wait')
if self.wait_timeout is not None:
args.extend(['--wait-timeout', str(self.wait_timeout)])
if no_start:
args.append('--no-start')
if dry_run:
Expand Down Expand Up @@ -597,6 +615,8 @@ def main():
timeout=dict(type='int'),
services=dict(type='list', elements='str'),
scale=dict(type='dict'),
wait=dict(type='bool', default=False),
wait_timeout=dict(type='int'),
)
argument_spec.update(common_compose_argspec())

Expand Down

0 comments on commit e494464

Please sign in to comment.