Detection
migetpacks detects Go when any of these files are present in your project root:go.modGodeps/Godeps.jsonglide.yaml
Version Detection
Go version is resolved in this order:Build Process
migetpacks generates a multi-stage Dockerfile that produces a static binary:Static Linking
Go builds useCGO_ENABLED=0 by default, producing fully static binaries that run on minimal base images. The linker flags -s -w strip debug information for smaller binaries.
Module Name and Binary Detection
The binary name is automatically derived from the module name ingo.mod:
module github.com/user/myappproduces binarymyapp- Falls back to
appif detection fails
Package Spec
You can specify which packages to build using the//+heroku install comment in go.mod:
go build . is used (builds the package in the current directory).
For multiple packages, binaries are placed in /build/bin/:
Build Hooks
migetpacks supports pre- and post-compile hooks:bin/go-pre-compile- Runs beforego buildbin/go-post-compile- Runs aftergo build
golang-migrate
Ifgithub.com/golang-migrate/migrate is detected in go.mod, the migrate CLI tool is automatically installed in the builder stage.
Linker Symbols
Set custom linker symbols using environment variables:-X main.version=1.0.0 to the linker flags.
Run Command
The default run command is determined in this order:Binary names in Procfiles are automatically prefixed with
./ if they don’t already have a path prefix.Caching
Docker Layer Caching
Dependencies are downloaded in a separate layer.go mod download is only re-run when go.mod or go.sum changes.
BuildKit Cache Mounts
WhenBUILD_CACHE_DIR is configured, BuildKit cache mounts are used:
Registry Cache
UseCACHE_IMAGE to push/pull BuildKit inline cache layers to a registry for cross-build caching.
DHI Support
Go is supported with Docker Hardened Images (requires version 1.22 or later).
The DHI runtime image is distroless with no shell. Since Go produces static binaries, this works without any special handling.
Go Toolchain in Runtime
If you need the Go toolchain available at runtime (for plugins,go run, etc.):
/usr/local/go from the builder to the runtime image.
Example
With Custom Options
Multi-Binary Project
// +heroku install ./cmd/api ./cmd/worker in go.mod, both binaries are available at /app/bin/api and /app/bin/worker.