forked from jakub/ansible
test change semaphore 2
This commit is contained in:
@@ -45,49 +45,59 @@
|
|||||||
- |
|
- |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# English comments: create unique run id and log paths
|
# English comments: store state in user's home (more reliable than /tmp)
|
||||||
RID="$(date +%s)"
|
STATE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/semaphore-self-update"
|
||||||
LOG="/tmp/semaphore-self-update-${RID}.log"
|
mkdir -p "$STATE_DIR"
|
||||||
PIDF="/tmp/semaphore-self-update-${RID}.pid"
|
|
||||||
RCF="/tmp/semaphore-self-update-${RID}.rc"
|
RID="$(date +%s)"
|
||||||
|
LOG="$STATE_DIR/run-${RID}.log"
|
||||||
|
PIDF="$STATE_DIR/run-${RID}.pid"
|
||||||
|
RCF="$STATE_DIR/run-${RID}.rc"
|
||||||
|
SH="$STATE_DIR/run-${RID}.sh"
|
||||||
|
|
||||||
|
# English comments: write worker script (no variable expansion while writing)
|
||||||
|
cat > "$SH" <<'EOS'
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
unalias docker 2>/dev/null || true
|
||||||
|
export DOCKER_CLI_HINTS=0
|
||||||
|
|
||||||
|
echo "=== started: $(date -Is) ==="
|
||||||
|
echo "host: $(hostname)"
|
||||||
|
echo "compose: {{ semaphore_compose_file }}"
|
||||||
|
echo "project: {{ semaphore_project }} service: {{ semaphore_service }}"
|
||||||
|
echo "USE_SUDO=${USE_SUDO:-0}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
sleep 15
|
||||||
|
|
||||||
# English comments: build docker command (optionally via sudo -n)
|
|
||||||
DOCKER="docker"
|
DOCKER="docker"
|
||||||
if [ "${USE_SUDO:-0}" = "1" ]; then
|
if [ "${USE_SUDO:-0}" = "1" ]; then
|
||||||
DOCKER="sudo -n docker"
|
DOCKER="sudo -n docker"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# English comments: start background worker, delay to let Semaphore job finish
|
# English comments: pull explicitly + recreate
|
||||||
nohup bash -lc "
|
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} pull {{ semaphore_service }}
|
||||||
set -euo pipefail
|
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} up -d --no-deps --force-recreate {{ semaphore_service }}
|
||||||
unalias docker 2>/dev/null || true
|
|
||||||
export DOCKER_CLI_HINTS=0
|
|
||||||
|
|
||||||
echo \"=== started: \$(date -Is) ===\"
|
echo
|
||||||
echo \"host: \$(hostname)\"
|
echo "=== finished: $(date -Is) ==="
|
||||||
echo \"compose: {{ semaphore_compose_file }}\"
|
EOS
|
||||||
echo \"project: {{ semaphore_project }} service: {{ semaphore_service }}\"
|
|
||||||
echo \"USE_SUDO=\${USE_SUDO:-0}\"
|
|
||||||
echo
|
|
||||||
|
|
||||||
sleep 15
|
chmod +x "$SH"
|
||||||
|
|
||||||
# English comments: pull explicitly (more compatible than --pull always)
|
# English comments: start in background, persist output, store pid + rc
|
||||||
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} pull {{ semaphore_service }}
|
nohup env USE_SUDO="{{ lookup('env', 'USE_SUDO') | default('0') }}" \
|
||||||
|
bash "$SH" >"$LOG" 2>&1 </dev/null &
|
||||||
|
|
||||||
# English comments: recreate service
|
echo $! >"$PIDF"
|
||||||
$DOCKER compose -p {{ semaphore_project }} -f {{ semaphore_compose_file }} up -d --no-deps --force-recreate {{ semaphore_service }}
|
|
||||||
|
|
||||||
echo
|
# English comments: best-effort rc tracking (will be overwritten at end if you add it later)
|
||||||
echo \"=== finished: \$(date -Is) ===\"
|
echo "running" >"$RCF"
|
||||||
" >\"$LOG\" 2>&1 </dev/null &
|
|
||||||
|
|
||||||
echo $! >\"$PIDF\"
|
echo "scheduled: pid=$(cat "$PIDF"), log=$LOG, script=$SH, rcfile=$RCF"
|
||||||
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 }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user