59 lines
2.2 KiB
YAML
59 lines
2.2 KiB
YAML
steps:
|
|
ssh-test:
|
|
image: google/cloud-sdk:latest
|
|
entrypoint:
|
|
- bash
|
|
- -c
|
|
- |
|
|
set -euo pipefail
|
|
|
|
mkdir -p ~/.ssh
|
|
|
|
# ── Secrets for SSH ────────────────────────────────────────
|
|
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"
|
|
|
|
# ── Log what the CI knows ──────────────────────────────────
|
|
echo "🔍 CI_COMMIT_SHA: ${CI_COMMIT_SHA:-unset}"
|
|
echo "🔍 CI_COMMIT: ${CI_COMMIT:-unset}"
|
|
echo "🔍 DRONE_COMMIT_SHA: ${DRONE_COMMIT_SHA:-unset}"
|
|
|
|
# ── Resolve tag safely ─────────────────────────────────────
|
|
RAW_SHA="${CI_COMMIT_SHA:-${CI_COMMIT:-${DRONE_COMMIT_SHA:-}}}"
|
|
if [ -z "$RAW_SHA" ]; then
|
|
echo "❌ CI commit SHA not found. Aborting."
|
|
exit 1
|
|
fi
|
|
TAG=$(echo "$RAW_SHA" | head -c 8)
|
|
echo "🚀 Deploying tag ${TAG} to staging"
|
|
|
|
# ── SSH into staging and refresh ───────────────────────────
|
|
ssh -o StrictHostKeyChecking=yes \
|
|
-i ~/.ssh/id_ed25519 \
|
|
jcoakley@10.128.0.12 \
|
|
"export IMG_TAG=${TAG}; \
|
|
cd /home/jcoakley/aptiva-staging-app; \
|
|
echo 'Pulling containers with IMG_TAG=${IMG_TAG}'; \
|
|
docker compose pull; \
|
|
echo 'Recreating services'; \
|
|
docker compose up -d --force-recreate --remove-orphans; \
|
|
echo '✅ Staging stack refreshed with tag ${IMG_TAG}'"
|
|
|
|
environment:
|
|
CI_COMMIT_SHA: ${CI_COMMIT_SHA}
|
|
CI_COMMIT: ${CI_COMMIT}
|
|
DRONE_COMMIT_SHA: ${DRONE_COMMIT_SHA}
|
|
|
|
when:
|
|
event:
|
|
- push
|