ADR-001: Preview Environments via Railway Native PR Environments
ADR-001: Preview Environments via Railway Native PR Environments
Status
Accepted
Context
We need preview deployments for pull requests so reviewers can test changes before merging. As an open-source project, we also need to handle PRs from external contributors (forks) safely.
Options Considered
- Custom GitHub Actions workflow - Build our own preview deployment workflow using Railway CLI
- Railway's native PR environments - Use Railway's built-in GitHub integration
Key Constraints
- Fork security: GitHub Actions workflows triggered by fork PRs cannot access repository secrets (by design). This makes custom workflows problematic for OSS.
- Code review before deploy: We don't want arbitrary code from unknown contributors deployed automatically.
- Simplicity: Less custom infrastructure means less maintenance burden.
Decision
Use Railway's native PR environments feature.
How It Works
- Enable in Railway Dashboard: Project Settings → Environments → Enable PR Environments
- Connect GitHub repo: Railway's GitHub App handles authentication
- Automatic for team members: PRs from team members get auto-deployed
- Gated for external contributors: PRs from forks are NOT auto-deployed (security feature)
For External Contributors
Railway only deploys PRs from users who are team members or invited to the project. This is intentional - it prevents:
- Arbitrary code execution from untrusted sources
- Secret/environment variable exposure
- Resource abuse
Workflow for external contributor PRs:
- Contributor opens PR from fork
- CI runs (tests, lint, build) via GitHub Actions
- Maintainer reviews code
- To preview: maintainer can either
- Temporarily invite contributor to Railway project
- Checkout branch locally and deploy manually
- Merge to a preview branch that triggers deployment
- Once approved, merge to main
This "review before deploy" pattern is the standard for OSS projects and is more secure than auto-deploying fork code.
Consequences
Positive
- Zero custom workflow maintenance
- Built-in security model for fork PRs
- Automatic cleanup when PRs close
- Railway handles domain provisioning
- Works with Railway's existing GitHub integration
Negative
- Less flexibility than custom workflow
- External contributor previews require manual intervention
- Dependent on Railway's feature set
Neutral
- Team members must have Railway project access for auto-deploys
- PR environment URLs follow Railway's naming convention
Setup Instructions
1. Add a Railway domain to the production service
PR environments only get auto-provisioned domains if the base (production) environment has a Railway-provided domain.
- Go to Railway Dashboard → Toast project
- Select the
apiservice in the production environment - Go to Settings → Networking → Public Networking
- Click "Generate Domain" to get a
*.up.railway.appdomain
2. Enable PR Environments
- Go to Project Settings → Environments tab
- Toggle "Enable PR Environments"
- Optionally toggle "Enable Bot PR Environments" for Dependabot/Renovate
3. Verify GitHub Integration
Railway creates GitHub Deployments for each deploy. The deployment URL will appear in:
- PR sidebar: "Deployments" section shows environment with "View deployment" link
- Commit status: Checkmark links to Railway dashboard
- GitHub Deployments API:
environment_urlfield contains the live URL
No PR comment is posted, but the URL is accessible via the GitHub Deployments UI.