steps: ssh-deploy: image: google/cloud-sdk:latest entrypoint: - bash - -c - | set -euo pipefail mkdir -p ~/.ssh # 1. Install SSH prerequisites ────────────────────────────── gcloud secrets versions access latest \ --secret=STAGING_KNOWN_HOSTS --project=aptivaai-dev \ | base64 -d > ~/.ssh/known_hosts chmod 644 ~/.ssh/known_hosts gcloud secrets versions access latest \ --secret=STAGING_SSH_KEY --project=aptivaai-dev \ | base64 -d > ~/.ssh/id_ed25519 chmod 600 ~/.ssh/id_ed25519 echo "🔑 SSH prerequisites installed" # 2. Fetch canonical IMG_TAG (trim newline) ───────────────── IMG_TAG=$(gcloud secrets versions access latest \ --secret=IMG_TAG --project=aptivaai-dev | tr -d '\n') echo "📦 IMG_TAG=${IMG_TAG}" # 3. SSH to staging and redeploy ──────────────────────────── ssh -o StrictHostKeyChecking=yes \ -i ~/.ssh/id_ed25519 \ jcoakley@10.128.0.12 \ "set -euo pipefail; \ export IMG_TAG=${IMG_TAG}; \ cd /home/jcoakley/aptiva-staging-app; \ echo 'Pulling containers for tag ${IMG_TAG}'; \ docker compose pull; \ echo 'Re‑creating services'; \ docker compose up -d --force-recreate --remove-orphans; \ echo '✅ Staging stack refreshed with tag ${IMG_TAG}'" secrets: [ STAGING_SSH_KEY, STAGING_KNOWN_HOSTS ] when: event: - push