mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-03-15 19:58:28 +00:00
Parse build events from stderr. (#779)
This commit is contained in:
parent
b5391c7971
commit
b5d085bb88
2
changelogs/fragments/779-compose-v2-build.yml
Normal file
2
changelogs/fragments/779-compose-v2-build.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "docker_compose_v2 - properly parse dry-run build events from ``stderr`` (https://github.com/ansible-collections/community.docker/issues/778, https://github.com/ansible-collections/community.docker/pull/779)."
|
||||||
@ -47,6 +47,8 @@ DOCKER_STATUS_WORKING = frozenset((
|
|||||||
'Recreate',
|
'Recreate',
|
||||||
# Extras for pull events
|
# Extras for pull events
|
||||||
'Pulling',
|
'Pulling',
|
||||||
|
# Extras for build start events
|
||||||
|
'Building',
|
||||||
))
|
))
|
||||||
DOCKER_STATUS_PULL = frozenset((
|
DOCKER_STATUS_PULL = frozenset((
|
||||||
'Pulled',
|
'Pulled',
|
||||||
@ -166,6 +168,24 @@ _RE_SKIPPED_EVENT = re.compile(
|
|||||||
r'$'
|
r'$'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_RE_BUILD_START_EVENT = re.compile(
|
||||||
|
r'^'
|
||||||
|
r'\s*'
|
||||||
|
r'build service'
|
||||||
|
r'\s+'
|
||||||
|
r'(?P<resource_id>\S+)'
|
||||||
|
r'$'
|
||||||
|
)
|
||||||
|
|
||||||
|
_RE_BUILD_PROGRESS_EVENT = re.compile(
|
||||||
|
r'^'
|
||||||
|
r'\s*'
|
||||||
|
r'==>'
|
||||||
|
r'\s+'
|
||||||
|
r'(?P<msg>.*)'
|
||||||
|
r'$'
|
||||||
|
)
|
||||||
|
|
||||||
# The following needs to be kept in sync with the MINIMUM_VERSION compose_v2 docs fragment
|
# The following needs to be kept in sync with the MINIMUM_VERSION compose_v2 docs fragment
|
||||||
MINIMUM_COMPOSE_VERSION = '2.18.0'
|
MINIMUM_COMPOSE_VERSION = '2.18.0'
|
||||||
|
|
||||||
@ -215,6 +235,14 @@ def _extract_event(line):
|
|||||||
'Skipped',
|
'Skipped',
|
||||||
match.group('msg'),
|
match.group('msg'),
|
||||||
)
|
)
|
||||||
|
match = _RE_BUILD_START_EVENT.match(line)
|
||||||
|
if match:
|
||||||
|
return Event(
|
||||||
|
ResourceType.SERVICE,
|
||||||
|
match.group('resource_id'),
|
||||||
|
'Building',
|
||||||
|
None,
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -281,6 +309,10 @@ def parse_events(stderr, dry_run=False, warn_function=None):
|
|||||||
error_event = None
|
error_event = None
|
||||||
_warn_missing_dry_run_prefix(line, warn_missing_dry_run_prefix, warn_function)
|
_warn_missing_dry_run_prefix(line, warn_missing_dry_run_prefix, warn_function)
|
||||||
continue
|
continue
|
||||||
|
match = _RE_BUILD_PROGRESS_EVENT.match(line)
|
||||||
|
if match:
|
||||||
|
# Ignore this
|
||||||
|
continue
|
||||||
match = _RE_CONTINUE_EVENT.match(line)
|
match = _RE_CONTINUE_EVENT.match(line)
|
||||||
if match:
|
if match:
|
||||||
# Continuing an existing event
|
# Continuing an existing event
|
||||||
|
|||||||
@ -379,6 +379,7 @@ actions:
|
|||||||
- Removing
|
- Removing
|
||||||
- Recreating
|
- Recreating
|
||||||
- Pulling
|
- Pulling
|
||||||
|
- Building
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|||||||
@ -8,16 +8,82 @@ __metaclass__ = type
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.docker.plugins.module_utils.compose_v2 import (
|
from ansible_collections.community.docker.plugins.module_utils.compose_v2 import (
|
||||||
|
Event,
|
||||||
parse_events,
|
parse_events,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .compose_v2_test_cases import EVENT_TEST_CASES
|
from .compose_v2_test_cases import EVENT_TEST_CASES
|
||||||
|
|
||||||
|
|
||||||
|
EXTRA_TEST_CASES = [
|
||||||
|
(
|
||||||
|
'2.24.2-manual-build-dry-run',
|
||||||
|
'2.24.2',
|
||||||
|
True,
|
||||||
|
' DRY-RUN MODE - build service foobar \n'
|
||||||
|
' DRY-RUN MODE - ==> ==> writing image dryRun-8843d7f92416211de9ebb963ff4ce28125932878 \n'
|
||||||
|
' DRY-RUN MODE - ==> ==> naming to my-python \n'
|
||||||
|
' DRY-RUN MODE - Network compose_default Creating\n'
|
||||||
|
' DRY-RUN MODE - Network compose_default Created\n'
|
||||||
|
' DRY-RUN MODE - Container compose-foobar-1 Creating\n'
|
||||||
|
' DRY-RUN MODE - Container compose-foobar-1 Created\n'
|
||||||
|
' DRY-RUN MODE - Container ompose-foobar-1 Starting\n'
|
||||||
|
' DRY-RUN MODE - Container ompose-foobar-1 Started\n',
|
||||||
|
[
|
||||||
|
Event(
|
||||||
|
'service',
|
||||||
|
'foobar',
|
||||||
|
'Building',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
'network',
|
||||||
|
'compose_default',
|
||||||
|
'Creating',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
'network',
|
||||||
|
'compose_default',
|
||||||
|
'Created',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
'container',
|
||||||
|
'compose-foobar-1',
|
||||||
|
'Creating',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
'container',
|
||||||
|
'compose-foobar-1',
|
||||||
|
'Created',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
'container',
|
||||||
|
'ompose-foobar-1',
|
||||||
|
'Starting',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
'container',
|
||||||
|
'ompose-foobar-1',
|
||||||
|
'Started',
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
_ALL_TEST_CASES = EVENT_TEST_CASES + EXTRA_TEST_CASES
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'test_id, compose_version, dry_run, stderr, events, warnings',
|
'test_id, compose_version, dry_run, stderr, events, warnings',
|
||||||
EVENT_TEST_CASES,
|
_ALL_TEST_CASES,
|
||||||
ids=[tc[0] for tc in EVENT_TEST_CASES],
|
ids=[tc[0] for tc in _ALL_TEST_CASES],
|
||||||
)
|
)
|
||||||
def test_parse_events(test_id, compose_version, dry_run, stderr, events, warnings):
|
def test_parse_events(test_id, compose_version, dry_run, stderr, events, warnings):
|
||||||
collected_warnings = []
|
collected_warnings = []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user