mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
docker_image_build: work around strange behavior of docker buildx build when --output is provided (#1006)
* Work around strange behavior of docker buildx build when --output is provided. * Adjust tests. * Allow to pass multiple image names; correctly quote --output values. * Return executed command. * Adjust tests.
This commit is contained in:
@@ -243,47 +243,58 @@
|
||||
## outputs #########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure the image is not there
|
||||
docker_image_remove:
|
||||
name: "{{ iname }}"
|
||||
- when: buildx_version is version('0.13.0', '>=')
|
||||
block:
|
||||
- name: Make sure the image is not there
|
||||
docker_image_remove:
|
||||
name: "{{ iname }}"
|
||||
|
||||
- name: Make sure the image tarball is not there
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/container.tar"
|
||||
state: absent
|
||||
- name: Make sure the image tarball is not there
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/container.tar"
|
||||
state: absent
|
||||
|
||||
- name: Build image with outputs
|
||||
docker_image_build:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "Dockerfile"
|
||||
pull: false
|
||||
outputs:
|
||||
- type: tar
|
||||
dest: "{{ remote_tmp_dir }}/container.tar"
|
||||
register: outputs_1
|
||||
- name: Build image with outputs
|
||||
docker_image_build:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "Dockerfile"
|
||||
pull: false
|
||||
outputs:
|
||||
- type: tar
|
||||
dest: "{{ remote_tmp_dir }}/container.tar"
|
||||
ignore_errors: true
|
||||
register: outputs_1
|
||||
|
||||
- name: cleanup (should not be changed)
|
||||
docker_image_remove:
|
||||
name: "{{ iname }}"
|
||||
register: outputs_1_cleanup
|
||||
- when: outputs_1 is not failed
|
||||
block:
|
||||
- name: cleanup (should be changed)
|
||||
docker_image_remove:
|
||||
name: "{{ iname }}"
|
||||
register: outputs_1_cleanup
|
||||
|
||||
- name: Gather information on tarball
|
||||
stat:
|
||||
path: "{{ remote_tmp_dir }}/container.tar"
|
||||
register: outputs_1_stat
|
||||
- name: Gather information on tarball
|
||||
stat:
|
||||
path: "{{ remote_tmp_dir }}/container.tar"
|
||||
register: outputs_1_stat
|
||||
|
||||
- name: Show image information
|
||||
debug:
|
||||
var: outputs_1.image
|
||||
- name: Show image information
|
||||
debug:
|
||||
var: outputs_1.image
|
||||
|
||||
- name: Show tarball information
|
||||
debug:
|
||||
var: outputs_1_stat.stat
|
||||
- name: Show tarball information
|
||||
debug:
|
||||
var: outputs_1_stat.stat
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- outputs_1 is changed
|
||||
- outputs_1.image | length == 0
|
||||
- outputs_1_cleanup is not changed
|
||||
- outputs_1_stat.stat.exists
|
||||
- assert:
|
||||
that:
|
||||
- outputs_1 is changed
|
||||
- outputs_1.image | length > 0
|
||||
- outputs_1_cleanup is changed
|
||||
- outputs_1_stat.stat.exists
|
||||
|
||||
- when: outputs_1 is failed
|
||||
assert:
|
||||
that:
|
||||
- >-
|
||||
'ERROR: multiple outputs currently unsupported by the current BuildKit daemon' in outputs_1.stderr
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Copyright 2024 Felix Fontein <felix@fontein.de>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.docker.plugins.modules.docker_image_build import _quote_csv
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input, expected", [
|
||||
('', ''),
|
||||
(' ', '" "'),
|
||||
(',', '","'),
|
||||
('"', '""""'),
|
||||
('\rhello, "hi" !\n', '"\rhello, ""hi"" !\n"'),
|
||||
])
|
||||
def test__quote_csv(input, expected):
|
||||
assert _quote_csv(input) == expected
|
||||
Reference in New Issue
Block a user