Skip to content

Deploy PR previews to Cloud Run, like seating and sections - #23

Open
pancakereport wants to merge 3 commits into
mainfrom
pr-previews
Open

pancakereport wants to merge 3 commits into
mainfrom
pr-previews

Conversation

@pancakereport

@pancakereport pancakereport commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Deploys each pull request as a preview on the staging project, the way seating and sections do, and gets the image ready for Cloud Run.

Changes

  • Dockerfile
    • Builds the frontend with flask build in a build stage that has Node. In production the app serves oh_queue/static/public/common.js and style.css as they are, and they aren't committed, so the old image had no JavaScript.
    • Runs one gunicorn worker with 8 threads as a non-root user, like seating and sections.
    • Adds a health check at /health.
    • Only runs migrations when RUN_MIGRATIONS=true. entrypoint.sh ran them on every start, which would have let a preview migrate the shared staging database.
  • Database: connects to Cloud SQL as the service account the app runs as (IAM database auth through the Cloud SQL connector: CLOUD_SQL_INSTANCE, DB_USER, DB_NAME), like sections, so no database password is stored. DATABASE_URL still works locally and in CI. Alembic now uses the app's engine so migrations connect the same way, and takes an advisory lock so instances starting together don't migrate at once.
  • Schema check (oh_queue/schema_check.py, from sections): while the database's migration doesn't match the code's, pages, API calls and /health return 503 with an explanation. On a preview whose PR adds a migration, it says to merge the PR. On a preview behind staging, it says to merge main. See docs/migrations.md. The course page reloads on a 503 from its API, as it already did on 403 and 404, so an open page shows the explanation too.
  • .github/workflows/pr-staging.yml: seating's hardened version (pinned actions, per-job permissions, no previews for fork or Dependabot PRs) with sections' concurrency group. Runs as oh-app with the oh-* secrets, and builds as oh-build.
  • Removes entrypoint.sh and the unused Heroku .buildpacks.

Before previews work

Testing

  • pytest (112 passed, including new tests for the schema check, /health and the Cloud SQL settings) and flake8.
  • Built the image locally and ran it with ENV=prod. Before migrations, /health returned 503 with the preview message. After flask initdb, /health, the landing page and /static/public/common.js returned 200. Gunicorn ran as PID 1 under the app user, and Docker reported the container healthy.

🤖 Generated with Claude Code

- Dockerfile: build the frontend with `flask build` (production serves
  oh_queue/static/public as it is, and it isn't committed), run one non-root
  gunicorn worker with threads, add a /health check, and only migrate with
  RUN_MIGRATIONS=true instead of on every start.
- Connect to Cloud SQL as the service account the app runs as (IAM database
  auth, CLOUD_SQL_INSTANCE/DB_USER/DB_NAME), so no database password is
  stored; Alembic uses the app's engine and takes an advisory lock.
- Refuse requests with an explanation while the database doesn't match the
  migrations, as on a preview whose PR adds a migration (from sections).
- PR preview workflow, from seating's and sections'.
- Remove entrypoint.sh and the unused Heroku buildpacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from offerings to main November 21, 2026 00:38
pancakereport and others added 2 commits November 20, 2026 16:57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default compute service account has Editor on the project, so letting
the deployer act as it would give every PR branch Editor on staging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.19608% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.41%. Comparing base (27aafc2) to head (e311313).

Files with missing lines Patch % Lines
oh_queue/schema_check.py 90.19% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #23      +/-   ##
==========================================
+ Coverage   72.66%   73.41%   +0.74%     
==========================================
  Files          10       11       +1     
  Lines        1394     1452      +58     
  Branches      198      207       +9     
==========================================
+ Hits         1013     1066      +53     
- Misses        323      327       +4     
- Partials       58       59       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

🚀 Staging Preview Deployed!

URL: https://preview-oh-pr-23-137456085712.us-west1.run.app

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.

2 participants