71 lines
3.5 KiB
Bash
71 lines
3.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Gitea push main -> production only if the identical SHA is live on release dev.
|
|
set -euo pipefail
|
|
|
|
sha="${EXPECTED_SHA:?EXPECTED_SHA is required}"
|
|
test "${EXPECTED_REF:-}" = refs/heads/main
|
|
test "$(git rev-parse HEAD)" = "$sha"
|
|
checkout=$(pwd -P)
|
|
stage=/home/mcp-user/smeta-web-release
|
|
prod=/home/mcp-user/smeta-web
|
|
python_bin=/home/mcp-user/python314-migration-venv/bin/python
|
|
test -x "$python_bin"
|
|
"$python_bin" -c 'import sys; assert sys.version_info[:2] == (3, 14), sys.version'
|
|
export PYTHON_BIN="$python_bin"
|
|
export PYTHONNOUSERSITE=1
|
|
index=data/real_corpus/estimates_ext_index.json
|
|
marker=/data_safe/backups/smeta-web/release-ready.json
|
|
log="/data_safe/backups/smeta-web/release-prod-${sha:0:12}.log"
|
|
|
|
exec 9>/tmp/smeta-release-deploy.lock
|
|
flock -w 1800 9
|
|
test "$(git -C "$prod" branch --show-current)" = main
|
|
remote=$(HTTPS_PROXY= HTTP_PROXY= NO_PROXY='*' git -C "$prod" ls-remote --exit-code origin refs/heads/main | cut -f1)
|
|
test "$remote" = "$sha"
|
|
HTTPS_PROXY= HTTP_PROXY= NO_PROXY='*' git -C "$prod" fetch -q origin main
|
|
git -C "$prod" merge-base --is-ancestor HEAD "$sha"
|
|
"$python_bin" "$checkout/scripts/release_gate.py" verify "$sha" "$stage" "$prod/$index" "$marker"
|
|
systemctl is-active --quiet smeta-web-release
|
|
curl -fsS --noproxy '*' http://127.0.0.1:8106/health | grep -q '"status":"ok"'
|
|
index_before=$(sha256sum "$prod/$index" | cut -d' ' -f1)
|
|
env_before=$(sha256sum "$prod/.env" | cut -d' ' -f1)
|
|
|
|
# Fresh full gate for this exact main push; the dev approval can be days old.
|
|
cp "$prod/$index" "$checkout/$index"
|
|
sqlite3 "$prod/smeta-web.db" ".backup $checkout/smeta-web.db"
|
|
mkdir -p "$checkout/tests/fixtures/tsn_local"
|
|
for pdf in tsn3-1.pdf index222.pdf; do
|
|
cp "$prod/tests/fixtures/tsn_local/$pdf" "$checkout/tests/fixtures/tsn_local/$pdf"
|
|
done
|
|
PYTHONPATH="$checkout:/home/mcp-user/smeta-railway/src" \
|
|
APP_DIR="$checkout" COPY_DIR=/home/mcp-user/smeta-prod-auto-predeploy \
|
|
bash "$checkout/scripts/predeploy-tests.sh" > "$log" 2>&1 || {
|
|
tail -30 "$log" >&2
|
|
exit 1
|
|
}
|
|
test "$(head -n 1 "$checkout/.predeploy-stamp")" = "$sha"
|
|
grep -q "^python: 3\.14\.[0-9]* $python_bin$" "$checkout/.predeploy-stamp"
|
|
test "$(sha256sum "$prod/$index" | cut -d' ' -f1)" = "$index_before"
|
|
test "$(sha256sum "$prod/.env" | cut -d' ' -f1)" = "$env_before"
|
|
test "$(HTTPS_PROXY= HTTP_PROXY= NO_PROXY='*' git -C "$prod" ls-remote --exit-code origin refs/heads/main | cut -f1)" = "$sha"
|
|
"$python_bin" "$checkout/scripts/release_gate.py" verify "$sha" "$stage" "$prod/$index" "$marker"
|
|
cp "$checkout/.predeploy-stamp" "$prod/.predeploy-stamp"
|
|
# Запускаем deploy.sh именно из проверенного SHA: скрипт в боевом каталоге
|
|
# до fast-forward ещё старый и иначе использует Python 3.10.
|
|
export PYTHONPATH="$prod:/home/mcp-user/smeta-railway/src"
|
|
APP_DIR="$prod" bash "$checkout/scripts/deploy.sh"
|
|
|
|
test "$(git -C "$prod" rev-parse HEAD)" = "$sha"
|
|
test "$(sha256sum "$prod/$index" | cut -d' ' -f1)" = "$index_before"
|
|
test "$(sha256sum "$prod/.env" | cut -d' ' -f1)" = "$env_before"
|
|
systemctl is-active --quiet smeta-web
|
|
curl -fsS --noproxy '*' http://127.0.0.1:8101/health | grep -q '"status":"ok"'
|
|
(cd "$prod" && "$python_bin" scripts/migrate_python314_cron.py)
|
|
(cd "$prod" && set -a && . ./.env && set +a &&
|
|
"$python_bin" -c 'import health_checks; assert health_checks.check_unpriced_runs().ok')
|
|
canary=$(cd "$prod" && CANARY_DRY_RUN=1 \
|
|
JOURNEY_STATE=/tmp/smeta-release-journey.state bash scripts/journey_canary.sh)
|
|
printf '%s\n' "$canary"
|
|
[[ "$canary" == *' OK journey:'* ]]
|
|
echo "RELEASE_PROD_OK sha=$sha log=$log"
|