Files
computer-playbook/roles/docker-compose/handlers/main.yml
Kevin Veen-Birkenbach dece6228a4 Refactor docker-compose build logic and pull policy
- Added conditional '--pull' flag on retry in docker-compose build handler, tied to MODE_UPDATE
- Added 'pull_policy: never' to multiple docker-compose service templates to prevent unwanted image pulls
- Fixed minor formatting issues (e.g. Nextcloud volume spacing, WordPress desktop alignment)

Reference: https://chatgpt.com/share/68b0207a-4d9c-800f-b76f-9515885e5183
2025-08-28 11:25:35 +02:00

80 lines
2.4 KiB
YAML

---
- name: Validate Docker Compose configuration
command:
cmd: docker compose -f {{ docker_compose.files.docker_compose }} config --quiet
chdir: "{{ docker_compose.directories.instance }}"
register: dc_validate
changed_when: false
failed_when: dc_validate.rc != 0
listen:
- docker compose up
- docker compose restart
- docker compose just up
when: MODE_ASSERT | bool
- name: docker compose pull
shell: |
set -euo pipefail
lock="{{ [ PATH_DOCKER_COMPOSE_PULL_LOCK_DIR | docker_compose.directories.instance ] | path_join | hash('sha1') }}"
if [ ! -e "$lock" ]; then
mkdir -p "$(dirname "$lock")"
docker compose pull
: > "$lock"
echo "pulled"
fi
args:
chdir: "{{ docker_compose.directories.instance }}"
executable: /bin/bash
register: compose_pull
changed_when: "'pulled' in compose_pull.stdout"
environment:
COMPOSE_HTTP_TIMEOUT: 600
DOCKER_CLIENT_TIMEOUT: 600
when: MODE_UPDATE | bool
listen:
- docker compose up
- docker compose restart
- docker compose just up
- name: Build docker compose
shell: |
set -euo pipefail
docker compose build || {
echo "Retrying without cache and pulling bases...";
docker compose build --no-cache{{ ' --pull' if MODE_UPDATE | bool else ''}};
}
args:
chdir: "{{ docker_compose.directories.instance }}"
executable: /bin/bash
environment:
COMPOSE_HTTP_TIMEOUT: 600
DOCKER_CLIENT_TIMEOUT: 600
# Faster build
DOCKER_BUILDKIT: "1"
COMPOSE_DOCKER_CLI_BUILD: "1"
listen:
- docker compose build
- name: docker compose up
shell: |
if [ -f "{{ docker_compose.files.env }}" ]; then
docker compose -p {{ application_id | get_entity_name }} --env-file "{{ docker_compose.files.env }}" up -d --force-recreate --remove-orphans
else
docker compose -p {{ application_id | get_entity_name }} up -d --force-recreate --remove-orphans
fi
args:
chdir: "{{ docker_compose.directories.instance }}"
executable: /bin/bash
environment:
COMPOSE_HTTP_TIMEOUT: 600
DOCKER_CLIENT_TIMEOUT: 600
listen:
- docker compose up
- docker compose just up # @todo replace later just up by up when code is refactored, build atm is also listening to up
- name: docker compose restart
command:
cmd: 'docker compose restart'
chdir: "{{ docker_compose.directories.instance }}"
listen: docker compose restart