Go makes deployment simple because go build produces a single, statically linked binary with no runtime to install. Release management is then a matter of building reproducibly, embedding version information, packaging the binary (usually in a small container image), automating tests and releases in CI/CD, and rolling out gradually with a way to roll back.
The best practices are to pin dependencies, cross-compile in CI, tag releases with semantic versions, handle graceful shutdown, expose health checks, and keep configuration outside the binary.
Cross-compilation is built in: set GOOS and GOARCH and build. Disabling cgo gives a fully static binary that runs on minimal images.
-trimpath removes local file paths, which helps reproducible builds, and -s -w strips symbol and debug tables to shrink the file (keep unstripped builds if you need profiling symbols). Commit go.mod and go.sum, pin the toolchain with the go and toolchain lines in go.mod, and use go mod verify in CI.
Make every running binary report which release it is. Since Go 1.18 the build embeds VCS data, readable in code via runtime/debug.ReadBuildInfo. You can also inject values with linker flags.
Log the version at start-up and expose it on a /version endpoint, so you always know what is deployed.
A multi-stage Dockerfile builds in a full Go image and copies only the binary into a minimal final image.
Use the Go version your project targets, run as a non-root user, and scan images for vulnerabilities. Run govulncheck ./... in CI to catch known issues in your dependencies and in the standard library.
A typical pipeline on every pull request runs:
go vet ./... and a linter such as golangci-lint.go test -race -cover ./....govulncheck ./....On a tag such as v1.4.0, the pipeline publishes the image and binaries. Tools like GoReleaser create archives for several platforms, checksums, changelogs and GitHub releases from one config file. Follow semantic versioning, and for libraries remember that a major version of 2 or higher changes the module path (example.com/lib/v2).
Prefer gradual strategies over replacing everything at once:
| Strategy | How it works | Rollback |
|---|---|---|
| Rolling update | Replace instances a few at a time | Redeploy the previous image |
| Blue-green | Run old and new side by side, switch traffic | Switch traffic back |
| Canary | Send a small share of traffic to the new version | Remove the canary |
Your service must cooperate. Expose readiness and liveness endpoints, and shut down gracefully so in-flight requests finish:
Make database migrations backward compatible (add a column first, switch code, remove the old column later), so the previous version still works after a rollback.
Keep configuration in environment variables or mounted files, not in the binary, and keep secrets in a secret manager. Emit structured logs with log/slog, expose metrics (for example Prometheus format) and add tracing with OpenTelemetry. Define alerts on error rate and latency so a bad release is noticed within minutes.
No. You can copy the binary to a server and run it under systemd. Containers help with consistency and orchestration, but they are optional.
Set GOOS and GOARCH before go build, for example GOOS=windows GOARCH=arm64. Disable cgo unless you have set up a cross C compiler.
Set a variable with -ldflags "-X main.version=...", or read VCS information from debug.ReadBuildInfo().
Redeploy the previous tagged image or binary, which is why immutable, versioned artifacts and backward-compatible migrations matter.
Deploy Go by building a static, versioned binary in CI, packaging it in a minimal non-root image, testing with the race detector and govulncheck, and releasing with tags. Use rolling, blue-green or canary rollouts with health checks and graceful shutdown, and keep rollback one redeploy away.