Skip to content

Commit 024eb26

Browse files
karthikeyan5claude
andcommitted
deploy: remove two staging papercuts (preflight project + backend --no-traffic)
Both surfaced while running the v1.1-r2 staged deploy by hand. 1. scripts/deploy-preflight.sh read only $PROJECT (default placeholder), but the deploy scripts and .env.deploy.local set PROJECT_ID — so a deploy needed a separate `export PROJECT=...` or the preflight aborted "unsafe". Now PROJECT resolves from $PROJECT -> $PROJECT_ID -> PROJECT_ID in .env.deploy.local -> placeholder, so it just works (incl. a standalone run). 2. backend/deploy-gcp.sh had no staged option, so a code redeploy always went to 100% immediately — unlike the frontend, which has DEPLOY_NO_TRAFFIC. Add the same DEPLOY_NO_TRAFFIC=1 -> `--no-traffic --tag ${DEPLOY_TAG:-stg}` knob, applied to BOTH image-only and full deploy modes, so a staged canary + explicit promote is one command (proctor-api serves the live exam). Comments-only behaviour change is opt-in; default deploy paths are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c6022b5 commit 024eb26

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

backend/deploy-gcp.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,23 @@ COMMON_RUN_ARGS=(
230230
--timeout 120s
231231
)
232232

233+
# Staged zero-downtime option (mirrors frontend/deploy-gcp.sh): DEPLOY_NO_TRAFFIC=1
234+
# deploys a NEW revision WITHOUT taking traffic, tagged for verification on its tag
235+
# URL; promote later with `gcloud run services update-traffic "$SERVICE_NAME"
236+
# --to-revisions=<rev>=100` (prior revision held at 0% for instant rollback).
237+
# Applies to BOTH deploy modes. proctor-api serves the LIVE exam, so a staged
238+
# canary + explicit promote is the safe path during/near a test. Unset = the new
239+
# healthy revision serves 100% immediately.
240+
TRAFFIC_ARGS=()
241+
if [ -n "${DEPLOY_NO_TRAFFIC:-}" ]; then
242+
TRAFFIC_ARGS=(--no-traffic --tag "${DEPLOY_TAG:-stg}")
243+
fi
244+
233245
if [ "$DEPLOY_MODE" = "image-only" ]; then
234246
# Routine code-only redeploy: ship the new image, PRESERVE existing env +
235247
# secrets (no --set-env-vars / --set-secrets, which would replace them).
236248
echo "==> image-only deploy: preserving the service's existing env + secret mounts."
237-
gcloud run deploy "$SERVICE_NAME" "${COMMON_RUN_ARGS[@]}"
249+
gcloud run deploy "$SERVICE_NAME" "${COMMON_RUN_ARGS[@]}" "${TRAFFIC_ARGS[@]}"
238250
else
239251
# FULL deploy: set the COMPLETE env map + mount the signer key, atomically.
240252
# NOTE: --set-env-vars REPLACES the whole env map and --set-secrets REPLACES
@@ -290,7 +302,8 @@ else
290302
echo "==> full deploy: setting the complete env + mounting the signer key (${SIGNER_SECRET_NAME})."
291303
gcloud run deploy "$SERVICE_NAME" "${COMMON_RUN_ARGS[@]}" \
292304
--set-env-vars="$ENV_VARS" \
293-
--set-secrets="${SIGNER_MOUNT_PATH}=${SIGNER_SECRET_NAME}:latest"
305+
--set-secrets="${SIGNER_MOUNT_PATH}=${SIGNER_SECRET_NAME}:latest" \
306+
"${TRAFFIC_ARGS[@]}"
294307
fi
295308

296309
echo "Backend URL:"

scripts/deploy-preflight.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ set -euo pipefail
2323
cd "$(dirname "$0")/.."
2424

2525
REGION="${REGION:-asia-south1}"
26-
PROJECT="${PROJECT:-your-gcp-project-id}"
2726
SLUG="${1:-}"
2827
GCLOUD="${GCLOUD:-$HOME/google-cloud-sdk/bin/gcloud}"
2928

3029
if [ ! -f .env.deploy.local ]; then echo "✗ .env.deploy.local not found (need ADMIN_PASSWORD)"; exit 2; fi
3130
ADMINPW="$(grep -E '^ADMIN_PASSWORD=' .env.deploy.local | head -1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//')"
3231
if [ -z "$ADMINPW" ]; then echo "✗ ADMIN_PASSWORD missing from .env.deploy.local"; exit 2; fi
3332

33+
# Resolve the project from $PROJECT, then $PROJECT_ID (what the deploy scripts and
34+
# .env.deploy.local actually set), then PROJECT_ID read from .env.deploy.local, then
35+
# a placeholder. This removes the footgun of needing a separate `export PROJECT=...`
36+
# before a deploy — the frontend deploy invokes this preflight with PROJECT_ID set,
37+
# and a standalone run picks PROJECT_ID up straight from the deploy env file.
38+
ENV_PROJECT_ID="$(grep -E '^PROJECT_ID=' .env.deploy.local | head -1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//')"
39+
PROJECT="${PROJECT:-${PROJECT_ID:-${ENV_PROJECT_ID:-your-gcp-project-id}}}"
40+
3441
API_URL="$("$GCLOUD" run services describe proctor-api --region "$REGION" --project "$PROJECT" --format='value(status.url)' 2>/dev/null || true)"
3542
if [ -z "$API_URL" ]; then echo "✗ could not resolve proctor-api URL (gcloud auth?)"; exit 2; fi
3643

0 commit comments

Comments
 (0)