94 lines
2.6 KiB
Bash
Executable File
94 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
deploy_web() {
|
|
pnpm --offline --config.inject-workspace-packages=true \
|
|
--filter @hivegrid/runtime-web deploy --prod /prod/web
|
|
}
|
|
|
|
deploy_api() {
|
|
pnpm --offline --config.inject-workspace-packages=true \
|
|
--filter @hivegrid/runtime-api deploy --prod --no-optional /prod/api
|
|
}
|
|
|
|
deploy_mcp() {
|
|
pnpm --offline --config.inject-workspace-packages=true \
|
|
--filter @hivegrid/runtime-mcp deploy --prod --no-optional /prod/mcp
|
|
}
|
|
|
|
deploy_portal_controller() {
|
|
pnpm --offline --config.inject-workspace-packages=true \
|
|
--filter @hivegrid/runtime-portal-domain-controller deploy --prod --no-optional /prod/portal-domain-controller
|
|
}
|
|
|
|
deploy_worker() {
|
|
pnpm --offline --config.inject-workspace-packages=true \
|
|
--filter @hivegrid/runtime-worker deploy --prod /prod/worker
|
|
}
|
|
|
|
tasks=(deploy_web deploy_api deploy_mcp deploy_portal_controller deploy_worker)
|
|
targets=(web api mcp portal-domain-controller worker)
|
|
mkdir -p /prod
|
|
|
|
run_wave() {
|
|
local phase="$1"
|
|
local status=0
|
|
local child_status
|
|
local index
|
|
local task
|
|
local -a pids=()
|
|
|
|
for task in "${tasks[@]}"; do
|
|
echo "[production-deps] START phase=${phase} task=${task}" >&2
|
|
"$task" &
|
|
pids+=("$!")
|
|
done
|
|
|
|
# Always reap every child. A quick failure must not leave another deploy
|
|
# writing into /prod while the fallback cleans or retries the closures.
|
|
for index in "${!pids[@]}"; do
|
|
if wait "${pids[$index]}"; then
|
|
echo "[production-deps] PASS phase=${phase} task=${tasks[$index]}" >&2
|
|
continue
|
|
else
|
|
child_status=$?
|
|
fi
|
|
|
|
echo "[production-deps] FAIL phase=${phase} task=${tasks[$index]} exit_code=${child_status}" >&2
|
|
if [[ "$status" -eq 0 ]]; then
|
|
status="$child_status"
|
|
fi
|
|
done
|
|
|
|
return "$status"
|
|
}
|
|
|
|
initial_status=0
|
|
run_wave offline-first || initial_status=$?
|
|
if [[ "$initial_status" -eq 0 ]]; then
|
|
echo "[production-deps] READY source=warm-store" >&2
|
|
exit 0
|
|
fi
|
|
|
|
echo "[production-deps] REFRESH initial_exit_code=${initial_status}" >&2
|
|
for target in "${targets[@]}"; do
|
|
rm -rf -- "/prod/${target}"
|
|
done
|
|
|
|
if pnpm fetch --frozen-lockfile; then
|
|
echo "[production-deps] FETCH PASS" >&2
|
|
else
|
|
fetch_status=$?
|
|
echo "[production-deps] FETCH FAIL exit_code=${fetch_status} initial_exit_code=${initial_status}" >&2
|
|
exit "$fetch_status"
|
|
fi
|
|
|
|
retry_status=0
|
|
run_wave after-fetch || retry_status=$?
|
|
if [[ "$retry_status" -ne 0 ]]; then
|
|
echo "[production-deps] RETRY FAIL exit_code=${retry_status} initial_exit_code=${initial_status}" >&2
|
|
exit "$retry_status"
|
|
fi
|
|
|
|
echo "[production-deps] READY source=refreshed-store initial_exit_code=${initial_status}" >&2
|