Skip to content

chore: add GCP Cloud Run deployment scripts#1

Merged
austinw8 merged 1 commit into
mainfrom
chore/gcp-cloud-run-deploy
Jun 16, 2026
Merged

chore: add GCP Cloud Run deployment scripts#1
austinw8 merged 1 commit into
mainfrom
chore/gcp-cloud-run-deploy

Conversation

@eglenn-dev

Copy link
Copy Markdown
Collaborator

Summary

Adds a self-contained toolkit for deploying this app to Google Cloud using
Cloud Run + Cloud SQL (PostgreSQL) + Artifact Registry + Secret Manager
the natural fit since the app already ships a production docker/Dockerfile,
listens on $PORT, exposes /api/health, and runs migrations on startup.

What's included

  • cloudbuild.yaml (repo root) — builds the image from docker/Dockerfile
    (which isn't at the root) with the repo as context.
  • deploy/gcp/ — config-driven, idempotent bash scripts:
    • config.example.sh → copy to config.sh (gitignored) and edit
    • 00-prerequisites.sh — enable APIs + create Artifact Registry repo
    • 01-database.sh — Cloud SQL instance/db/user + connection-string secret
    • 02-secrets.sh — encryption/auth secrets, self-signed signing cert, IAM
    • 03-build.sh — Cloud Build → Artifact Registry
    • 04-deploy.shgcloud run deploy with Cloud SQL, secrets, env wired in
    • 05-migrate-job.sh(optional) run migrations as a one-off Cloud Run Job
    • deploy-all.sh — runs 00→04 in order
    • 99-teardown.sh — destructive cleanup (confirmation required)
    • README.md — architecture, quick start, decision points, troubleshooting

Notable choices (documented in the README)

  • database upload transport keeps Cloud Run stateless (docs in Postgres).
  • --min-instances=1 --no-cpu-throttling so the in-process local jobs
    provider keeps running scheduled work.
  • Cloud SQL via unix socket (--add-cloudsql-instances); runtime SA gets
    cloudsql.client + secretmanager.secretAccessor.
  • Self-signed signing cert is generated for testing; README covers swapping
    in a real cert or Cloud KMS HSM signing for production.
  • Secrets live in Secret Manager; nothing sensitive is committed (config.sh,
    *.p12, *.pem are gitignored).

How to use

cd deploy/gcp
cp config.example.sh config.sh   # edit PROJECT_ID, REGION, SMTP, ...
./deploy-all.sh

Notes for reviewers

  • No application code is touched — purely additive ops tooling.
  • All scripts pass bash -n; not yet executed against a live GCP project.
  • SMTP credentials must be supplied in config.sh for outbound email to work.

🤖 Generated with Claude Code

Add a deploy/gcp toolkit (config-driven, idempotent bash scripts) plus a
root cloudbuild.yaml to deploy the app to Google Cloud using Cloud Run,
Cloud SQL for PostgreSQL, Artifact Registry and Secret Manager.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@austinw8 austinw8 marked this pull request as ready for review June 16, 2026 21:40
Copilot AI review requested due to automatic review settings June 16, 2026 21:40
@austinw8 austinw8 merged commit 4443f5a into main Jun 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a self-contained GCP deployment toolkit to deploy the existing Dockerized app to Cloud Run with Cloud SQL (PostgreSQL), Artifact Registry, Secret Manager, and Cloud Build.

Changes:

  • Adds cloudbuild.yaml to build/push the image using docker/Dockerfile from repo-root context.
  • Introduces deploy/gcp/* idempotent-ish bash scripts to provision prerequisites, database, secrets/IAM, build, deploy, optional migration job, and teardown.
  • Updates .gitignore to prevent committing local GCP config and generated cert/key artifacts.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
deploy/gcp/README.md Documents the Cloud Run + Cloud SQL + Secret Manager architecture, script flow, and operational decision points.
deploy/gcp/deploy-all.sh Convenience runner to execute steps 00→04 in order.
deploy/gcp/config.example.sh Template config users copy to config.sh for project/region/runtime sizing and SMTP/signing inputs.
deploy/gcp/common.sh Shared config loading + helper functions (gcloud wrapper, secret helpers, runtime SA resolver).
deploy/gcp/00-prerequisites.sh Enables required GCP APIs and creates Artifact Registry repo.
deploy/gcp/01-database.sh Provisions Cloud SQL instance/db/user and stores DB URL in Secret Manager.
deploy/gcp/02-secrets.sh Creates encryption/auth/signing secrets and binds runtime SA IAM for Secret Manager + Cloud SQL.
deploy/gcp/03-build.sh Submits Cloud Build using cloudbuild.yaml and pushes to Artifact Registry.
deploy/gcp/04-deploy.sh Deploys Cloud Run service wiring Cloud SQL, secrets, and env vars; resolves service URL.
deploy/gcp/05-migrate-job.sh Optional Cloud Run Job to run prisma migrate deploy separately from service rollout.
deploy/gcp/99-teardown.sh Destructive cleanup for all resources created by the toolkit (with confirmation).
cloudbuild.yaml Cloud Build definition for building/pushing the container image from docker/Dockerfile.
.gitignore Ignores deploy/gcp/config.sh and local cert/key artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deploy/gcp/02-secrets.sh
Comment on lines +54 to +57
if [[ -n "${SIGNING_PASSPHRASE:-}" ]]; then
secret_put "$PASSPHRASE_SECRET" "$SIGNING_PASSPHRASE"
info "Stored signing passphrase in secret '${PASSPHRASE_SECRET}'."
fi
Comment thread deploy/gcp/02-secrets.sh
Comment on lines +59 to +62
if [[ -n "${SMTP_PASSWORD:-}" ]]; then
secret_put "$SMTP_PASSWORD_SECRET" "$SMTP_PASSWORD"
info "Stored SMTP password in secret '${SMTP_PASSWORD_SECRET}'."
fi
Comment thread deploy/gcp/04-deploy.sh
Comment on lines +13 to +21
# ─── Environment variables ───────────────────────────────────────────────────
# Joined with '|' because some values (email addresses) contain commas/@; '|'
# never appears in our values, so it's a safe gcloud delimiter.

env_kv=(
"NEXT_PUBLIC_UPLOAD_TRANSPORT=${UPLOAD_TRANSPORT}"
"NEXT_PRIVATE_SIGNING_TRANSPORT=local"
"NEXT_PRIVATE_SIGNING_LOCAL_FILE_PATH=/opt/documenso/cert.p12"
)
Comment thread deploy/gcp/common.sh
Comment on lines +41 to +42
: "${SMTP_FROM_NAME:=KeepContracts}"
: "${SIGNING_CERT_CN:=Documenso Self-Signed}"
Comment on lines +31 to +34
# Optional: deploy under a dedicated runtime service account instead of the
# default Compute Engine SA. Leave unset to use the default.
# export RUNTIME_SA="documenso-run@PROJECT_ID.iam.gserviceaccount.com"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants