wails icon indicating copy to clipboard operation
wails copied to clipboard

[v3] First-class production server build (parity with desktop Taskfiles)

Open taliesin-ai opened this issue 5 months ago • 0 comments

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

  1. Taskfile parity (primary). Give build:server the same profile matrix as desktop:
    • production by default: -tags server,production -trimpath -buildvcs=false -ldflags="-w -s", consistent with task build being production for desktop;
    • DEV=true for a dev server (-tags server, no strip);
    • obfuscation parity (garble + wails_obfuscated);
    • a package:server equivalent (the Docker image is the natural "package").
  2. Dockerfile.server should build the production server (-tags server,production + strip) and CGO_ENABLED=0 for a clean static binary into distroless.
  3. Keep run:server as a convenience that builds + runs (DEV by default is reasonable for run).

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 server and production compose as a documented, first-class combination (today it's an undocumented -tags server,production that users must discover). Decide whether build:server is production-by-default (recommended, mirrors desktop build) with DEV=true opting into the dev server.
  • Asset/middleware behaviour: a production server should not run the dev asset middleware. Confirm the !production dev asset path is fully excluded when production is 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 lightweight App.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:server produces a stripped, production-tagged binary by default; DEV=true produces a dev server.
  • [ ] Obfuscated server builds supported, matching desktop.
  • [ ] Dockerfile.server builds 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/production relationship and ServerOptions/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.

taliesin-ai avatar Jun 29 '26 00:06 taliesin-ai