Add wait and wait_timeout options. (#796)

This commit is contained in:
Felix Fontein 2024-02-14 22:48:36 +01:00 committed by GitHub
parent b5de1fd1ad
commit e494464e56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -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)."

View File

@ -124,6 +124,18 @@ options:
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)
@ -416,6 +428,8 @@ class ServicesManager(BaseComposeManager):
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):
@ -463,6 +477,10 @@ class ServicesManager(BaseComposeManager):
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:
@ -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())