Skip to content

190 add a staging environment for previewing and testing ahead of a new deployment - #201

Merged
lmcdonough merged 24 commits into
mainfrom
190-add-a-staging-environment-for-previewing-and-testing-ahead-of-a-new-deployment
Feb 27, 2026
Merged

190 add a staging environment for previewing and testing ahead of a new deployment#201
lmcdonough merged 24 commits into
mainfrom
190-add-a-staging-environment-for-previewing-and-testing-ahead-of-a-new-deployment

Conversation

@lmcdonough

Copy link
Copy Markdown
Collaborator

🚀 Add Automated PR Preview Deployments

Implements isolated staging environments for every pull request.

What This Does

  • Auto-deploys backend on PR open/update to RPi5 via Tailscale
  • Isolated per PR: Separate containers, networks, volumes, ports
  • Bot comments on PR with clickable URLs and testing instructions
  • Auto-cleanup when PR closes/merges

Architecture

  • Backend port: 4000 + PR_NUMBER
  • Postgres port: 5432 + PR_NUMBER
  • Docker namespace: pr-{number} (complete isolation)
  • Images tagged: ghcr.io/owner/repo:pr-{number}

Files Added

  • .github/workflows/deploy-pr-preview.yml - Deployment automation
  • .github/workflows/cleanup-pr-preview.yml - Cleanup automation
  • docker-compose.pr-preview.yaml - Multi-tenant template
  • docs/PR-PREVIEW.md - Usage documentation

Access

  1. Connect to Tailscale
  2. Check PR comment for URLs
  3. Test your changes in isolation

This comment was marked as outdated.

lmcdonough and others added 13 commits February 20, 2026 09:33
Use AllowOrigin::mirror_request() when ALLOWED_ORIGINS contains "*"
to support credentials with wildcard origins. The browser rejects
Access-Control-Allow-Origin: * when credentials are included, so
we mirror the request's Origin header instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- docs/cicd/README.md: CI/CD pipeline overview and architecture
- docs/cicd/pr-preview-environments.md: PR preview system documentation
- docs/cicd/future-improvements.md: planned enhancements
- docs/cicd/gap-analysis.md: current vs desired state analysis
- Reorganize runbooks into docs/cicd/ (docker-quickstart, production-deployment)
- README.md: add CI/CD documentation section
- .gitignore: add new ignore rules
- .vscode/settings.json: remove from tracking (already in .gitignore)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document reusable workflow architecture, Docker Compose PR preview
stack, nginx path-based routing, CORS wildcard handling, entrypoint
schema flow, and secrets resolution order with stale secret warning.
…iews

The pr-preview environment secrets (MailerSend, Tiptap) were empty when
the frontend repo called the reusable workflow because GitHub Actions
resolves environment secrets from the caller repo, not the callee.

- Make welcome email non-fatal in user creation (if-let-Err + warn log)
- Add || 'UNUSED' fallbacks for 6 backend-specific secrets in .env heredoc
- Fix misleading comments about cross-repo environment resolution
- Add dedicated SSE location blocks to both nginx preview configs
- Create deploy-pr-preview-dispatch.yml for correct secret resolution
- Fix frontend checkout steps to use explicit repository parameter
Added 7 missing directories: docs, events, nginx, nginx-preview,
scripts, sse, and testing-tools. Added brief descriptions for each.
Added SESSION_SCHEDULED_EMAIL_TEMPLATE_ID, ACTION_ASSIGNED_EMAIL_TEMPLATE_ID,
and FRONTEND_BASE_URL to the email configuration section.
Addresses review comment by jhodapp on docker-compose.pr-preview.yaml:84
Addresses review comment by jhodapp on build-test-push.yml:47
Addresses review comment by jhodapp on build-test-push.yml:51
Addresses review comment by jhodapp on ci-deploy-pr-preview.yml:955
Addresses review comment by jhodapp on web/src/lib.rs:137
Addresses review comment by jhodapp on ci-deploy-pr-preview.yml:791
Addresses review comment by jhodapp on ci-deploy-pr-preview.yml:867
@lmcdonough

Copy link
Copy Markdown
Collaborator Author

Already addressed.

- Add EXIT trap for secrets env file cleanup on deploy failure
  (ci-deploy-pr-preview.yml). Without this, set -eo pipefail exits
  would leave DB passwords, GHCR PAT, and API keys on disk.

