-
Notifications
You must be signed in to change notification settings - Fork 27
Implement Preview Deployments #4101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…enhance redis configuration to optionally take two different urls - Added additional headers in the API proxy to handle scheme-related warnings on Fly.io. - Updated Nginx configuration to use incoming X-Forwarded-Proto and clear conflicting headers. - Modified Django settings to allow optional Redis cache and message queue URLs for better flexibility.
…nvironments - Introduced `fly.preview.toml` for configuring Fly.io deployments specific to Metaculus preview environments. - Created a GitHub Actions workflow (`pr_preview.yml`) to automate the setup of ephemeral preview environments for pull requests, including Docker image builds, database creation, and resource cleanup. - Updated Django settings to allow dynamic addition of allowed hosts for preview deployments.
📝 WalkthroughWalkthroughAdds a GitHub Actions PR preview workflow and Fly preview config to create ephemeral preview environments; provisions NeonDB branches and Fly Redis, builds/pushes Docker images, deploys to Fly.io, posts PR comments, and cleans up on close. Also adds Redis overrides, ALLOWED_HOSTS support, and scheme-related nginx/proxy/header adjustments. Changes
Sequence DiagramsequenceDiagram
participant PR as Pull Request
participant GHA as GitHub Actions
participant GHCR as GitHub Container Registry
participant Neon as NeonDB
participant Fly as Fly.io
participant Redis as Fly Redis
participant App as Preview App
participant Bot as PR Comment Bot
PR->>GHA: PR opened/updated
GHA->>GHA: check fork, generate preview IDs
alt fork PR
GHA->>Bot: post guidance comment
else internal PR
GHA->>GHCR: build & push Docker image
GHCR-->>GHA: image tags
par provision DB and cache
GHA->>Neon: create DB branch
Neon-->>GHA: DB connection info
and
GHA->>Redis: provision Redis
Redis-->>GHA: Redis URL
end
GHA->>Fly: deploy app with image & env
Fly->>App: start with DB/Redis
App-->>Fly: ready
Fly-->>GHA: preview URL
GHA->>Bot: post/update PR comment with preview details
end
PR->>GHA: PR closed
GHA->>Fly: delete app
GHA->>Neon: delete DB branch
GHA->>Redis: delete Redis
GHA->>Bot: update comment (cleaned)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
🧹 Preview Environment Cleaned UpThe preview environment for this PR has been destroyed.
Cleanup triggered by PR close at 2026-01-20T11:38:02Z |
elisescu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…od builds. - Changed the method of generating the Docker image tag and tag SHA to use the slug URL output from the slugify step. - Updated the image name output to include the new slug URL format for better traceability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @.github/workflows/pr_preview.yml:
- Around line 305-319: The backend settings are reading the typo'd environment
variable SENTRY_DNS—update metaculus_web/settings.py to read SENTRY_DSN (e.g.,
change any os.environ.get("SENTRY_DNS") / config lookup to
os.environ.get("SENTRY_DSN") or equivalent) and then update the workflow snippet
to export SENTRY_DSN instead of SENTRY_DNS so the backend and workflow use the
standard Sentry DSN name; leave PUBLIC_FRONTEND_SENTRY_DSN unchanged.
- Around line 138-159: The generated Fly resource names (PREVIEW_ID used for
fly_app and redis_name) may exceed Fly's 63-char limit or contain trailing
hyphens; sanitize and shorten PREVIEW_ID derived from
steps.slugify.outputs.slug-url by enforcing lowercase, removing/normalizing
invalid chars (allow only a-z0-9 and hyphen), trimming the overall name to
ensure fly_app and redis_name <=63 chars (accounting for their prefixes
"metaculus-" and "mtc-redis-"), and ensure redis_name ends with an alphanumeric
character (trim trailing hyphens or append a digit if needed); update the
name-generation block around PREVIEW_ID, fly_app, and redis_name to perform
these checks/truncation before writing to GITHUB_OUTPUT.
🧹 Nitpick comments (1)
.github/workflows/pr_preview.yml (1)
245-278: Useflyctl redis status --jsonfor stable URL parsing.The current grep/awk parsing of "Private URL" is brittle and will break if the CLI output format changes. Instead, use
flyctl redis status <name> --jsonwhich outputs GraphQL API response as JSON, then parse the private URL field withjq. This is more maintainable and resilient to CLI updates.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/pr_preview.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Docker Image
- GitHub Check: Backend Checks
- GitHub Check: Frontend Checks
- GitHub Check: integration-tests
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
.github/workflows/pr_preview.yml (4)
71-113: Fork PR guardrails look good.Clear skip path + user-facing guidance keeps secrets safe for forked PRs.
167-212: Docker build/push flow is solid.Tags, metadata, and cache usage look well-structured for PR previews.
339-395: PR comment content is clear and helpful.Nice summary + details section for discoverability.
399-475: Cleanup flow is thorough.Resource teardown + PR comment update covers the full lifecycle well.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
Summary
Add ephemeral preview environments for pull requests that spin up on PR open and automatically clean up on PR close.
Features
closes #4093
Summary by CodeRabbit
New Features
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.