GCP & Cloud Engineer Guide: Zero-Downtime Multi-Service Google App Engine & Cloud Run CD in GitLab
Deploying a multi-service Google Cloud Platform application (such as `default`, `api`, and `worker` services on App Engine or Cloud Run) via manual `gcloud app deploy` commands or long-lived JSON service account keys stored in GitLab CI variables creates both security exposure and mid-deployment version skew. Worse, deploying with `--promote` immediately routes 100% of production traffic to an unverified version before smoke tests run. As a GCP engineer and cloud engineer, I architect keyless Workload Identity Federation (WIF) pipelines with staged `--no-promote` smoke testing and gradual traffic splitting.
1. Keyless GitLab OIDC Authentication & Staged --no-promote Deployment
We exchange GitLab's `$CI_JOB_JWT_V2` OIDC token for a short-lived Google Cloud STS credential, deploy the new revision with `--no-promote` so it receives 0% live user traffic, run automated health probes against the revision-specific URL, and then shift traffic:
# .gitlab-ci.yml (GCP Staged Rollout)
deploy_gcp_api_service:
stage: deploy
image: google/cloud-sdk:478.0.0-slim
id_tokens:
GITLAB_OIDC_TOKEN:
aud: "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/gitlab-pool/providers/gitlab-oidc"
variables:
GCP_PROJECT_ID: "prod-afcom-gcp"
VERSION_ID: "v-${CI_COMMIT_SHORT_SHA}"
script:
- echo "${GITLAB_OIDC_TOKEN}" > /tmp/oidc_token.jwt
- gcloud iam workload-identity-pools create-cred-config
"projects/123456789/locations/global/workloadIdentityPools/gitlab-pool/providers/gitlab-oidc"
--service-account="ci-deployer@${GCP_PROJECT_ID}.iam.gserviceaccount.com"
--credential-source-file="/tmp/oidc_token.jwt"
--output-file="/tmp/gcp_creds.json"
- export GOOGLE_APPLICATION_CREDENTIALS="/tmp/gcp_creds.json"
- gcloud auth login --cred-file="/tmp/gcp_creds.json"
# 1. Deploy new version without routing live traffic
- gcloud app deploy services/api/app.yaml --project="${GCP_PROJECT_ID}" --version="${VERSION_ID}" --no-promote --quiet
# 2. Smoke-test the isolated version URL directly
- curl --fail --retry 5 --retry-delay 3 "https://${VERSION_ID}-dot-api-dot-${GCP_PROJECT_ID}.et.r.appspot.com/healthz"
# 3. Promote traffic only after health check passes
- gcloud app services set-traffic api --splits="${VERSION_ID}=1" --project="${GCP_PROJECT_ID}" --quiet
2. Synchronizing `dispatch.yaml` and Cloud Tasks Queues
In multi-service architectures, always version-control and deploy `dispatch.yaml` and `queue.yaml` in a dedicated pre-traffic stage so new URL path prefixes and Cloud Tasks rate limits exist before the application code starts enqueuing background jobs.