- Use StrictHostKeyChecking=yes in cleanup workflow to match deploy
  workflow (cleanup-pr-preview.yml). Fixes inconsistency where deploy
  used strict checking but cleanup used accept-new.

- Make PR preview lint gates match main CI: add -D warnings to clippy,
  remove continue-on-error from fmt (ci-deploy-pr-preview.yml).

- Fix clippy warnings: allow too_many_arguments on
  send_action_assigned_email, remove needless borrow in test code.

- Apply cargo fmt to all files.
Backend PRs were reusing the main-arm64 frontend image which has
basePath="" baked in. Next.js basePath is a build-time config, so
PR previews needing basePath="/pr-<NUM>" for sub-path routing got
404s on all _next/static/* assets. Now frontend is always built
with the correct NEXT_PUBLIC_BASE_PATH regardless of repo_type.

Also adds branch fallback logic to checkout steps: if a specified
branch has been deleted (e.g. after merge), checkout falls back to
main for zero-downtime transitions.
Override images (backend_image/frontend_image inputs) previously set
build_mode='skip' unconditionally. If the override pointed to a
deleted or nonexistent image, the workflow failed at docker pull
with no fallback. Now validates overrides with docker manifest
inspect — if missing, falls back to building from source.
Frontend main branch lacks basePath support (NEXT_PUBLIC_BASE_PATH
in Dockerfile and next.config.mjs), causing _next/static/ asset 404s
in backend PR preview environments. Point to frontend feature branch
225 until PR #226 merges to main.
@jhodapp

This comment was marked as resolved.

calebbourg

This comment was marked as resolved.

jhodapp and others added 3 commits February 23, 2026 13:28
Resolve merge conflicts in domain/src/emails.rs and
web/src/controller/organization/user_controller.rs by taking
main's refactored email patterns (ResolvedEmailConfig, private
send functions, internal error handling).
Removes the "Access Requirements" section that mentioned Tailscale
from the automated PR comment template to avoid revealing internal
network infrastructure details.

Addresses review comment by jhodapp on PR #201
@lmcdonough

Copy link
Copy Markdown
Collaborator Author

Removed the Access Requirements section from the PR comment template.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 PR Preview Environment Deployed!

🔗 Access URLs

Service URL
Frontend http://neo/pr-201/
Backend API http://neo/pr-201/api
Health Check http://neo/pr-201/health
Base Path /pr-201/

📊 Environment Details

🧪 Testing

# Health check
curl http://neo/pr-201/health

# Frontend
curl http://neo/pr-201/

# API test
curl http://neo/pr-201/api/v1/users

🧹 Cleanup

Environment auto-cleaned when PR closes/merges


Deployed: 2026-02-24T22:20:00.551Z
Architecture: Native ARM64 build on Neo + Multi-tier caching

@jhodapp

jhodapp commented Feb 25, 2026

Copy link
Copy Markdown
Member

@lmcdonough approved from both Caleb and me. Before merging, you've got one merge conflict to take care of which Claude should be able to help you with if it's at all confusing.

Resolve conflict in web/src/lib.rs keeping wildcard CORS logic
for PR preview environments while incorporating main's changes.
Use PR_PREVIEW_FRONTEND_BRANCH repo variable instead of hardcoding the
frontend feature branch name. Falls back to 'main' when the variable is
unset or empty, eliminating post-merge code changes.
@github-actions

Copy link
Copy Markdown
Contributor

🧹 PR Preview Environment Cleaned Up!

📊 Cleanup Summary

Resource Status
Containers ✅ Stopped and removed
PR-Specific Images (RPi5) ✅ Removed
Database Volume (RPi5) ✅ Removed
Network ✅ Removed
Compose File ✅ Deleted
Environment File ✅ Deleted
main-arm64 Image ❌ Build failed
PR Image (GHCR) ⚠️ Deletion skipped or failed

📝 Details

💡 Layer Caching Strategy

  • main-arm64 image now available for faster PR builds
  • Future PR builds will use main-arm64 layers as cache
  • Reduces build times and GHCR image accumulation
  • Single source of truth: main-arm64 image

Cleaned up: 2026-02-27T17:14:01.811Z
Workflow: cleanup-pr-preview.yml

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

Labels

feature work Specifically implementing a new feature infrastructure DevOps related

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Add a staging environment for previewing and testing ahead of a new deployment

4 participants