Compare commits

..

1 commit

Author SHA1 Message Date
Agent
6734887a0a fix: [nomad-step-1] S1.2 — add lib/init/nomad/deploy.sh (dependency-ordered nomad job run + wait) (#841)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/nomad-validate Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/pr/nomad-validate Pipeline was successful
2026-04-16 10:36:38 +00:00

View file

@ -30,7 +30,7 @@ set -euo pipefail
# ── Configuration ────────────────────────────────────────────────────────────
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="${REPO_ROOT:-$(cd "${SCRIPT_ROOT}/../.." && pwd)}"
REPO_ROOT="${REPO_ROOT:-$(cd "${SCRIPT_ROOT}/../../.." && pwd)}"
JOB_READY_TIMEOUT_SECS="${JOB_READY_TIMEOUT_SECS:-120}"
DRY_RUN=0
@ -96,28 +96,14 @@ _wait_job_running() {
log "job '${job_name}' is now running"
return 0
;;
complete|dead|failed)
# Check allocations for partial success
local allocs_running
allocs_running=$(printf '%s' "$status_json" \
| jq '[.Evaluations[].Allocations[]? | select(.Status == "running")] | length' 2>/dev/null) || allocs_running=0
local allocs_total
allocs_total=$(printf '%s' "$status_json" \
| jq '[.Evaluations[].Allocations[]? | length] | add' 2>/dev/null) || allocs_total=0
if [ "$allocs_running" -gt 0 ]; then
log "job '${job_name}' has ${allocs_running}/${allocs_total} allocations running"
# If not all running but some are, keep waiting
if [ "$allocs_running" -lt "$allocs_total" ]; then
sleep 5
elapsed=$((elapsed + 5))
continue
fi
fi
complete)
log "job '${job_name}' reached terminal state: ${status}"
return 0
;;
dead|failed)
log "job '${job_name}' reached terminal state: ${status}"
return 1
;;
*)
log "job '${job_name}' status: ${status} (waiting...)"
;;
@ -170,10 +156,13 @@ for job_name in "${JOBS[@]}"; do
fi
# 2. Check if already running (idempotency)
job_status=$(nomad job status "$job_name" 2>/dev/null | head -1 || true)
if printf '%s' "$job_status" | grep -qi "running"; then
log "${job_name} already running"
continue
job_status_json=$(nomad job status -json "$job_name" 2>/dev/null || true)
if [ -n "$job_status_json" ]; then
current_status=$(printf '%s' "$job_status_json" | jq -r '.Status' 2>/dev/null || true)
if [ "$current_status" = "running" ]; then
log "${job_name} already running"
continue
fi
fi
# 3. Run the job (idempotent registration)