Elixir/Phoenix Deployment Reference
Quick reference for deploying Elixir/Phoenix applications.
Iron Laws — Never Violate These
- Config at runtime, not compile time — Secrets in
config.exs get baked into the release binary. Use runtime.exs with env vars so secrets are resolved at boot
- Graceful shutdown ≥ 60 seconds — Shorter timeouts kill in-flight requests and WebSocket connections mid-operation, causing data loss for users
- Health checks required — Without startup/liveness/readiness endpoints, orchestrators can't distinguish a booting node from a dead one, leading to cascading restarts
- SSL verification for database — Skipping
verify: :verify_peer allows MITM attacks between your app and database; production data traverses the connection
- No CPU limits — The BEAM scheduler assumes it owns all cores; cgroups CPU limits cause scheduler collapse where the VM thinks it has more cores than it can use, leading to latency spikes
Quick Configuration
runtime.exs (Essential)
if config_env() == :prod do
database_url = System.get_env("DATABASE_URL") || raise "DATABASE_URL is required"
secret_key_base = System.get_env("SECRET_KEY_BASE") || raise "SECRET_KEY_BASE is required"
host = System.get_env("PHX_HOST") || raise "PHX_HOST is required"
config :my_app, MyApp.Repo,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
ssl: true,
ssl_opts: [verify: :verify_peer]
config :my_app, MyAppWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000")],
secret_key_base: secret_key_base,
server: true
end
Health Check Plug
def call(%{path_info: ["health", "readiness"]} = conn, _opts) do
case Ecto.Adapters.SQL.query(MyApp.Repo, "SELECT 1", []) do
{:ok, _} -> send_resp(conn, 200, ~s({"status":"ok"})) |> halt()
{:error, _} -> send_resp(conn, 503, ~s({"status":"error"})) |> halt()
end
end
Quick Decisions
Platform Choice
| Need |
Use |
| Simple, managed |
Fly.io |
| Enterprise, existing K8s |
Kubernetes |
| Custom infrastructure |
Docker + your orchestrator |
Resource Limits
| Resource |
Recommendation |
| CPU |
NO LIMITS (BEAM scheduler issues) |
| Memory |
Set limits (256Mi-512Mi typical) |
| Graceful shutdown |
≥ 60 seconds |
Deployment Checklist
Asset Pipeline Notes
Phoenix 1.8 uses esbuild + tailwind (no Node.js required):
- Config in
config/config.exs under :esbuild and :tailwind
mix assets.deploy builds for production
mix assets.setup installs binaries on first run
- Custom JS bundlers: configure in
config/config.exs
References
For detailed patterns, see:
${CLAUDE_SKILL_DIR}/references/docker-config.md - Multi-stage Dockerfile, best practices
${CLAUDE_SKILL_DIR}/references/flyio-config.md - fly.toml, clustering, commands
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: deploy-313description: Elixir/Phoenix deployment patterns — Dockerfile, fly.toml, runtime.exs, mix release, rel/ overlays. Use when configuring Fly.io, Docker, CI/CD, health checks, or production migrations. Use when this capability is needed.4---56# Elixir/Phoenix Deployment Reference78Quick reference for deploying Elixir/Phoenix applications.910## Iron Laws — Never Violate These11121. **Config at runtime, not compile time** — Secrets in `config.exs` get baked into the release binary. Use `runtime.exs` with env vars so secrets are resolved at boot132. **Graceful shutdown ≥ 60 seconds** — Shorter timeouts kill in-flight requests and WebSocket connections mid-operation, causing data loss for users143. **Health checks required** — Without startup/liveness/readiness endpoints, orchestrators can't distinguish a booting node from a dead one, leading to cascading restarts154. **SSL verification for database** — Skipping `verify: :verify_peer` allows MITM attacks between your app and database; production data traverses the connection165. **No CPU limits** — The BEAM scheduler assumes it owns all cores; cgroups CPU limits cause scheduler collapse where the VM thinks it has more cores than it can use, leading to latency spikes1718## Quick Configuration1920### runtime.exs (Essential)2122```elixir23if config_env() == :prod do24 database_url = System.get_env("DATABASE_URL") || raise "DATABASE_URL is required"25 secret_key_base = System.get_env("SECRET_KEY_BASE") || raise "SECRET_KEY_BASE is required"26 host = System.get_env("PHX_HOST") || raise "PHX_HOST is required"2728 config :my_app, MyApp.Repo,29 url: database_url,30 pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),31 ssl: true,32 ssl_opts: [verify: :verify_peer]3334 config :my_app, MyAppWeb.Endpoint,35 url: [host: host, port: 443, scheme: "https"],36 http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000")],37 secret_key_base: secret_key_base,38 server: true39end40```4142### Health Check Plug4344```elixir45def call(%{path_info: ["health", "readiness"]} = conn, _opts) do46 case Ecto.Adapters.SQL.query(MyApp.Repo, "SELECT 1", []) do47 {:ok, _} -> send_resp(conn, 200, ~s({"status":"ok"})) |> halt()48 {:error, _} -> send_resp(conn, 503, ~s({"status":"error"})) |> halt()49 end50end51```5253## Quick Decisions5455### Platform Choice5657| Need | Use |58|------|-----|59| Simple, managed | Fly.io |60| Enterprise, existing K8s | Kubernetes |61| Custom infrastructure | Docker + your orchestrator |6263### Resource Limits6465| Resource | Recommendation |66|----------|----------------|67| CPU | **NO LIMITS** (BEAM scheduler issues) |68| Memory | Set limits (256Mi-512Mi typical) |69| Graceful shutdown | ≥ 60 seconds |7071## Deployment Checklist7273- [ ] All secrets from environment variables in runtime.exs74- [ ] `server: true` in endpoint config75- [ ] SSL verification for database connections76- [ ] Health endpoints: /health/startup, /health/liveness, /health/readiness77- [ ] Graceful shutdown period ≥ 60 seconds78- [ ] No CPU limits (memory limits only)79- [ ] Migrations in deploy process8081## Asset Pipeline Notes8283Phoenix 1.8 uses esbuild + tailwind (no Node.js required):8485- Config in `config/config.exs` under `:esbuild` and `:tailwind`86- `mix assets.deploy` builds for production87- `mix assets.setup` installs binaries on first run88- Custom JS bundlers: configure in `config/config.exs`8990## References9192For detailed patterns, see:9394- `${CLAUDE_SKILL_DIR}/references/docker-config.md` - Multi-stage Dockerfile, best practices95- `${CLAUDE_SKILL_DIR}/references/flyio-config.md` - fly.toml, clustering, commands9697---98> Converted and distributed by [TomeVault](https://tomevault.io/claim/oliver-kriska) — claim your Tome and manage your conversions.99<!-- tomevault:4.0:skill_md:2026-04-11 -->