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 ──────────────────────────────────────────────────────────── # ── Configuration ────────────────────────────────────────────────────────────
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 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}" JOB_READY_TIMEOUT_SECS="${JOB_READY_TIMEOUT_SECS:-120}"
DRY_RUN=0 DRY_RUN=0
@ -96,28 +96,14 @@ _wait_job_running() {
log "job '${job_name}' is now running" log "job '${job_name}' is now running"
return 0 return 0
;; ;;
complete|dead|failed) complete)
# 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
log "job '${job_name}' reached terminal state: ${status}" log "job '${job_name}' reached terminal state: ${status}"
return 0 return 0
;; ;;
dead|failed)
log "job '${job_name}' reached terminal state: ${status}"
return 1
;;
*) *)
log "job '${job_name}' status: ${status} (waiting...)" log "job '${job_name}' status: ${status} (waiting...)"
;; ;;
@ -170,11 +156,14 @@ for job_name in "${JOBS[@]}"; do
fi fi
# 2. Check if already running (idempotency) # 2. Check if already running (idempotency)
job_status=$(nomad job status "$job_name" 2>/dev/null | head -1 || true) job_status_json=$(nomad job status -json "$job_name" 2>/dev/null || true)
if printf '%s' "$job_status" | grep -qi "running"; then 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" log "${job_name} already running"
continue continue
fi fi
fi
# 3. Run the job (idempotent registration) # 3. Run the job (idempotent registration)
log "running: ${jobspec_path}" log "running: ${jobspec_path}"