Detection

migetpacks detects Go when any of these files are present in your project root:
  • go.mod
  • Godeps/Godeps.json
  • glide.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 use CGO_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 in go.mod:
  • module github.com/user/myapp produces binary myapp
  • Falls back to app if detection fails

Package Spec

You can specify which packages to build using the //+heroku install comment in go.mod:
Without this directive, 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 before go build
  • bin/go-post-compile - Runs after go build

golang-migrate

If github.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:
This adds -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

When BUILD_CACHE_DIR is configured, BuildKit cache mounts are used:

Registry Cache

Use CACHE_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).
DHI images for Go require minimum patch versions: 1.22.12, 1.23.7, or 1.24.1+. Older patch versions within these minor releases are not available.
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.):
This copies /usr/local/go from the builder to the runtime image.

Example

With Custom Options

Multi-Binary Project

With // +heroku install ./cmd/api ./cmd/worker in go.mod, both binaries are available at /app/bin/api and /app/bin/worker.