mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
5
tests/integration/targets/docker_image/aliases
Normal file
5
tests/integration/targets/docker_image/aliases
Normal file
|
@ -0,0 +1,5 @@
|
|||
shippable/posix/group5
|
||||
skip/aix
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
destructive
|
3
tests/integration/targets/docker_image/files/Dockerfile
Normal file
3
tests/integration/targets/docker_image/files/Dockerfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
FROM busybox
|
||||
ENV foo /bar
|
||||
WORKDIR ${foo}
|
|
@ -0,0 +1,3 @@
|
|||
FROM busybox
|
||||
# This should fail building if docker cannot resolve some-custom-host
|
||||
RUN ping -c1 some-custom-host
|
|
@ -0,0 +1,5 @@
|
|||
FROM alpine:3.7
|
||||
ENV INSTALL_PATH /newdata
|
||||
RUN mkdir -p $INSTALL_PATH
|
||||
|
||||
WORKDIR $INSTALL_PATH
|
|
@ -0,0 +1,7 @@
|
|||
FROM busybox AS first
|
||||
ENV dir /first
|
||||
WORKDIR ${dir}
|
||||
|
||||
FROM busybox AS second
|
||||
ENV dir /second
|
||||
WORKDIR ${dir}
|
3
tests/integration/targets/docker_image/meta/main.yml
Normal file
3
tests/integration/targets/docker_image/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
dependencies:
|
||||
- setup_docker_registry
|
3
tests/integration/targets/docker_image/tasks/main.yml
Normal file
3
tests/integration/targets/docker_image/tasks/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
|
||||
include_tasks:
|
||||
file: test.yml
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- name: "Loading tasks from {{ item }}"
|
||||
include_tasks: "{{ item }}"
|
34
tests/integration/targets/docker_image/tasks/test.yml
Normal file
34
tests/integration/targets/docker_image/tasks/test.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
- name: Create random name prefix
|
||||
set_fact:
|
||||
name_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
|
||||
- name: Create image and container list
|
||||
set_fact:
|
||||
inames: []
|
||||
cnames: []
|
||||
|
||||
- debug:
|
||||
msg: "Using name prefix {{ name_prefix }}"
|
||||
|
||||
- block:
|
||||
- include_tasks: run-test.yml
|
||||
with_fileglob:
|
||||
- "tests/*.yml"
|
||||
|
||||
always:
|
||||
- name: "Make sure all images are removed"
|
||||
docker_image:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
with_items: "{{ inames }}"
|
||||
- name: "Make sure all containers are removed"
|
||||
docker_container:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
force_kill: yes
|
||||
with_items: "{{ cnames }}"
|
||||
|
||||
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
|
||||
|
||||
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
|
||||
when: not(docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
78
tests/integration/targets/docker_image/tasks/tests/basic.yml
Normal file
78
tests/integration/targets/docker_image/tasks/tests/basic.yml
Normal file
|
@ -0,0 +1,78 @@
|
|||
---
|
||||
####################################################################
|
||||
## basic ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure image is not there
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
register: absent_1
|
||||
|
||||
- name: Make sure image is not there (idempotency)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
state: absent
|
||||
register: absent_2
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- absent_2 is not changed
|
||||
|
||||
- name: Make sure image is there
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
state: present
|
||||
source: pull
|
||||
register: present_1
|
||||
|
||||
- name: Make sure image is there (idempotent)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
state: present
|
||||
source: pull
|
||||
register: present_2
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- present_1 is changed
|
||||
- present_2 is not changed
|
||||
|
||||
- name: Make sure tag is not there
|
||||
docker_image:
|
||||
name: "hello-world:alias"
|
||||
state: absent
|
||||
|
||||
- name: Tag image with alias
|
||||
docker_image:
|
||||
source: local
|
||||
name: "hello-world:latest"
|
||||
repository: "hello-world:alias"
|
||||
register: tag_1
|
||||
|
||||
- name: Tag image with alias (idempotent)
|
||||
docker_image:
|
||||
source: local
|
||||
name: "hello-world:latest"
|
||||
repository: "hello-world:alias"
|
||||
register: tag_2
|
||||
|
||||
- name: Tag image with alias (force, still idempotent)
|
||||
docker_image:
|
||||
source: local
|
||||
name: "hello-world:latest"
|
||||
repository: "hello-world:alias"
|
||||
force_tag: yes
|
||||
register: tag_3
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- tag_1 is changed
|
||||
- tag_2 is not changed
|
||||
- tag_3 is not changed
|
||||
|
||||
- name: Cleanup alias tag
|
||||
docker_image:
|
||||
name: "hello-world:alias"
|
||||
state: absent
|
|
@ -0,0 +1,152 @@
|
|||
---
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
iname: "{{ name_prefix ~ '-options' }}"
|
||||
|
||||
- name: Determining pushed image names
|
||||
set_fact:
|
||||
hello_world_image_base: "{{ registry_address }}/test/hello-world"
|
||||
test_image_base: "{{ registry_address }}/test/{{ iname }}"
|
||||
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
inames: "{{ inames + [iname, test_image_base ~ ':latest', hello_world_image_base ~ ':latest'] }}"
|
||||
|
||||
####################################################################
|
||||
## interact with test registry #####################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure image is not there
|
||||
docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- name: Make sure we have hello-world:latest
|
||||
docker_image:
|
||||
name: hello-world:latest
|
||||
source: pull
|
||||
|
||||
- name: Push image to test registry
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
push: yes
|
||||
source: local
|
||||
register: push_1
|
||||
|
||||
- name: Push image to test registry (idempotent)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
push: yes
|
||||
source: local
|
||||
register: push_2
|
||||
|
||||
- name: Push image to test registry (force, still idempotent)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
repository: "{{ hello_world_image_base }}"
|
||||
push: yes
|
||||
source: local
|
||||
force_tag: yes
|
||||
register: push_3
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- push_1 is changed
|
||||
- push_2 is not changed
|
||||
- push_3 is not changed
|
||||
|
||||
- name: Get facts of local image
|
||||
docker_image_info:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
register: facts_1
|
||||
|
||||
- name: Make sure image is not there
|
||||
docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- name: Get facts of local image (absent)
|
||||
docker_image_info:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
register: facts_2
|
||||
|
||||
- name: Pull image from test registry
|
||||
docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: present
|
||||
source: pull
|
||||
register: pull_1
|
||||
|
||||
- name: Pull image from test registry (idempotency)
|
||||
docker_image:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
state: present
|
||||
source: pull
|
||||
register: pull_2
|
||||
|
||||
- name: Get facts of local image (present)
|
||||
docker_image_info:
|
||||
name: "{{ hello_world_image_base }}:latest"
|
||||
register: facts_3
|
||||
|
||||
- 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
|
||||
|
||||
####################################################################
|
||||
## repository ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure image is not there
|
||||
docker_image:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- name: repository
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
pull: no
|
||||
repository: "{{ test_image_base }}"
|
||||
source: build
|
||||
register: repository_1
|
||||
|
||||
- name: repository (idempotent)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
pull: no
|
||||
repository: "{{ test_image_base }}"
|
||||
source: build
|
||||
register: repository_2
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- repository_1 is changed
|
||||
- repository_2 is not changed
|
||||
|
||||
- name: Get facts of image
|
||||
docker_image_info:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
register: facts_1
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ test_image_base }}:latest"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- facts_1.images | length == 1
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
iname: "{{ name_prefix ~ '-old-options' }}"
|
||||
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
inames: "{{ inames + [iname]}}"
|
||||
|
||||
####################################################################
|
||||
## build ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: build with old-style options
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: Dockerfile
|
||||
http_timeout: 60
|
||||
nocache: yes
|
||||
pull: no
|
||||
rm: no
|
||||
buildargs:
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
container_limits:
|
||||
memory: 5000000
|
||||
memswap: 7000000
|
||||
source: build
|
||||
register: build
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- '"Please specify build.container_limits instead of container_limits. The container_limits option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.dockerfile instead of dockerfile. The dockerfile option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.http_timeout instead of http_timeout. The http_timeout option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.nocache instead of nocache. The nocache option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.path instead of path. The path option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.pull instead of pull. The pull option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.rm instead of rm. The rm option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.args instead of buildargs. The buildargs option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
300
tests/integration/targets/docker_image/tasks/tests/options.yml
Normal file
300
tests/integration/targets/docker_image/tasks/tests/options.yml
Normal file
|
@ -0,0 +1,300 @@
|
|||
---
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
iname: "{{ name_prefix ~ '-options' }}"
|
||||
iname_1: "{{ name_prefix ~ '-options-1' }}"
|
||||
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
inames: "{{ inames + [iname, iname_1] }}"
|
||||
|
||||
####################################################################
|
||||
## build.args ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- name: buildargs
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
args:
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
pull: no
|
||||
source: build
|
||||
register: buildargs_1
|
||||
|
||||
- name: buildargs (idempotency)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
args:
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
pull: no
|
||||
source: build
|
||||
register: buildargs_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- buildargs_1 is changed
|
||||
- buildargs_2 is not changed
|
||||
when: docker_py_version is version('1.6.0', '>=')
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- buildargs_1 is failed
|
||||
- buildargs_2 is failed
|
||||
when: docker_py_version is version('1.6.0', '<')
|
||||
|
||||
####################################################################
|
||||
## container_limits ################################################
|
||||
####################################################################
|
||||
|
||||
- name: container_limits (Failed due to min memory limit)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
container_limits:
|
||||
memory: 4000
|
||||
pull: no
|
||||
source: build
|
||||
ignore_errors: yes
|
||||
register: container_limits_1
|
||||
|
||||
- name: container_limits
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
container_limits:
|
||||
memory: 5000000
|
||||
memswap: 7000000
|
||||
pull: no
|
||||
source: build
|
||||
register: container_limits_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- 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 4MB', 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 4MB') 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)"
|
||||
|
||||
####################################################################
|
||||
## dockerfile ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: dockerfile
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: no
|
||||
source: build
|
||||
register: dockerfile_1
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- dockerfile_1 is changed
|
||||
- dockerfile_1['image']['Config']['WorkingDir'] == '/newdata'
|
||||
|
||||
####################################################################
|
||||
## force ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build an image
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
pull: no
|
||||
source: build
|
||||
|
||||
- name: force (changed)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: no
|
||||
source: build
|
||||
force_source: yes
|
||||
register: force_1
|
||||
|
||||
- name: force (unchanged)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: "MyDockerfile"
|
||||
pull: no
|
||||
source: build
|
||||
force_source: yes
|
||||
register: force_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- force_1 is changed
|
||||
- force_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## load path #######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Archive image
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
archive_path: "{{ output_dir }}/image.tar"
|
||||
source: pull
|
||||
register: archive_image
|
||||
|
||||
- name: remove image
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- name: load image (changed)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
load_path: "{{ output_dir }}/image.tar"
|
||||
source: load
|
||||
register: load_image
|
||||
|
||||
- name: load image (idempotency)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
load_path: "{{ output_dir }}/image.tar"
|
||||
source: load
|
||||
register: load_image_1
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- load_image is changed
|
||||
- load_image_1 is not changed
|
||||
- archive_image['image']['Id'] == load_image['image']['Id']
|
||||
|
||||
####################################################################
|
||||
## path ############################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
pull: no
|
||||
source: build
|
||||
register: path_1
|
||||
|
||||
- name: Build image (idempotency)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
pull: no
|
||||
source: build
|
||||
register: path_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- path_1 is changed
|
||||
- path_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## target ##########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build multi-stage image
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: "StagedDockerfile"
|
||||
target: first
|
||||
pull: no
|
||||
source: build
|
||||
register: dockerfile_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- dockerfile_2 is changed
|
||||
- dockerfile_2.image.Config.WorkingDir == '/first'
|
||||
|
||||
####################################################################
|
||||
## build.etc_hosts #################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image with custom etc_hosts
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
build:
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: "EtcHostsDockerfile"
|
||||
pull: no
|
||||
etc_hosts:
|
||||
some-custom-host: "127.0.0.1"
|
||||
source: build
|
||||
register: path_1
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- path_1 is changed
|
Loading…
Add table
Add a link
Reference in a new issue