--- - 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]" #################################################################### ## buildargs ####################################################### #################################################################### - name: buildargs docker_image: path: "{{ role_path }}/files" name: "{{ iname }}" buildargs: TEST1: val1 TEST2: val2 TEST3: "True" register: buildargs_1 - name: buildargs (idempotency) docker_image: path: "{{ role_path }}/files" name: "{{ iname }}" buildargs: TEST1: val1 TEST2: val2 TEST3: "True" register: buildargs_2 - name: cleanup docker_image: name: "{{ iname }}" state: absent - 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: path: "{{ role_path }}/files" name: "{{ iname }}" container_limits: memory: 4000 ignore_errors: yes register: container_limits_1 - name: container_limits docker_image: path: "{{ role_path }}/files" name: "{{ iname }}" container_limits: memory: 5000000 memswap: 7000000 register: container_limits_2 - name: cleanup docker_image: name: "{{ iname }}" state: absent - 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: path: "{{ role_path }}/files" name: "{{ iname }}" dockerfile: "MyDockerfile" register: dockerfile_1 - name: cleanup docker_image: name: "{{ iname }}" state: absent - 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 - name: repository docker_image: name: "{{ iname }}" path: "{{ role_path }}/files" repository: "{{ registry_address }}/test/{{ iname }}" register: repository_1 - name: repository (idempotent) docker_image: name: "{{ iname }}" path: "{{ role_path }}/files" repository: "{{ registry_address }}/test/{{ iname }}" register: repository_2 - assert: that: - repository_1 is changed - repository_2 is not changed - name: Get facts of image docker_image_facts: name: "{{ registry_address }}/test/{{ iname }}:latest" register: facts_1 - name: cleanup docker_image: name: "{{ registry_address }}/test/{{ iname }}:latest" state: absent force: yes - assert: that: - facts_1.images | length == 1 #################################################################### ## force ########################################################### #################################################################### - name: Build an image docker_image: path: "{{ role_path }}/files" name: "{{ iname }}" - name: force (changed) docker_image: path: "{{ role_path }}/files" name: "{{ iname }}" dockerfile: "MyDockerfile" force: yes register: force_1 - name: force (unchanged) docker_image: path: "{{ role_path }}/files" name: "{{ iname }}" dockerfile: "MyDockerfile" force: yes register: force_2 - name: cleanup docker_image: name: "{{ iname }}" state: absent - 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 register: archive_image - name: remove image docker_image: name: "hello-world:latest" state: absent - name: load image (changed) docker_image: name: "hello-world:latest" load_path: image.tar register: load_image - name: load image (idempotency) docker_image: name: "hello-world:latest" load_path: image.tar 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 }}" path: "{{ role_path }}/files" register: path_1 - name: Build image(idempotency) docker_image: name: "{{ iname }}" path: "{{ role_path }}/files" register: path_2 - name: cleanup docker_image: name: "{{ iname }}" state: absent - assert: that: - path_1 is changed - path_2 is not changed