|
| 1 | +--- |
| 2 | +# Copyright (c) Ansible Project |
| 3 | +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 | + |
| 6 | +- vars: |
| 7 | + bname: "{{ name_prefix }}-build" |
| 8 | + cname: "{{ name_prefix }}-cont" |
| 9 | + non_existing_image: does-not-exist:latest |
| 10 | + dockerfile_path: test-dockerfile |
| 11 | + base_image: hello-world:latest |
| 12 | + project_src: "{{ remote_tmp_dir }}/{{ bname }}" |
| 13 | + test_service_non_existing: | |
| 14 | + version: '3' |
| 15 | + services: |
| 16 | + {{ cname }}: |
| 17 | + image: {{ non_existing_image }} |
| 18 | + build: |
| 19 | + dockerfile: Dockerfile-does-not-exist |
| 20 | + test_service_simple: | |
| 21 | + version: '3' |
| 22 | + services: |
| 23 | + {{ cname }}: |
| 24 | + image: {{ docker_test_image_simple_1 }} |
| 25 | + build: |
| 26 | + dockerfile: {{ dockerfile_path }} |
| 27 | + command: 10m |
| 28 | + stop_grace_period: 1s |
| 29 | + test_service_simple_dockerfile: | |
| 30 | + FROM {{ base_image }} |
| 31 | +
|
| 32 | + block: |
| 33 | + - name: Registering container name |
| 34 | + set_fact: |
| 35 | + cnames: "{{ cnames + [bname ~ '-' ~ cname ~ '-1'] + [ base_image ]}}" |
| 36 | + dnetworks: "{{ dnetworks + [bname ~ '_default'] }}" |
| 37 | + |
| 38 | + - name: Create project directory |
| 39 | + file: |
| 40 | + path: '{{ project_src }}' |
| 41 | + state: directory |
| 42 | + |
| 43 | + - name: Make sure images are not around |
| 44 | + docker_image_remove: |
| 45 | + name: '{{ item }}' |
| 46 | + loop: |
| 47 | + - '{{ base_image }}' |
| 48 | + - '{{ non_existing_image }}' |
| 49 | + - '{{ docker_test_image_simple_1 }}' |
| 50 | + |
| 51 | +#################################################################### |
| 52 | +## Image with missing dockerfile ################################### |
| 53 | +#################################################################### |
| 54 | + |
| 55 | + - name: Template project file with non-existing image |
| 56 | + copy: |
| 57 | + dest: '{{ project_src }}/docker-compose.yml' |
| 58 | + content: '{{ test_service_non_existing }}' |
| 59 | + |
| 60 | + - name: Build (check) |
| 61 | + docker_compose_v2_build: |
| 62 | + project_src: '{{ project_src }}' |
| 63 | + check_mode: true |
| 64 | + register: build_1_check |
| 65 | + ignore_errors: true |
| 66 | + |
| 67 | + - name: Build |
| 68 | + docker_compose_v2_build: |
| 69 | + project_src: '{{ project_src }}' |
| 70 | + register: build_1 |
| 71 | + ignore_errors: true |
| 72 | + |
| 73 | + - assert: |
| 74 | + that: |
| 75 | + - build_1_check is failed or build_1_check is changed |
| 76 | + - build_1_check is changed or build_1_check.msg.startswith('Error when processing ') |
| 77 | + - build_1_check.warnings | default([]) | select('regex', 'Cannot parse event from ') | length == 0 |
| 78 | + - build_1 is failed |
| 79 | + - build_1.msg.startswith('Error when processing ') |
| 80 | + - build_1.warnings | default([]) | select('regex', 'Cannot parse event from ') | length == 0 |
| 81 | + |
| 82 | +#################################################################### |
| 83 | +## Regular image ################################################### |
| 84 | +#################################################################### |
| 85 | + |
| 86 | + - name: Template project file with simple dockerfile |
| 87 | + copy: |
| 88 | + dest: '{{ project_src }}/docker-compose.yml' |
| 89 | + content: '{{ test_service_simple }}' |
| 90 | + |
| 91 | + - name: Template dockerfile |
| 92 | + copy: |
| 93 | + dest: '{{ project_src }}/{{ dockerfile_path }}' |
| 94 | + content: '{{ test_service_simple_dockerfile }}' |
| 95 | + |
| 96 | + - name: Build (check) |
| 97 | + docker_compose_v2_build: |
| 98 | + project_src: '{{ project_src }}' |
| 99 | + check_mode: true |
| 100 | + register: build_1_check |
| 101 | + |
| 102 | + - name: Build |
| 103 | + docker_compose_v2_build: |
| 104 | + project_src: '{{ project_src }}' |
| 105 | + register: build_1 |
| 106 | + |
| 107 | + - assert: |
| 108 | + that: |
| 109 | + - build_1_check is changed |
| 110 | + - (build_1_check.actions | selectattr('status', 'eq', 'Building') | first) is truthy |
| 111 | + - build_1_check.warnings | default([]) | select('regex', 'Cannot parse event from ') | length == 0 |
| 112 | + - build_1 is changed |
| 113 | + - (build_1.actions | selectattr('status', 'eq', 'Building') | first) is truthy |
| 114 | + - build_1.warnings | default([]) | select('regex', 'Cannot parse event from ') | length == 0 |
0 commit comments