pipeline secrets injection test v3

This commit is contained in:
Josh 2025-07-31 13:08:27 +00:00
parent 21ee8263f9
commit b702242302

View File

@ -1,14 +1,53 @@
steps: steps:
- name: echo-secret # ── 1. Build & push images ──────────────────────────────
image: alpine:latest - name: build-and-push
image: docker:24.0-cli
privileged: true
volumes:
- name: docker-sock
path: /var/run/docker.sock
environment: environment:
STAGING_SSH_KEY: test123 REG: us-central1-docker.pkg.dev/aptivaai-dev/aptiva-repo
commands: commands:
- | - |
echo "START SECRET" set -eu
echo "$STAGING_SSH_KEY" | wc -c TAG=$(echo "$CI_COMMIT_SHA" | head -c 8)
echo "$STAGING_SSH_KEY" | head -c 64 docker buildx create --use --name woodpecker || true
echo "END SECRET" for svc in server1 server2 server3 nginx; do
docker buildx build -f Dockerfile.${svc} \
-t ${REG}/${svc}:${TAG} --push .
done
when: when:
event: [push, manual] event: [push, manual]
branch: [master] branch: [master]
# ── 2. Deploy to staging ────────────────────────────────
- name: deploy-staging
image: alpine:latest
environment:
STAGING_SSH_KEY_B64: <base64-encoded-key>
STAGING_KNOWN_HOSTS_B64: <base64-encoded-known-hosts>
commands:
- |
set -eu
apk add --no-cache openssh bash
mkdir -p ~/.ssh
echo "$STAGING_KNOWN_HOSTS_B64" | base64 -d > ~/.ssh/known_hosts
echo "$STAGING_SSH_KEY_B64" | base64 -d > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
TAG=$(echo "$CI_COMMIT_SHA" | head -c 8)
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=yes jcoakley@10.128.0.12 <<EOF
cd /opt/aptiva-staging-app
IMG_TAG=$TAG docker compose pull
IMG_TAG=$TAG docker compose up -d --force-recreate --remove-orphans
EOF
when:
event: [push, manual]
branch: [master]
volumes:
- name: docker-sock
host:
path: /var/run/docker.sock