Tooling & production/Deployment & Production
Deployment & Production
Building static CGO_ENABLED=0 binaries, shipping assets, graceful shutdown, health probes, migrations, and production config.
On this page
Fletch compiles your application into a static Go binary with CGO_ENABLED=0 and ships with production lifecycle primitives for graceful shutdown, readiness probes, migration locking, and background worker supervision.
Building a Production Binary
Run fletch build to generate code, build frontend assets into public/dist, and compile the Go binary with CGO_ENABLED=0:
fletch build -o dist/myapp --os linux --arch amd64 --ldflags "-s -w"
fletch build runs fletch gen first so generated route, template, and schema files match your source tree before compilation starts.
| Flag | Description |
|---|---|
-o <file> |
Output path for the compiled binary. |
--os <goos> |
Target operating system (GOOS), such as linux or darwin. |
--arch <goarch> |
Target CPU architecture (GOARCH), such as amd64 or arm64. |
--ldflags <flags> |
Linker flags passed through to go build -ldflags. |
--tags <tags> |
Build tags passed through to go build -tags. |
--skip-assets |
Skip building frontend assets into public/dist. |
--json |
Emit build metadata as JSON for CI pipelines. |
Shipping Static Assets
In the default scaffold, bootstrap/assets.go serves compiled assets from public/dist on disk using os.DirFS. When deploying a default app in a container image or release tarball, ship public/dist alongside the compiled binary. Include config/ as well, and include database/migrations/ if you run ./myapp migrate from the same image.
If you prefer a single self-contained binary with no asset files on disk, embed public/dist. A //go:embed pattern cannot reach a parent directory, so the embed has to live in a package at or above public/dist. Add a small package in public/:
// public/embed.go
package public
import "embed"
//go:embed dist
var Dist embed.FS
Then read the manifest from the embedded files and pass both to assets.NewFSResolver in bootstrap/assets.go:
package bootstrap
import (
"io/fs"
"github.com/fletchhq/fletch/assets"
"myapp/public"
)
func assetResolver() assets.Resolver {
dist, err := fs.Sub(public.Dist, "dist")
if err != nil {
return nil
}
m, err := assets.ReadManifest(dist)
if err != nil {
return nil
}
return assets.NewFSResolver(dist, m)
}
//go:embed dist fails to compile when public/dist does not exist, so run fletch build (or fletch assets build) before go build or go test. For a Vite app, keep the scaffold’s assets.Vite(...) call and pass the embedded files with assets.ViteManifest(dist) in place of os.DirFS("public/dist").
Production Config and Secrets
Set FLETCH_ENV=production in your deployment environment. Fletch overlays config/environments/production.yaml on top of your base configuration. In generated apps, production.yaml sets auto_migrate: false and requires APP_URL to be present at boot.
Also set STORAGE_SIGNING_KEY (32 random bytes, hex-encoded, for example from openssl rand -hex 32) when the app uses the default local storage disk. config/storage.yaml falls back to a public development signing secret, and in production the app refuses to boot with set STORAGE_SIGNING_KEY: the development signing secret is public.
export FLETCH_ENV=production
export APP_URL=https://app.example.com
export STORAGE_SIGNING_KEY="$(openssl rand -hex 32)"
Leave FLETCH_DEV unset in production. Dev-only behavior such as the loopback dev dashboard and permissive queue fallbacks stays disabled whenever FLETCH_DEV is not 1.
Supply production secrets using whichever mechanism fits your infrastructure:
- Set
FLETCH_MASTER_KEYin the runtime environment to decrypt your checked-in encrypted credentials file. - Wire the
config/awsprovider to pull parameters from AWS Systems Manager Parameter Store or Secrets Manager. - Inject values directly through OS environment variables, which hold highest precedence in Fletch’s configuration stack.
Running Database Migrations
Generated projects enable auto_migrate: true in config/database.yaml for local development and override it to auto_migrate: false in config/environments/production.yaml. Running migrations inside web startup slows cold boots and couples schema changes to autoscaling events.
Run migrations explicitly as a pre-deploy step or release job using the compiled application binary:
./myapp migrate
./myapp migrate --status
nock/migrate acquires a database advisory or transaction lock before applying pending SQL files, so overlapping deploy jobs or parallel release containers will not apply the same migration twice.
Graceful Shutdown
Start production servers through fletch.Run so the process handles SIGTERM and SIGINT cleanly:
err := fletch.Run(
app,
fletch.WithAddr(":8080"),
fletch.WithDeregisterDelay(5*time.Second),
fletch.WithShutdownGrace(20*time.Second),
)
When the process receives SIGTERM or SIGINT, fletch.Run does the following:
/readyzflips to unhealthy immediately.- The deregister delay (
$FLETCH_DEREGISTER_DELAY, default0) elapses so load balancers stop sending new connections to the instance. - The shutdown grace timer starts and the HTTP server begins shutting down: listeners close and in-flight requests drain.
- At the start of that HTTP shutdown, a callback registered with the server closes active Live connections with WebSocket status
1001(Going Away) and ends streaming responses. This runs alongside request draining, because long-lived WebSocket and SSE connections would otherwise hold the drain open until the grace timeout. - Once the server has stopped, Quiver workers stop claiming new jobs and drain running jobs.
- Registered
OnShutdownhooks run. - Providers with a
Closemethod close.
All of these steps share one grace timeout, $FLETCH_SHUTDOWN_GRACE (default 10s). Requests or jobs still running when it expires are cut off. Keep the combined deregister delay and shutdown grace period below your orchestrator’s hard kill timeout (such as ECS stopTimeout or Kubernetes terminationGracePeriodSeconds) so the process finishes draining before receiving SIGKILL.
Health Probes
Fletch exposes two health endpoints automatically:
/healthzreports process liveness./readyzreports readiness by pinging the configured database and any custom pingers registered viafletch.WithPinger(name, p).
Register additional readiness checks or customize the paths when building your app:
app := fletch.New(
fletch.WithPinger("redis", redisClient),
fletch.WithHealthPaths("/live", "/ready"),
)
To disable the built-in health endpoints completely, pass fletch.WithoutHealthChecks().
Postgres Memory-Queue Guard
Outside dev mode (FLETCH_DEV != 1), Fletch refuses to boot if a Postgres database is configured while Quiver is still using the default in-memory queue. This guard prevents silent job loss when containers restart or redeploy.
In production with Postgres, configure a durable job backend such as quiver/postgres or quiver/sqs. If an application genuinely intends to run an ephemeral in-memory queue alongside Postgres, opt out explicitly with fletch.WithAllowMemoryQueue().
Workers and Multi-Node Deployments
The compiled binary exposes both web and worker subcommands:
- Run
./myapp servefor HTTP and Live web instances. - Run
./myapp workfor dedicated Quiver worker processes.
Small deployments can run web and worker workloads together on a single instance, then split ./myapp work onto separate replicas as job volume grows.
Once you run more than one web replica behind a load balancer, configure a shared PubSub backend (pubsub/postgres, pubsub/nats, or pubsub/redis) so Live component updates and domain events propagate across nodes. Run fletch state plan in CI to detect Live state schema changes that would force connected clients to remount during a rolling deploy. See Multi-Node Deployments for the full multi-replica topology guide.
Example Dockerfile
The following two-stage Dockerfile builds a static CGO_ENABLED=0 binary and copies the binary along with public/dist, config, and database/migrations into a minimal distroless image. Swap the runtime base to alpine if you need a shell inside the container.
# Pin the Go and Fletch versions in production.
FROM golang:alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go install github.com/fletchhq/fletch/cmd/fletch@latest
RUN fletch build --os linux --arch amd64 --ldflags "-s -w" -o /out/myapp
FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /app
COPY --from=build /out/myapp /app/myapp
COPY --from=build /src/public/dist /app/public/dist
COPY --from=build /src/config /app/config
COPY --from=build /src/database/migrations /app/database/migrations
ENV FLETCH_ENV=production
EXPOSE 8080
ENTRYPOINT ["/app/myapp"]
CMD ["serve"]
To run migrations as a release task against the same image, override the container command to ["migrate"].