Created
July 13, 2026 08:15
-
-
Save bogdan/b1f88df6ba08aee21563bc172967aa34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| steps: | |
| # Pull cache images for both build stage and final image (ignore failure on first run) | |
| - id: "pull-cache" | |
| name: "gcr.io/cloud-builders/docker" | |
| entrypoint: /bin/bash | |
| args: | |
| - -c | |
| - | | |
| docker pull ${_IMAGE_NAME}:build-cache || true && \ | |
| docker pull ${_IMAGE_NAME}:latest || true | |
| # Build the Docker image, injecting RAILS_MASTER_KEY as a build arg | |
| - id: "build" | |
| name: "gcr.io/cloud-builders/docker" | |
| entrypoint: bash | |
| args: | |
| - -c | |
| - | | |
| docker build \ | |
| --target build \ | |
| -t ${_IMAGE_NAME}:build-cache \ | |
| --cache-from ${_IMAGE_NAME}:build-cache \ | |
| --build-arg BUILDKIT_INLINE_CACHE=1 \ | |
| . && \ | |
| docker build \ | |
| -t ${_IMAGE_NAME}:${_SHA} \ | |
| -t ${_IMAGE_NAME}:latest \ | |
| --cache-from ${_IMAGE_NAME}:build-cache \ | |
| --cache-from ${_IMAGE_NAME}:latest \ | |
| --build-arg BUILDKIT_INLINE_CACHE=1 \ | |
| --build-arg MASTER_KEY=$$RAILS_MASTER_KEY \ | |
| . | |
| env: | |
| - DOCKER_BUILDKIT=1 | |
| secretEnv: | |
| - RAILS_MASTER_KEY | |
| # Push both SHA-tagged, latest, and build-cache images | |
| - id: "push" | |
| name: "gcr.io/cloud-builders/docker" | |
| entrypoint: /bin/bash | |
| args: | |
| - -c | |
| - | | |
| docker push ${_IMAGE_NAME}:build-cache && \ | |
| docker push --all-tags ${_IMAGE_NAME} | |
| # Deploy web service | |
| - id: "deploy-web" | |
| waitFor: ["push"] | |
| name: "gcr.io/google.com/cloudsdktool/cloud-sdk" | |
| entrypoint: gcloud | |
| args: | |
| - run | |
| - deploy | |
| - realphotos-web | |
| - --image=${_IMAGE_NAME}:${_SHA} | |
| - --region=${_REGION} | |
| - --platform=managed | |
| - --allow-unauthenticated | |
| - --port=80 | |
| - --min-instances=1 | |
| - --memory=1Gi | |
| - --set-cloudsql-instances=${_CLOUDSQL_INSTANCE} | |
| - --set-secrets=RAILS_MASTER_KEY=rails-master-key:2,DATABASE_URL=database-url:latest | |
| # Deploy worker service | |
| - id: "deploy-worker" | |
| waitFor: ["push"] | |
| name: "gcr.io/google.com/cloudsdktool/cloud-sdk" | |
| entrypoint: gcloud | |
| args: | |
| - run | |
| - deploy | |
| - realphotos-worker | |
| - --image=${_IMAGE_NAME}:${_SHA} | |
| - --region=${_REGION} | |
| - --platform=managed | |
| - --no-allow-unauthenticated | |
| - --port=8080 | |
| - --min-instances=1 | |
| - --max-instances=1 | |
| - --set-cloudsql-instances=${_CLOUDSQL_INSTANCE} | |
| - --set-secrets=RAILS_MASTER_KEY=rails-master-key:2,DATABASE_URL=database-url:latest | |
| - --command=bundle | |
| - --args=exec,good_job,start,--probe-port=8080 | |
| images: | |
| - "${_IMAGE_NAME}:${_SHA}" | |
| - "${_IMAGE_NAME}:latest" | |
| - "${_IMAGE_NAME}:build-cache" | |
| availableSecrets: | |
| secretManager: | |
| - versionName: projects/${PROJECT_ID}/secrets/rails-master-key/versions/2 | |
| env: RAILS_MASTER_KEY | |
| substitutions: | |
| _REGION: us-central1 | |
| _SHA: latest | |
| _AR_REPO: us-central1-docker.pkg.dev/${PROJECT_ID}/realphotos | |
| _IMAGE_NAME: ${_AR_REPO}/app | |
| _CLOUDSQL_INSTANCE: ${PROJECT_ID}:${_REGION}:realphotos-db | |
| options: | |
| logging: LEGACY | |
| dynamicSubstitutions: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment