From 9905a959562477c9a7c0d01a5e131f5b8a729ada Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 1 Aug 2024 15:58:03 +0200 Subject: [PATCH] Fix composition of --output parameters. --- .../fragments/947-docker_image_build.yml | 2 ++ plugins/modules/docker_image_build.py | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/947-docker_image_build.yml diff --git a/changelogs/fragments/947-docker_image_build.yml b/changelogs/fragments/947-docker_image_build.yml new file mode 100644 index 000000000..fe6d98953 --- /dev/null +++ b/changelogs/fragments/947-docker_image_build.yml @@ -0,0 +1,2 @@ +bugfixes: + - "docker_image_build - fix ``--output`` parameter composition for ``type=docker`` and ``type=image`` (https://github.com/ansible-collections/community.docker/issues/946, https://github.com/ansible-collections/community.docker/pull/947)." diff --git a/plugins/modules/docker_image_build.py b/plugins/modules/docker_image_build.py index 8574b5aad..f2dcc9f45 100644 --- a/plugins/modules/docker_image_build.py +++ b/plugins/modules/docker_image_build.py @@ -207,7 +207,8 @@ image: - This exporter writes the build result as an image or a manifest list. When using this driver, the image will appear in C(docker images). - - The image name can be provided in O(outputs[].name). If it is not provided, the + - The image name can be provided in O(outputs[].name). If it is not provided, + O(name) and O(tag) will be used. - Optionally, image can be automatically pushed to a registry by setting O(outputs[].push=true). required: true dest: @@ -433,19 +434,19 @@ def add_args(self, args): if output['type'] == 'oci': args.extend(['--output', 'type=oci,dest={dest}'.format(dest=output['dest'])]) if output['type'] == 'docker': - more = [] + subargs = ['type=docker'] if output['dest'] is not None: - more.append('dest={dest}'.format(dest=output['dest'])) - if output['dest'] is not None: - more.append('context={context}'.format(context=output['context'])) - args.extend(['--output', 'type=docker,{more}'.format(more=','.join(more))]) + subargs.append('dest={dest}'.format(dest=output['dest'])) + if output['context'] is not None: + subargs.append('context={context}'.format(context=output['context'])) + args.extend(['--output', ','.join(subargs)]) if output['type'] == 'image': - more = [] + subargs = ['type=image'] if output['name'] is not None: - more.append('name={name}'.format(name=output['name'])) + subargs.append('name={name}'.format(name=output['name'])) if output['push']: - more.append('push=true') - args.extend(['--output', 'type=image,{more}'.format(more=','.join(more))]) + subargs.append('push=true') + args.extend(['--output', ','.join(subargs)]) return environ_update def build_image(self):