diff --git a/update_semaphore.yml b/update_semaphore.yml index 8123916..22bae85 100644 --- a/update_semaphore.yml +++ b/update_semaphore.yml @@ -128,10 +128,7 @@ - "{{ semaphore_compose_filename }}" pull: always - # Cannot use docker_compose_v2 here: recreating the container kills this - # very Ansible process. Detached so the update outlives the job. - # No `recreate: always` — compose recreates only when the image or the - # resolved config actually changed, so unchanged runs finish green. + - name: Recreate Semaphore in the background ansible.builtin.shell: | cat > "{{ compose_remote_base }}/semaphore-selfupdate.sh" <<'SH' @@ -139,15 +136,19 @@ set -uo pipefail exec 2>&1 cd "{{ compose_remote_dir }}" || exit 1 + COMPOSE=(docker compose -p "{{ semaphore_project }}" -f "{{ semaphore_compose_filename }}") echo "=== $(date -Is) update starting ===" - docker compose -p "{{ semaphore_project }}" \ - -f "{{ semaphore_compose_filename }}" \ - up -d --remove-orphans --wait --wait-timeout 300 + "${COMPOSE[@]}" pull || { echo "FAIL: pull failed" >&2; exit 1; } + "${COMPOSE[@]}" up -d --remove-orphans --wait --wait-timeout 300 for _ in $(seq 1 60); do code=$(curl -s -o /dev/null -w '%{http_code}' \ "http://127.0.0.1:{{ semaphore_port }}/api/ping" || true) if [ "$code" = "200" ]; then - docker logs --tail 40 "{{ semaphore_container }}" 2>&1 \ + echo "image: $(docker inspect "{{ semaphore_container }}" \ + --format '{{ '{{' }}.Config.Image{{ '}}' }}')" + # --tail 40 misses the startup line when the container was not + # recreated; grep the whole log instead + docker logs "{{ semaphore_container }}" 2>&1 \ | grep -m1 'SQLite @' || echo "WARN: no 'SQLite @' line" echo "OK: semaphore healthy at $(date -Is)" exit 0