Skip to content

Deploy: add Google Cloud deployment (Compute Engine VM and Cloud Run) - #32

Merged
mfarim merged 2 commits into
mainfrom
feat/gcp-deploy
Nov 27, 2026
Merged

mfarim merged 2 commits into
mainfrom
feat/gcp-deploy

Conversation

@mfarim

@mfarim mfarim commented Nov 27, 2026

Copy link
Copy Markdown
Owner

What

Two optional ways to run the app on Google Cloud. The existing VPS setup (docker-compose.prod.yml, deploy.sh) is unchanged and does not read any of these files.

Depends on the exam-result outbox PR, which adds the Pub/Sub publisher and BACKEND_UPSTREAM.

Contents

  • deploy/gcp/: one Compute Engine VM running docker-compose.gcp.yml.
    • PostgreSQL on Cloud SQL via the Auth Proxy; uploads in Cloud Storage (S3 API + HMAC key).
    • Images from Artifact Registry, logs in Cloud Logging, TLS via certbot.
    • Numbered gcloud scripts: foundation, Cloud SQL, VM, functions, teardown.
    • Secrets are generated into Secret Manager and rendered into the VM's .env. Nothing secret is stored in the repo.
  • deploy/cloudrun/: Terraform for a Cloud Run service (frontend + backend containers), Cloud SQL, Memorystore and Secret Manager.
  • functions/: Cloud Run functions.
    • exam-result-mailer: e-mails students from exam.result_ready events, deduplicated by event id.
    • sql-export: scheduled Cloud SQL export to Cloud Storage.
    • upload-inspector: checks uploaded files against their declared type.
  • .gitignore: Terraform state and tfvars, which hold secrets and project ids.

Testing

  • node --test in each function: 16 tests, 0 failures.
  • bash -n on every deploy script; docker compose -f docker-compose.gcp.yml config passes.
  • Not yet run in this PR: terraform validate for deploy/cloudrun, and a real run of the scripts against a GCP project.

When an attempt's result becomes final (fully auto-graded on submit, or when the
last essay is graded), an "exam.result_ready" event is written to outbox_events
in the same transaction as the grade. OutboxRelay publishes pending rows in the
background so the student can be e-mailed.

- Off by default (APP_NOTIFY_EXAM_RESULTS=false): no outbox beans, no relay,
  resultReady() is a no-op. Existing deployments behave as before.
- Publishers: "log" (local development, default) or "pubsub" (Google Cloud
  Pub/Sub over REST, authenticated with the VM's service account through the
  metadata server; no key file).
- One event per attempt (unique event_type + aggregate_id); later re-grades do
  not send it again. Rows are locked with SKIP LOCKED so several instances can
  run the relay. Failed publishes are retried up to app.outbox.max-attempts.
- The score is only included when the exam shows results to students.
- V5 migration adds the outbox_events table.

Frontend: the backend address Nginx proxies /api and /ws to is now
BACKEND_UPSTREAM (default backend:8080, unchanged for Docker Compose), so the
same image also works on Cloud Run where both containers share localhost.
…d Run)

Two optional ways to run the app on Google Cloud. The existing VPS setup
(docker-compose.prod.yml, deploy.sh) is unchanged and does not read any of it.

- deploy/gcp: one Compute Engine VM running docker-compose.gcp.yml, with
  PostgreSQL on Cloud SQL (Auth Proxy), uploads in Cloud Storage (S3 API + HMAC
  key), images from Artifact Registry, logs in Cloud Logging, TLS via certbot.
  Numbered gcloud scripts (foundation, Cloud SQL, VM, functions, teardown);
  secrets are generated into Secret Manager and rendered into the VM's .env.
- deploy/cloudrun: Terraform for a Cloud Run service (frontend + backend
  containers), Cloud SQL, Memorystore and Secret Manager.
- functions/: Cloud Run functions
  - exam-result-mailer: e-mails students from the exam.result_ready Pub/Sub
    events (deduplicated by event id)
  - sql-export: scheduled Cloud SQL export to Cloud Storage
  - upload-inspector: checks uploaded files against their declared type
- .gitignore: Terraform state and tfvars (they hold secrets and project ids).
@mfarim mfarim self-assigned this Nov 27, 2026
@mfarim mfarim added the enhancement New feature or request label Nov 27, 2026
@mfarim
mfarim merged commit 2dd7129 into main Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant