forked from jakub/ansible
fix: improve Semaphore update process by using array syntax for docker compose commands
This commit is contained in:
@@ -128,10 +128,7 @@
|
|||||||
- "{{ semaphore_compose_filename }}"
|
- "{{ semaphore_compose_filename }}"
|
||||||
pull: always
|
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
|
- name: Recreate Semaphore in the background
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cat > "{{ compose_remote_base }}/semaphore-selfupdate.sh" <<'SH'
|
cat > "{{ compose_remote_base }}/semaphore-selfupdate.sh" <<'SH'
|
||||||
@@ -139,15 +136,19 @@
|
|||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
exec 2>&1
|
exec 2>&1
|
||||||
cd "{{ compose_remote_dir }}" || exit 1
|
cd "{{ compose_remote_dir }}" || exit 1
|
||||||
|
COMPOSE=(docker compose -p "{{ semaphore_project }}" -f "{{ semaphore_compose_filename }}")
|
||||||
echo "=== $(date -Is) update starting ==="
|
echo "=== $(date -Is) update starting ==="
|
||||||
docker compose -p "{{ semaphore_project }}" \
|
"${COMPOSE[@]}" pull || { echo "FAIL: pull failed" >&2; exit 1; }
|
||||||
-f "{{ semaphore_compose_filename }}" \
|
"${COMPOSE[@]}" up -d --remove-orphans --wait --wait-timeout 300
|
||||||
up -d --remove-orphans --wait --wait-timeout 300
|
|
||||||
for _ in $(seq 1 60); do
|
for _ in $(seq 1 60); do
|
||||||
code=$(curl -s -o /dev/null -w '%{http_code}' \
|
code=$(curl -s -o /dev/null -w '%{http_code}' \
|
||||||
"http://127.0.0.1:{{ semaphore_port }}/api/ping" || true)
|
"http://127.0.0.1:{{ semaphore_port }}/api/ping" || true)
|
||||||
if [ "$code" = "200" ]; then
|
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"
|
| grep -m1 'SQLite @' || echo "WARN: no 'SQLite @' line"
|
||||||
echo "OK: semaphore healthy at $(date -Is)"
|
echo "OK: semaphore healthy at $(date -Is)"
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user