feat(deploy): gate immutable production CI promotion on audited Stage acceptance

This commit is contained in:
Canina Engineering committed 2026-10-25 06:52:32 +00:00
1 parent 5f5c3eb3b9
commit 448c250944
6 files changed
+268 -11

No files matched your search

+9 -6
View File
@@ -3,7 +3,7 @@
set -euo pipefail
set +x
fail() { printf 'ERROR: %s\n' "$1" >&2; exit 2; }
[[ ${GITHUB_ACTIONS:-${GITEA_ACTIONS:-}} == true && ${BRANCH:-} == develop && $# == 0 ]] || fail 'CI-only Stage deployment; Production is blocked'
[[ ${GITHUB_ACTIONS:-${GITEA_ACTIONS:-}} == true && ( ${BRANCH:-} == develop || ${BRANCH:-} == main ) && $# == 0 ]] || fail 'CI-only immutable deployment'
[[ ${DEPLOY_SHA:-} =~ ^[0-9a-f]{40}$ ]] || fail 'immutable DEPLOY_SHA required'
# Repository secret DEPLOY_KEY is the historical approved devops SSH credential.
# Never fall back to baked-in runner keys, agent forwarding or docker.sock.
@@ -22,12 +22,12 @@ ssh -F /dev/null -T -p 2234 -i "$scratch/key" \
-o BatchMode=yes -o IdentitiesOnly=yes -o IdentityAgent=none \
-o StrictHostKeyChecking=yes -o UserKnownHostsFile="$scratch/known_hosts" \
-o GlobalKnownHostsFile=/dev/null -o ConnectTimeout=15 \
devops@87.248.133.138 "sudo -n bash -s -- $DEPLOY_SHA" <<'HOST'
devops@87.248.133.138 "sudo -n bash -s -- $DEPLOY_SHA $BRANCH" <<'HOST'
set -euo pipefail
set +x
umask 077
fail() { printf 'ERROR: host context: %s\n' "$1" >&2; exit 2; }
[[ $# == 1 && $1 =~ ^[0-9a-f]{40}$ ]] || fail 'immutable SHA required'
[[ $# == 2 && $1 =~ ^[0-9a-f]{40}$ && ( $2 == develop || $2 == main ) ]] || fail 'immutable SHA and approved branch required'
[[ ! -e /.dockerenv && ! -e /run/.containerenv ]] || fail 'refusing container filesystem'
[[ $(id -u) == 0 ]] || fail 'noninteractive approved sudo required'
for tool in bash python3 docker git flock realpath install wget; do command -v "$tool" >/dev/null || fail "missing $tool"; done
@@ -36,10 +36,13 @@ for tool in bash python3 docker git flock realpath install wget; do command -v "
docker compose version >/dev/null
docker volume inspect stage_canina_stage_db stage_canina_stage_uploads >/dev/null
docker network inspect traefik_public >/dev/null
printf 'Host context validated; Stage commit=%s; runtime env present; Production blocked\n' "$1"
if [[ $2 == main ]]; then
[[ -s /opt/services/canina/production-acceptance/$1.json ]] || fail 'audited Stage acceptance receipt missing'
fi
printf 'Host context validated; branch=%s commit=%s\n' "$2" "$1"
script=$(mktemp)
trap 'rm -f "$script"' EXIT
wget --no-proxy -qO "$script" "https://git.parsaaghayi.ir/parsa/canina/raw/commit/${1}/scripts/deploy.sh"
# CI marker exists only across this authenticated, fixed Stage boundary.
GITHUB_ACTIONS=true STAGE_PROVISION_ENABLED=true DEPLOY_SHA="$1" bash "$script" develop
# CI marker exists only across this authenticated, fixed host boundary.
GITHUB_ACTIONS=true STAGE_PROVISION_ENABLED=true DEPLOY_SHA="$1" bash "$script" "$2"
HOST