2019-01-30 20:11:49 +01:00
|
|
|
---
|
|
|
|
- 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]"
|
|
|
|
|
|
|
|
####################################################################
|
2019-03-14 10:46:38 +01:00
|
|
|
## build.args ######################################################
|
2019-01-30 20:11:49 +01:00
|
|
|
####################################################################
|
|
|
|
|
|
|
|
- name: buildargs
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
args:
|
|
|
|
TEST1: val1
|
|
|
|
TEST2: val2
|
|
|
|
TEST3: "True"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: buildargs_1
|
|
|
|
|
|
|
|
- name: buildargs (idempotency)
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
args:
|
|
|
|
TEST1: val1
|
|
|
|
TEST2: val2
|
|
|
|
TEST3: "True"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: buildargs_2
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- 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 }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
container_limits:
|
|
|
|
memory: 4000
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
ignore_errors: yes
|
|
|
|
register: container_limits_1
|
|
|
|
|
|
|
|
- name: container_limits
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
container_limits:
|
|
|
|
memory: 5000000
|
|
|
|
memswap: 7000000
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: container_limits_2
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
2019-03-07 20:35:47 +01:00
|
|
|
# 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)"
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
####################################################################
|
|
|
|
## dockerfile ######################################################
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
- name: dockerfile
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
dockerfile: "MyDockerfile"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: dockerfile_1
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- dockerfile_1 is changed
|
|
|
|
- dockerfile_1['image']['Config']['WorkingDir'] == '/newdata'
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
## repository ######################################################
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
- name: Make sure image is not there
|
|
|
|
docker_image:
|
|
|
|
name: "{{ registry_address }}/test/{{ iname }}:latest"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- name: repository
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-01-30 20:11:49 +01:00
|
|
|
repository: "{{ registry_address }}/test/{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: repository_1
|
|
|
|
|
|
|
|
- name: repository (idempotent)
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-01-30 20:11:49 +01:00
|
|
|
repository: "{{ registry_address }}/test/{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: repository_2
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- repository_1 is changed
|
|
|
|
- repository_2 is not changed
|
|
|
|
|
|
|
|
- name: Get facts of image
|
2019-03-21 09:37:18 +01:00
|
|
|
docker_image_info:
|
2019-01-30 20:11:49 +01:00
|
|
|
name: "{{ registry_address }}/test/{{ iname }}:latest"
|
|
|
|
register: facts_1
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
docker_image:
|
|
|
|
name: "{{ registry_address }}/test/{{ iname }}:latest"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- facts_1.images | length == 1
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
## force ###########################################################
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
- name: Build an image
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- name: force (changed)
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
dockerfile: "MyDockerfile"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
|
|
|
force_source: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
register: force_1
|
|
|
|
|
|
|
|
- name: force (unchanged)
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
dockerfile: "MyDockerfile"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
|
|
|
force_source: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
register: force_2
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- force_1 is changed
|
|
|
|
- force_2 is not changed
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
## load path #######################################################
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
- name: Archive image
|
|
|
|
docker_image:
|
|
|
|
name: "hello-world:latest"
|
|
|
|
archive_path: image.tar
|
2019-03-14 10:46:38 +01:00
|
|
|
source: pull
|
2019-01-30 20:11:49 +01:00
|
|
|
register: archive_image
|
|
|
|
|
|
|
|
- name: remove image
|
|
|
|
docker_image:
|
|
|
|
name: "hello-world:latest"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- name: load image (changed)
|
|
|
|
docker_image:
|
|
|
|
name: "hello-world:latest"
|
|
|
|
load_path: image.tar
|
2019-03-14 10:46:38 +01:00
|
|
|
source: load
|
2019-01-30 20:11:49 +01:00
|
|
|
register: load_image
|
|
|
|
|
|
|
|
- name: load image (idempotency)
|
|
|
|
docker_image:
|
|
|
|
name: "hello-world:latest"
|
|
|
|
load_path: image.tar
|
2019-03-14 10:46:38 +01:00
|
|
|
source: load
|
2019-01-30 20:11:49 +01:00
|
|
|
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 }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
|
|
|
path: "{{ role_path }}/files"
|
2019-03-18 06:34:07 +01:00
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: path_1
|
|
|
|
|
2019-03-14 10:46:38 +01:00
|
|
|
- name: Build image (idempotency)
|
2019-01-30 20:11:49 +01:00
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
2019-03-14 10:46:38 +01:00
|
|
|
build:
|
2019-03-18 06:34:07 +01:00
|
|
|
path: "{{ role_path }}/files"
|
|
|
|
pull: no
|
2019-03-14 10:46:38 +01:00
|
|
|
source: build
|
2019-01-30 20:11:49 +01:00
|
|
|
register: path_2
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
docker_image:
|
|
|
|
name: "{{ iname }}"
|
|
|
|
state: absent
|
2019-03-14 10:46:38 +01:00
|
|
|
force_absent: yes
|
2019-01-30 20:11:49 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- path_1 is changed
|
|
|
|
- path_2 is not changed
|