Zero-downtime deployments, automatic ports, and 30-second drains
Inside Neatploy's deployment state machine: readiness checks, port detection, Caddy upstream swaps, and snapshot rollbacks.
A deployment should never drop live user requests just because a container restarted, and a broken deploy should never take down a working production route.
Here is how the Neatploy control plane (neatploy-api) and node agent (neatploy-agent) coordinate every release.
1. Immutable builds and encrypted variable snapshots
Every deployment passes through an explicit state machine: queued → building → deploying → active (or failed / crashed / superseded).
When a deployment begins, the API snapshots the service’s variables encrypted under NEATPLOY_MASTER_KEY using AES-256-GCM. Secret variables are mounted exclusively via BuildKit --mount=type=secret,id=NAME during Docker builds so credentials never persist in OCI image layers.
2. Automatic port detection and health checks
Until a service pins an explicit PORT, Neatploy inspects single EXPOSE directives on built images and checks common listening ports as new replicas start. Each placed replica binds its own port so a new deployment never collides with its predecessor on the same node.
Readiness waits for either an HTTP 200 on healthcheck_path or a TCP accept (with a default 120-second timeout). If a replica fails health checks, the deployment fails immediately—the old deployment continues serving traffic untouched.
3. Edge swap, 30s drain, and crash backoff
Once every new replica passes readiness:
- The agent updates Caddy upstreams to point to the new replicas.
- Old app containers keep serving in-flight connections for a 30-second drain window before receiving
SIGTERM(managed databases receiveSIGINTor engine-specific signals with a 60-second clean stop). - Neatploy keeps the 3 most recent images per service and environment (plus the active image if older), so rolling back restores both the previous image and its exact variables snapshot.
If a healthy container later crashes, Docker restarts it up to 5 times locally before the scheduler takes over with exponential backoff from 10 seconds to 5 minutes.