[v3] First-class production server build (parity with desktop Taskfiles)
Summary
Server mode (-tags server) has no production build path. The generated build:server task always builds a dev-tagged binary, so deployed headless servers ship with dev-only code, no build hardening, and no parity with the rich desktop build/package tasks. We should make a production server build first-class and consistent with the desktop Taskfiles.
Current behaviour
In the build-assets template (v3/internal/commands/build_assets/Taskfile.tmpl.yml), the desktop tasks (darwin/windows/linux build → build:native) compute BUILD_FLAGS with a full profile matrix:
- production (default):
-tags production -trimpath -buildvcs=false -ldflags="-w -s" - DEV (
DEV=true):-gcflags=all="-l", no stripping - obfuscated:
garble+-tags wails_obfuscated - plus
package, icons, codesign, etc.
The server task, by contrast, is a single bare line:
build:server:
cmds:
- go build -tags server {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}-server{{exeExt}}
BUILD_FLAGS defaults to empty and production is never added.
Why this matters
application_dev.go is gated //go:build !production and application_server.go is //go:build server — the two tags are orthogonal and composable, but because build:server omits production, every server binary pulls in the !production dev code paths (dev logger, dev menu items, dev asset middleware) and skips -trimpath/strip.
Measured on a real app (modernc SQLite, no CGO):
| Build | Tags / flags | Size |
|---|---|---|
task build:server (today) |
-tags server |
39.7 MB |
| production server | -tags server,production -trimpath -buildvcs=false -ldflags="-w -s" |
25.9 MB (~35% smaller) |
-tags server,production already compiles cleanly today — the capability exists in the Go layer; only the build tooling is missing.
Proposed changes
- Taskfile parity (primary). Give
build:serverthe same profile matrix as desktop:- production by default:
-tags server,production -trimpath -buildvcs=false -ldflags="-w -s", consistent withtask buildbeing production for desktop; DEV=truefor a dev server (-tags server, no strip);- obfuscation parity (
garble+wails_obfuscated); - a
package:serverequivalent (the Docker image is the natural "package").
- production by default:
- Dockerfile.server should build the production server (
-tags server,production+ strip) andCGO_ENABLED=0for a clean static binary into distroless. - Keep
run:serveras a convenience that builds + runs (DEV by default is reasonable forrun).
Thoughts on the API surface
Config is mostly already there: application.Options.Server (ServerOptions{Host, Port, TLS, *Timeouts}) plus WAILS_SERVER_HOST / WAILS_SERVER_PORT env overrides. So no new Go config is strictly required.
The "API surface" that needs the change is really the build/task surface and the tag semantics:
- Make
serverandproductioncompose as a documented, first-class combination (today it's an undocumented-tags server,productionthat users must discover). Decide whetherbuild:serveris production-by-default (recommended, mirrors desktopbuild) withDEV=trueopting into the dev server. - Asset/middleware behaviour: a production server should not run the dev asset middleware. Confirm the
!productiondev asset path is fully excluded whenproductionis set, so a production server serves only embedded assets. - Optional, smaller: in server mode the desktop-only options (
Window,SystemTray,Mac, …) silently no-op. Consider a lightweightApp.IsServer()/validation or doc note so users aren't surprised, rather than a new options struct.
Net: the gap is build-system + tag wiring + docs, not new runtime config — a "slight" surface change at most.
Acceptance criteria
- [ ]
task build:serverproduces a stripped, production-tagged binary by default;DEV=trueproduces a dev server. - [ ] Obfuscated server builds supported, matching desktop.
- [ ]
Dockerfile.serverbuilds the production server (CGO_ENABLED=0, static) into distroless. - [ ] Production server excludes dev-only code paths/middleware (verified: smaller binary, no dev asset proxy).
- [ ] Docs note the
server/productionrelationship andServerOptions/env config.
Filed from a real-world server-mode deployment; happy to open a PR for the Taskfile/Dockerfile template changes if the approach looks right.