community.docker/tests/integration/targets/docker_compose_v2/tasks/tests/build.yml
Felix Fontein 68993fe353
docker_compose_v2: ignore result of build idempotency test since this seems like a hopeless case (#1196)
* Ignore result of idempotency test since this seems like a hopeless cause...

* And another one.
2025-11-15 17:06:21 +01:00

144 lines
5.6 KiB
YAML

---
# 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
- vars:
pname: "{{ name_prefix }}-build"
cname: "{{ name_prefix }}-container"
iname: "{{ name_prefix }}-image"
project_src: "{{ remote_tmp_dir }}/{{ pname }}"
test_service: |
services:
{{ cname }}:
build: ./build
image: "{{ iname }}"
pull_policy: never
stop_grace_period: 1s
block:
- name: Registering container name
ansible.builtin.set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
images: "{{ images + [iname] }}"
- name: Create project directory
ansible.builtin.file:
path: '{{ item }}'
state: directory
loop:
- '{{ project_src }}'
- '{{ project_src }}/build'
- name: Template default project file
ansible.builtin.copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'
- name: Template Dockerfile
ansible.builtin.copy:
dest: '{{ project_src }}/build/Dockerfile'
content: |
FROM {{ docker_test_image_alpine }}
ENTRYPOINT ["/bin/sh", "-c", "sleep 10m"]
- name: Present (check)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_1_check
- name: Present
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_1
- name: Present (idempotent check)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
check_mode: true
register: present_2_check
- name: Present (idempotent)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
register: present_2
- name: Present (idempotent check, build=always, ignore_build_events=false)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
ignore_build_events: false
check_mode: true
register: present_3_check
- name: Present (idempotent, build=always, ignore_build_events=false)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
ignore_build_events: false
register: present_3
- name: Present (idempotent check, build=always, ignore_build_events=true)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
ignore_build_events: true
check_mode: true
register: present_4_check
- name: Present (idempotent, build=always, ignore_build_events=true)
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: present
build: always
ignore_build_events: true
register: present_4
- ansible.builtin.assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
- present_1 is changed
- present_1.containers | length == 1
- present_1.containers[0].Name == (pname ~ '-' ~ cname ~ '-1')
- present_1.images | length == 1
- >-
docker_compose_version is version('2.37.0', '>=') or
present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- present_1.images[0].Repository == iname
- present_1.images[0].Tag == "latest"
- present_1.warnings | default([]) | select('regex', ' please report this at ') | length == 0
- present_2_check is not changed
- present_2_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
- present_2 is not changed
- present_2.warnings | default([]) | select('regex', ' please report this at ') | length == 0
# - present_3_check is changed -- whether this is true depends on a combination of Docker CLI and Docker Compose version...
# Compose 2.37.3 with Docker 28.2.x results in 'changed', while Compose 2.37.3 with Docker 28.3.0 results in 'not changed'.
# It seems that Docker is now clever enough to notice that nothing is rebuilt...
# With Docker 29.0.0, the behvaior seems to change again... I'm currently tending to simply ignore this check, for that
# reason the next three lines are commented out:
# - present_3_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
# - ((present_3 is changed) if docker_compose_version is version('2.31.0', '>=') and docker_compose_version is version('2.32.2', '<') else (present_3 is not changed))
# - present_3.warnings | default([]) | select('regex', ' please report this at ') | length == 0
# Same as above:
# - present_4_check is changed
- present_4_check.warnings | default([]) | select('regex', ' please report this at ') | length == 0
# Also seems like a hopeless case with Docker 29:
# - present_4 is not changed
- present_4.warnings | default([]) | select('regex', ' please report this at ') | length == 0
always:
- name: Cleanup
community.docker.docker_compose_v2:
project_src: '{{ project_src }}'
state: absent