Deployment Architecture
How forms-lab is deployed and served.
Overview
A single EC2 instance hosts all branch deployments. GitHub push webhooks trigger automated deploys. NixOS declaratively manages the server state — Caddy reverse proxy, per-branch application processes, and the webhook listener. Pulumi provisions the AWS resources.
How It Works
- Push to GitHub — A developer pushes to any branch.
- Webhook fires — GitHub sends a push event to the webhook listener on EC2.
- Deploy script runs — The listener validates the signature, creates a GitHub Deployment (status:
in_progress), and spawns the deploy script. - Build and serve — The script creates/updates a git worktree, runs
bun install && bun run build, starts/restarts the systemd service, and updates Caddy routing. - Status updated — On success, the deployment status is set to
successwith a link to the branch URL. On failure, it is set tofailure. PRs show a “View deployment” link in the sidebar. - Traffic routes — Caddy proxies
/<branch>/to the branch’s Bun process on its assigned port. - Branch deleted — When a branch is deleted, the webhook marks its deployment as
inactive.
Components
| Component | Location | Role |
|---|---|---|
| Pulumi project | infrastructure/pulumi/ |
Provisions EC2, EIP, security group, DNS, SES email identity |
| NixOS config | infrastructure/nixos/ |
Declares entire server state |
| Webhook listener | src/webhook/ |
Receives GitHub push events |
| Deploy script | infrastructure/nixos/modules/deploy.nix |
Builds and deploys branches |
| Caddy | NixOS service | Reverse proxy, auto-HTTPS, routing |
| App services | systemd template units | Per-branch Bun processes |
URL Scheme
Each branch is served at a subpath on the EC2 hostname:
https://<hostname>/main/— main branchhttps://<hostname>/slice-1/— slice-1 branch
The app reads BASE_PATH to generate correct links and asset URLs.
Operations
All operations are available through the CLI:
bun run cli infra up # Provision/update infrastructure
bun run cli nixos apply # Push NixOS changes to server
bun run cli nixos status # Check running services
bun run cli webhook setup # GitHub webhook configuration
Outbound email
The main deployment emails users when an admin approves their access
request (src/services/email/, Amazon SES). Branch deployments never send
mail: deploy.nix writes EMAIL_FROM into .env only for main, and
without it the app logs instead of sending.
Pulumi provisions, when domain is configured: an SES domain identity,
the three Easy DKIM CNAME records in the hosted zone, and an instance-role
policy allowing ses:SendEmail on that identity only.
Manual steps (not automated):
- Check DKIM verification. After
bun run cli infra up, confirm the records resolve and SES sees them:
Expectdig +short CNAME <token>._domainkey.<domain> # tokens: aws sesv2 get-email-identity --email-identity <domain> aws sesv2 get-email-identity --email-identity <domain> \ --query '{dkim: DkimAttributes.Status, sending: VerifiedForSendingStatus}'dkim: SUCCESSandsending: true. This can take up to 72 hours after the records first resolve, and requires the domain’s NS delegation to point at the Pulumi hosted zone (nameServersoutput). - Leave the SES sandbox. New AWS accounts start in the SES sandbox,
where mail is delivered only to verified addresses and sends from the
app to anyone else fail (the admin page shows the error). Request
production access in the SES console (Account dashboard → Request
production access) for the region in
AWS_REGION. Until AWS grants it, treat approval emails as best-effort; check the account status withaws sesv2 get-account --query ProductionAccessEnabled.
Sources
- EC2 with Pulumi
- Caddy reverse proxy
- GitHub webhook deploys
- Subpath routing
- Nix-built processes
- Canonical code:
src/services/email/,infrastructure/pulumi/,infrastructure/nixos/,src/webhook/
A digital services project by Flexion