Vendor Galaxy Roles and Collections
This commit is contained in:
parent
c1e1897cda
commit
2aed20393f
3553 changed files with 387444 additions and 2 deletions
|
|
@ -0,0 +1,6 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
azp/4
|
||||
destructive
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
dependencies:
|
||||
- setup_docker_registry
|
||||
- setup_docker_python_deps
|
||||
- setup_remote_tmp_dir
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
|
||||
ansible.builtin.include_tasks:
|
||||
file: test.yml
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
- name: "Loading tasks from {{ test_name }}"
|
||||
ansible.builtin.include_tasks: "{{ test_name }}"
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
- name: Create random name prefix
|
||||
ansible.builtin.set_fact:
|
||||
name_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
|
||||
- name: Create image and container list
|
||||
ansible.builtin.set_fact:
|
||||
inames: []
|
||||
cnames: []
|
||||
|
||||
- ansible.builtin.debug:
|
||||
msg: "Using name prefix {{ name_prefix }}"
|
||||
|
||||
- name: Create files directory
|
||||
ansible.builtin.file:
|
||||
path: '{{ remote_tmp_dir }}/files'
|
||||
state: directory
|
||||
|
||||
- name: Template files
|
||||
ansible.builtin.template:
|
||||
src: '{{ item }}'
|
||||
dest: '{{ remote_tmp_dir }}/files/{{ item }}'
|
||||
loop:
|
||||
- ArgsDockerfile
|
||||
- Dockerfile
|
||||
- EtcHostsDockerfile
|
||||
- MyDockerfile
|
||||
- StagedDockerfile
|
||||
|
||||
- block:
|
||||
- ansible.builtin.include_tasks: run-test.yml
|
||||
with_fileglob:
|
||||
- "tests/*.yml"
|
||||
loop_control:
|
||||
loop_var: test_name
|
||||
|
||||
always:
|
||||
- name: "Make sure all images are removed"
|
||||
community.docker.docker_image:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
with_items: "{{ inames }}"
|
||||
- name: "Make sure all containers are removed"
|
||||
community.docker.docker_container:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
force_kill: true
|
||||
with_items: "{{ cnames }}"
|
||||
|
||||
when: docker_api_version is version('1.25', '>=')
|
||||
|
||||
- ansible.builtin.fail: msg="Too old docker / docker-py version to run docker_image tests!"
|
||||
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
####################################################################
|
||||
## basic ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure image is not there
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
register: absent_1
|
||||
|
||||
- name: Make sure image is not there (idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
state: absent
|
||||
register: absent_2
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- absent_2 is not changed
|
||||
|
||||
- name: Make sure image is there
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
state: present
|
||||
source: pull
|
||||
pull:
|
||||
platform: amd64
|
||||
register: present_1
|
||||
|
||||
- name: Make sure image is there (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
state: present
|
||||
source: pull
|
||||
pull:
|
||||
platform: amd64
|
||||
register: present_2
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- present_1 is changed
|
||||
- present_2 is not changed
|
||||
|
||||
- name: Make sure tag is not there
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world_base }}:alias"
|
||||
state: absent
|
||||
|
||||
- name: Tag image with alias
|
||||
community.docker.docker_image:
|
||||
source: local
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ docker_test_image_hello_world_base }}:alias"
|
||||
register: tag_1
|
||||
|
||||
- name: Tag image with alias (idempotent)
|
||||
community.docker.docker_image:
|
||||
source: local
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ docker_test_image_hello_world_base }}:alias"
|
||||
register: tag_2
|
||||
|
||||
- name: Tag image with alias (force, still idempotent)
|
||||
community.docker.docker_image:
|
||||
source: local
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ docker_test_image_hello_world_base }}:alias"
|
||||
force_tag: true
|
||||
register: tag_3
|
||||
|
||||
- name: Tag image with ID instead of name
|
||||
community.docker.docker_image:
|
||||
source: local
|
||||
name: "{{ present_1.image.Id }}"
|
||||
repository: "{{ docker_test_image_hello_world_base }}:alias"
|
||||
register: tag_4
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- tag_1 is changed
|
||||
- tag_2 is not changed
|
||||
- tag_3 is not changed
|
||||
- tag_4 is not changed
|
||||
|
||||
- name: Cleanup alias tag
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world_base }}:alias"
|
||||
state: absent
|
||||
|
||||
- name: Tag image with ID instead of name (use ID for repository, must fail)
|
||||
community.docker.docker_image:
|
||||
source: local
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ present_1.image.Id }}"
|
||||
register: fail_1
|
||||
ignore_errors: true
|
||||
|
||||
- name: Push image with ID (must fail)
|
||||
community.docker.docker_image:
|
||||
source: local
|
||||
name: "{{ present_1.image.Id }}"
|
||||
push: true
|
||||
register: fail_2
|
||||
ignore_errors: true
|
||||
|
||||
- name: Pull image ID (must fail)
|
||||
community.docker.docker_image:
|
||||
source: pull
|
||||
name: "{{ present_1.image.Id }}"
|
||||
force_source: true
|
||||
register: fail_3
|
||||
ignore_errors: true
|
||||
|
||||
- name: Build image ID (must fail)
|
||||
community.docker.docker_image:
|
||||
source: build
|
||||
name: "{{ present_1.image.Id }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
force_source: true
|
||||
register: fail_4
|
||||
ignore_errors: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- fail_1 is failed
|
||||
- "'`repository` must not be an image ID' in fail_1.msg"
|
||||
- fail_2 is failed
|
||||
- "'Cannot push an image by ID' in fail_2.msg"
|
||||
- fail_3 is failed
|
||||
- "'Image name must not be an image ID for source=pull' in fail_3.msg"
|
||||
- fail_4 is failed
|
||||
- "'Image name must not be an image ID for source=build' in fail_4.msg"
|
||||
|
|
@ -0,0 +1,262 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
- name: Registering image name
|
||||
ansible.builtin.set_fact:
|
||||
iname: "{{ name_prefix ~ '-options' }}"
|
||||
|
||||
- name: Determining pushed image names
|
||||
ansible.builtin.set_fact:
|
||||
hello_world_image_base: "{{ registry_address | default('localhost') }}/test/hello-world"
|
||||
test_image_base: "{{ registry_address | default('localhost') }}/test/{{ iname }}"
|
||||
|
||||
- name: Registering image name
|
||||
ansible.builtin.set_fact:
|
||||
inames: "{{ inames + [iname, test_image_base ~ ':latest', test_image_base ~ ':other', hello_world_image_base ~ ':latest', hello_world_image_base ~ ':newtag', hello_world_image_base ~ ':newtag2'] }}"
|
||||
|
||||
####################################################################
|
||||
## interact with test registry #####################################
|
||||
####################################################################
|
||||
|
||||
- name: Run registry tests only when registry is present
|
||||
when: registry_address is defined
|
||||
block:
|
||||
- name: Make sure image is not there
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: Make sure we have {{ docker_test_image_hello_world }}
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
source: pull
|
||||
|
||||
- name: Push image to test registry
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ hello_world_image_base }}:latest"
|
||||
push: true
|
||||
source: local
|
||||
register: push_1
|
||||
|
||||
- name: Push image to test registry (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ hello_world_image_base }}:latest"
|
||||
push: true
|
||||
source: local
|
||||
register: push_2
|
||||
|
||||
- name: Push image to test registry (force, still idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ hello_world_image_base }}:latest"
|
||||
push: true
|
||||
source: local
|
||||
force_tag: true
|
||||
register: push_3
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- push_1 is changed
|
||||
- push_2 is not changed
|
||||
- push_3 is not changed
|
||||
|
||||
- name: Get facts of local image
|
||||
community.docker.docker_image_info:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
register: facts_1
|
||||
|
||||
- name: Make sure image is not there
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: Get facts of local image (absent)
|
||||
community.docker.docker_image_info:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
register: facts_2
|
||||
|
||||
- name: Pull image from test registry
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: present
|
||||
source: pull
|
||||
register: pull_1
|
||||
|
||||
- name: Pull image from test registry (idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: present
|
||||
source: pull
|
||||
register: pull_2
|
||||
|
||||
- name: Get facts of local image (present)
|
||||
community.docker.docker_image_info:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
register: facts_3
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- pull_1 is changed
|
||||
- pull_2 is not changed
|
||||
- facts_1.images | length == 1
|
||||
- facts_2.images | length == 0
|
||||
- facts_3.images | length == 1
|
||||
|
||||
- name: Pull image from test registry (with digest)
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}@{{ facts_3.images[0].RepoDigests[0] | regex_replace('.*@', '') }}"
|
||||
state: present
|
||||
source: pull
|
||||
force_source: true
|
||||
register: pull_digest
|
||||
|
||||
- name: Make sure that changed is still false
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- pull_digest is not changed
|
||||
|
||||
- name: Tag different image with new tag
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_alpine_different }}"
|
||||
repository: "{{ hello_world_image_base }}:newtag"
|
||||
push: false
|
||||
source: pull
|
||||
|
||||
- name: Push different image with new tag
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
tag: newtag
|
||||
push: true
|
||||
source: local
|
||||
register: push_1_different
|
||||
|
||||
- name: Push different image with new tag (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
tag: newtag
|
||||
push: true
|
||||
source: local
|
||||
register: push_2_different
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- push_1_different is changed
|
||||
- push_2_different is not changed
|
||||
|
||||
- name: Tag same image with new tag
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_alpine_different }}"
|
||||
repository: "{{ hello_world_image_base }}:newtag2"
|
||||
push: false
|
||||
source: pull
|
||||
|
||||
- name: Push same image with new tag
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
tag: newtag2
|
||||
push: true
|
||||
source: local
|
||||
register: push_1_same
|
||||
|
||||
- name: Push same image with new tag (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_image_base }}"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
tag: newtag2
|
||||
push: true
|
||||
source: local
|
||||
register: push_2_same
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
# NOTE: This should be:
|
||||
# - push_1_same is changed
|
||||
# Unfortunately docker does *NOT* report whether the tag already existed or not.
|
||||
# Here are the logs returned by client.push() for both tasks (which are exactly the same):
|
||||
# push_1_same:
|
||||
# {"status": "The push refers to repository [localhost:32796/test/hello-world]"},
|
||||
# {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Preparing"},
|
||||
# {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Layer already exists"},
|
||||
# {"status": "newtag2: digest: sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b size: 528"},
|
||||
# {"aux": {"Digest": "sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b", "Size": 528, "Tag": "newtag2"}, "progressDetail": {}}
|
||||
# push_2_same:
|
||||
# {"status": "The push refers to repository [localhost:32796/test/hello-world]"},
|
||||
# {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Preparing"},
|
||||
# {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Layer already exists"},
|
||||
# {"status": "newtag2: digest: sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b size: 528"},
|
||||
# {"aux": {"Digest": "sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b", "Size": 528, "Tag": "newtag2"}, "progressDetail": {}}
|
||||
- push_1_same is not changed
|
||||
- push_2_same is not changed
|
||||
|
||||
####################################################################
|
||||
## repository ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure image is not there
|
||||
community.docker.docker_image:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: repository
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
pull: false
|
||||
repository: "{{ test_image_base }}"
|
||||
source: build
|
||||
register: repository_1
|
||||
|
||||
- name: repository (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
repository: "{{ test_image_base }}"
|
||||
source: local
|
||||
register: repository_2
|
||||
|
||||
- name: repository, tag with ID
|
||||
community.docker.docker_image:
|
||||
name: "{{ repository_1.image.Id }}"
|
||||
repository: "{{ test_image_base }}:other"
|
||||
source: local
|
||||
register: repository_3
|
||||
|
||||
- name: repository, tag with ID (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ repository_1.image.Id }}"
|
||||
repository: "{{ test_image_base }}:other"
|
||||
source: local
|
||||
force_tag: true
|
||||
register: repository_4
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- repository_1 is changed
|
||||
- repository_2 is not changed
|
||||
- repository_3 is changed
|
||||
- repository_4 is not changed
|
||||
|
||||
- name: Get facts of image
|
||||
community.docker.docker_image_info:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
register: facts_1
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- facts_1.images | length == 1
|
||||
|
|
@ -0,0 +1,508 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
- name: Registering image name
|
||||
ansible.builtin.set_fact:
|
||||
iname: "{{ name_prefix ~ '-options' }}"
|
||||
iname_1: "{{ name_prefix ~ '-options-1' }}"
|
||||
hello_world_alt: "{{ name_prefix }}-hello-world-alt:v1.2.3-foo"
|
||||
|
||||
- name: Registering image name
|
||||
ansible.builtin.set_fact:
|
||||
inames: "{{ inames + [iname, iname_1, hello_world_alt] }}"
|
||||
|
||||
####################################################################
|
||||
## build.args ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: buildargs
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "ArgsDockerfile"
|
||||
args:
|
||||
IMAGE: "{{ docker_test_image_busybox }}"
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
pull: false
|
||||
source: build
|
||||
register: buildargs_1
|
||||
ignore_errors: true
|
||||
|
||||
- name: buildargs (idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "ArgsDockerfile"
|
||||
args:
|
||||
IMAGE: "{{ docker_test_image_busybox }}"
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
pull: false
|
||||
source: build
|
||||
register: buildargs_2
|
||||
ignore_errors: true
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- buildargs_1 is changed
|
||||
- buildargs_2 is not failed and buildargs_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## build.container_limits ##########################################
|
||||
####################################################################
|
||||
|
||||
- name: container_limits (Failed due to min memory limit)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
container_limits:
|
||||
memory: 4KB
|
||||
pull: false
|
||||
source: build
|
||||
ignore_errors: true
|
||||
register: container_limits_1
|
||||
|
||||
- name: container_limits
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
container_limits:
|
||||
memory: 7MB
|
||||
memswap: 8MB
|
||||
pull: false
|
||||
source: build
|
||||
register: container_limits_2
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
# It *sometimes* happens that the first task does not fail.
|
||||
# For now, we work around this by
|
||||
# a) requiring that if it fails, the message must
|
||||
# contain 'Minimum memory limit allowed is (4|6)MB', and
|
||||
# b) requiring that either the first task, or the second
|
||||
# task is changed, but not both.
|
||||
- "not container_limits_1 is failed or ('Minimum memory limit allowed is ') in container_limits_1.msg"
|
||||
- "container_limits_1 is changed or container_limits_2 is changed and not (container_limits_1 is changed and container_limits_2 is changed)"
|
||||
|
||||
####################################################################
|
||||
## build.dockerfile ################################################
|
||||
####################################################################
|
||||
|
||||
- name: dockerfile
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: false
|
||||
source: build
|
||||
register: dockerfile_1
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- dockerfile_1 is changed
|
||||
- "('FROM ' ~ docker_test_image_alpine) in dockerfile_1.stdout"
|
||||
- dockerfile_1['image']['Config']['WorkingDir'] == '/newdata'
|
||||
|
||||
####################################################################
|
||||
## build.platform ##################################################
|
||||
####################################################################
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: build.platform
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
platform: linux
|
||||
pull: false
|
||||
source: build
|
||||
register: platform_1
|
||||
ignore_errors: true
|
||||
|
||||
- name: build.platform (idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
platform: linux
|
||||
pull: false
|
||||
source: build
|
||||
register: platform_2
|
||||
ignore_errors: true
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- platform_1 is changed
|
||||
- platform_2 is not failed and platform_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## force ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build an image
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
pull: false
|
||||
source: build
|
||||
|
||||
- name: force (changed)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: false
|
||||
source: build
|
||||
force_source: true
|
||||
register: force_1
|
||||
|
||||
- name: force (unchanged)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: false
|
||||
source: build
|
||||
force_source: true
|
||||
register: force_2
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- force_1 is changed
|
||||
- force_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## load path #######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Archive image
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
archive_path: "{{ remote_tmp_dir }}/image.tar"
|
||||
source: pull
|
||||
register: archive_image
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- archive_image is changed
|
||||
|
||||
- name: Copy archive because we will mutate it but other tests need the original
|
||||
ansible.builtin.copy:
|
||||
remote_src: true
|
||||
src: "{{ remote_tmp_dir }}/image.tar"
|
||||
dest: "{{ remote_tmp_dir }}/image_mutated.tar"
|
||||
|
||||
- name: Archive image again (idempotent)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
archive_path: "{{ remote_tmp_dir }}/image_mutated.tar"
|
||||
source: local
|
||||
register: archive_image_2
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- archive_image_2 is not changed
|
||||
when: docker_cli_version is version("29.0.0", "<")
|
||||
# Apparently idempotency no longer works with the default storage backend
|
||||
# in Docker 29.0.0.
|
||||
# https://github.com/ansible-collections/community.docker/pull/1199
|
||||
|
||||
- name: Archive image 3rd time, should overwrite due to different id
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_alpine_different }}"
|
||||
archive_path: "{{ remote_tmp_dir }}/image_mutated.tar"
|
||||
source: pull
|
||||
register: archive_image_3
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- archive_image_3 is changed
|
||||
|
||||
- name: Reset archive
|
||||
ansible.builtin.copy:
|
||||
remote_src: true
|
||||
src: "{{ remote_tmp_dir }}/image.tar"
|
||||
dest: "{{ remote_tmp_dir }}/image_mutated.tar"
|
||||
|
||||
- name: Tag image with different name
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
repository: "{{ hello_world_alt }}"
|
||||
source: local
|
||||
|
||||
- name: Archive image 4th time, should overwrite due to different name even when ID is same
|
||||
community.docker.docker_image:
|
||||
name: "{{ hello_world_alt }}"
|
||||
# Tagged as docker_test_image_hello_world but has same hash/id (before this task overwrites it)
|
||||
archive_path: "{{ remote_tmp_dir }}/image_mutated.tar"
|
||||
source: local
|
||||
register: archive_image_4
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- archive_image_4 is changed
|
||||
|
||||
# This is the test that needs the original, non-mutated archive
|
||||
- name: Archive image by ID
|
||||
community.docker.docker_image:
|
||||
name: "{{ archive_image.image.Id }}"
|
||||
archive_path: "{{ remote_tmp_dir }}/image_id.tar"
|
||||
source: local
|
||||
register: archive_image_id
|
||||
|
||||
- name: Create invalid archive
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ remote_tmp_dir }}/image-invalid.tar"
|
||||
content: "this is not a valid image"
|
||||
|
||||
- name: remove image
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: load image (changed)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
load_path: "{{ remote_tmp_dir }}/image.tar"
|
||||
source: load
|
||||
register: load_image
|
||||
|
||||
- name: load image (idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ docker_test_image_hello_world }}"
|
||||
load_path: "{{ remote_tmp_dir }}/image.tar"
|
||||
source: load
|
||||
register: load_image_1
|
||||
|
||||
- name: load image (wrong name)
|
||||
community.docker.docker_image:
|
||||
name: foo:bar
|
||||
load_path: "{{ remote_tmp_dir }}/image.tar"
|
||||
source: load
|
||||
register: load_image_2
|
||||
ignore_errors: true
|
||||
|
||||
- name: load image (invalid image)
|
||||
community.docker.docker_image:
|
||||
name: foo:bar
|
||||
load_path: "{{ remote_tmp_dir }}/image-invalid.tar"
|
||||
source: load
|
||||
register: load_image_3
|
||||
ignore_errors: true
|
||||
|
||||
- name: load image (ID, idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ archive_image.image.Id }}"
|
||||
load_path: "{{ remote_tmp_dir }}/image_id.tar"
|
||||
source: load
|
||||
register: load_image_4
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- load_image is changed
|
||||
- archive_image['image']['Id'] == load_image['image']['Id']
|
||||
- load_image_1 is not changed
|
||||
- load_image_2 is failed
|
||||
- >-
|
||||
("The archive did not contain image 'foo:bar'. Instead, found '" ~ docker_test_image_hello_world ~ "'.") == load_image_2.msg
|
||||
- load_image_3 is failed
|
||||
- '"Detected no loaded images. Archive potentially corrupt?" == load_image_3.msg'
|
||||
- load_image_4 is not changed
|
||||
|
||||
####################################################################
|
||||
## build.path ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
pull: false
|
||||
source: build
|
||||
register: path_1
|
||||
|
||||
- name: Build image (idempotency)
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
pull: false
|
||||
source: build
|
||||
register: path_2
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- path_1 is changed
|
||||
- path_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## build.target ####################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build multi-stage image
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "StagedDockerfile"
|
||||
target: first
|
||||
pull: false
|
||||
source: build
|
||||
register: dockerfile_2
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- dockerfile_2 is changed
|
||||
- dockerfile_2.image.Config.WorkingDir == '/first'
|
||||
|
||||
####################################################################
|
||||
## build.etc_hosts #################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image with custom etc_hosts
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "EtcHostsDockerfile"
|
||||
pull: false
|
||||
etc_hosts:
|
||||
some-custom-host: "127.0.0.1"
|
||||
source: build
|
||||
register: path_1
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- path_1 is changed
|
||||
|
||||
####################################################################
|
||||
## build.shm_size ##################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image with custom shm_size
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: false
|
||||
shm_size: 128MB
|
||||
source: build
|
||||
register: path_1
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- path_1 is changed
|
||||
|
||||
####################################################################
|
||||
## build.labels ####################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image with labels
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ remote_tmp_dir }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: false
|
||||
labels:
|
||||
FOO: BAR
|
||||
this is a label: this is the label's value
|
||||
source: build
|
||||
register: labels_1
|
||||
|
||||
- name: cleanup
|
||||
community.docker.docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: true
|
||||
|
||||
- name: Show image information
|
||||
ansible.builtin.debug:
|
||||
var: labels_1.image
|
||||
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- labels_1 is changed
|
||||
- labels_1.image.Config.Labels.FOO == 'BAR'
|
||||
- labels_1.image.Config.Labels["this is a label"] == "this is the label's value"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright (c) 2022, Felix Fontein
|
||||
# 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
|
||||
|
||||
ARG IMAGE
|
||||
ARG TEST1
|
||||
ARG TEST2
|
||||
ARG TEST3
|
||||
|
||||
FROM ${IMAGE}
|
||||
ENV foo /bar
|
||||
WORKDIR ${foo}
|
||||
RUN echo "${TEST1} - ${TEST2} - ${TEST3}"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# 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 {{ docker_test_image_busybox }}
|
||||
ENV foo /bar
|
||||
WORKDIR ${foo}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# 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 {{ docker_test_image_busybox }}
|
||||
# This should fail building if docker cannot resolve some-custom-host
|
||||
RUN ping -c1 some-custom-host
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# 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 {{ docker_test_image_alpine }}
|
||||
ENV INSTALL_PATH /newdata
|
||||
RUN mkdir -p $INSTALL_PATH
|
||||
|
||||
WORKDIR $INSTALL_PATH
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# 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 {{ docker_test_image_busybox }} AS first
|
||||
ENV dir /first
|
||||
WORKDIR ${dir}
|
||||
|
||||
FROM {{ docker_test_image_busybox }} AS second
|
||||
ENV dir /second
|
||||
WORKDIR ${dir}
|
||||
Loading…
Add table
Add a link
Reference in a new issue