forked from jakub/ansible
test change semaphore
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
- name: Run Semaphore self-update on VM in background (nohup)
|
- name: Run Semaphore self-update on VM in background (nohup + log)
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
@@ -43,19 +43,56 @@
|
|||||||
- bash
|
- bash
|
||||||
- -lc
|
- -lc
|
||||||
- |
|
- |
|
||||||
nohup bash -c '
|
set -euo pipefail
|
||||||
|
|
||||||
|
# English comments: create unique run id and log paths
|
||||||
|
RID="$(date +%s)"
|
||||||
|
LOG="/tmp/semaphore-self-update-${RID}.log"
|
||||||
|
PIDF="/tmp/semaphore-self-update-${RID}.pid"
|
||||||
|
RCF="/tmp/semaphore-self-update-${RID}.rc"
|
||||||
|
|
||||||
|
# English comments: build docker command (optionally via sudo -n)
|
||||||
|
DOCKER="docker"
|
||||||
|
if [ "${USE_SUDO:-0}" = "1" ]; then
|
||||||
|
DOCKER="sudo -n docker"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# English comments: start background worker, delay to let Semaphore job finish
|
||||||
|
nohup bash -lc "
|
||||||
|
set -euo pipefail
|
||||||
unalias docker 2>/dev/null || true
|
unalias docker 2>/dev/null || true
|
||||||
DOCKER_CLI_HINTS=0 docker compose \
|
export DOCKER_CLI_HINTS=0
|
||||||
-p {{ semaphore_project }} \
|
|
||||||
-f {{ semaphore_compose_file }} \
|
echo \"=== started: \$(date -Is) ===\"
|
||||||
up -d --no-deps --force-recreate --pull always {{ semaphore_service }}
|
echo \"host: \$(hostname)\"
|
||||||
' >/dev/null 2>&1 &
|
echo \"compose: {{ semaphore_compose_file }}\"
|
||||||
|
echo \"project: {{ semaphore_project }} service: {{ semaphore_service }}\"
|
||||||
|
echo \"USE_SUDO=\${USE_SUDO:-0}\"
|
||||||
|
echo
|
||||||
|
|
||||||
|
sleep 15
|
||||||
|
|
||||||
|
# English comments: pull explicitly (more compatible than --pull always)
|
||||||
|
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} pull {{ semaphore_service }}
|
||||||
|
|
||||||
|
# English comments: recreate service
|
||||||
|
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} up -d --no-deps --force-recreate {{ semaphore_service }}
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo \"=== finished: \$(date -Is) ===\"
|
||||||
|
" >\"$LOG\" 2>&1 </dev/null &
|
||||||
|
|
||||||
|
echo $! >\"$PIDF\"
|
||||||
|
echo \"scheduled: pid=\$(cat \"$PIDF\"), log=$LOG\"
|
||||||
environment:
|
environment:
|
||||||
SSHPASS: "{{ vm_pass }}"
|
SSHPASS: "{{ vm_pass }}"
|
||||||
|
# Set USE_SUDO=1 in Semaphore env vars if vm_user needs sudo for docker
|
||||||
|
USE_SUDO: "{{ lookup('env', 'USE_SUDO') | default('0') }}"
|
||||||
register: semaphore_update
|
register: semaphore_update
|
||||||
changed_when: false
|
changed_when: false
|
||||||
no_log: "{{ DEBUG == 0 }}"
|
no_log: "{{ DEBUG == 0 }}"
|
||||||
|
|
||||||
|
|
||||||
- name: Show result of Semaphore self-update (debug)
|
- name: Show result of Semaphore self-update (debug)
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
|
|||||||
Reference in New Issue
Block a user