|
| 1 | +# ADR 001: Use Kamal for Production Deployment |
| 2 | + |
| 3 | +## Status |
| 4 | + |
| 5 | +Accepted |
| 6 | + |
| 7 | +## Date |
| 8 | + |
| 9 | +2026-01-01 |
| 10 | + |
| 11 | +## Context |
| 12 | + |
| 13 | +The production site has been down since PlanetScale (MySQL) shutdown. We need to |
| 14 | +deploy the application with the migrated SQLite database. The original plan was |
| 15 | +to use a traditional VPS deployment with PM2 + nginx (documented in |
| 16 | +`docs/vps-deployment.md`). |
| 17 | + |
| 18 | +However, we have additional requirements: |
| 19 | + |
| 20 | +1. **Multi-app hosting**: Want to host multiple applications on the same VPS |
| 21 | +2. **High availability**: Future-proof for HA setup with multiple servers |
| 22 | +3. **Consistent environments**: Avoid "works on my machine" issues |
| 23 | +4. **Zero-downtime deployments**: Rolling deploys without manual intervention |
| 24 | + |
| 25 | +## Decision |
| 26 | + |
| 27 | +Use **Kamal** (formerly MRSK) for deployment instead of bare PM2 + nginx. |
| 28 | + |
| 29 | +Kamal is a Docker-based deployment tool by 37signals (Basecamp/Hey.com) that: |
| 30 | + |
| 31 | +- Orchestrates Docker containers across servers |
| 32 | +- Manages Traefik as reverse proxy with automatic SSL |
| 33 | +- Provides zero-downtime rolling deployments |
| 34 | +- Supports multi-app hosting natively |
| 35 | +- Makes HA setup straightforward (just add more servers) |
| 36 | + |
| 37 | +## Alternatives Considered |
| 38 | + |
| 39 | +### 1. PM2 + nginx (Original Plan) |
| 40 | + |
| 41 | +**Pros:** |
| 42 | + |
| 43 | +- Simple, well-understood |
| 44 | +- Lower resource overhead (no Docker) |
| 45 | +- Documented in `docs/vps-deployment.md` |
| 46 | + |
| 47 | +**Cons:** |
| 48 | + |
| 49 | +- Manual nginx configuration per app |
| 50 | +- Complex HA setup |
| 51 | +- Environment drift between dev and prod |
| 52 | +- Manual SSL certificate management |
| 53 | + |
| 54 | +### 2. Docker Compose |
| 55 | + |
| 56 | +**Pros:** |
| 57 | + |
| 58 | +- Container consistency |
| 59 | +- Simple for single-server setups |
| 60 | + |
| 61 | +**Cons:** |
| 62 | + |
| 63 | +- No built-in deployment orchestration |
| 64 | +- Manual SSL setup |
| 65 | +- Limited multi-server support |
| 66 | + |
| 67 | +### 3. Kubernetes |
| 68 | + |
| 69 | +**Pros:** |
| 70 | + |
| 71 | +- Industry standard for container orchestration |
| 72 | +- Excellent HA and scaling |
| 73 | + |
| 74 | +**Cons:** |
| 75 | + |
| 76 | +- Massive overkill for this project size |
| 77 | +- Significant operational complexity |
| 78 | +- Higher resource requirements |
| 79 | + |
| 80 | +## Consequences |
| 81 | + |
| 82 | +### Positive |
| 83 | + |
| 84 | +- **Future-proof**: Easy path to HA by adding servers to config |
| 85 | +- **Consistent**: Same Docker image runs everywhere |
| 86 | +- **Simple SSL**: Traefik handles Let's Encrypt automatically |
| 87 | +- **Multi-app ready**: Each app gets its own `config/deploy.yml` |
| 88 | +- **Zero-downtime**: Built-in rolling deployments |
| 89 | + |
| 90 | +### Negative |
| 91 | + |
| 92 | +- **Learning curve**: Need to learn Docker and Kamal basics |
| 93 | +- **Ruby dependency**: Kamal requires Ruby to be installed locally |
| 94 | +- **Resource overhead**: Docker adds ~100-200MB RAM overhead |
| 95 | +- **Build time**: Multi-stage Docker builds take longer than direct deploys |
| 96 | + |
| 97 | +### Neutral |
| 98 | + |
| 99 | +- Obsoletes `docs/vps-deployment.md` (will be deleted) |
| 100 | +- Need to create new documentation for Kamal workflow |
| 101 | + |
| 102 | +## Implementation |
| 103 | + |
| 104 | +1. Create `Dockerfile` with multi-stage build (Node 24) |
| 105 | +2. Create `config/deploy.yml` for Kamal configuration |
| 106 | +3. Set up Traefik for SSL/HTTPS |
| 107 | +4. Use Docker volumes for SQLite persistence |
| 108 | +5. Document in `docs/kamal-deployment.md` |
| 109 | + |
| 110 | +## Future Work |
| 111 | + |
| 112 | +- Add Litestream for SQLite replication (separate epic for HA) |
| 113 | +- Add additional servers for redundancy |
| 114 | +- Set up GitHub Actions for CI/CD with Kamal |
| 115 | + |
| 116 | +## References |
| 117 | + |
| 118 | +- [Kamal Documentation](https://kamal-deploy.org/) |
| 119 | +- [37signals Kamal Announcement](https://world.hey.com/dhh/introducing-kamal-9330a267) |
| 120 | +- [Traefik Documentation](https://doc.traefik.io/traefik/) |
0 commit comments