A Makefile/Dockerfile example for Go projects.
Makefile
3,332
162 commits
updated Sep 25, 2026
This is a skeleton project for a Go application, which captures the best build techniques I have learned to date. It uses a Makefile to drive the build (the universal API to software projects) and a Dockerfile to build a docker image.
This has only been tested on Linux, and depends on Docker buildx to build.
To use this, simply copy this repo and make the following changes:
Makefile:
BINS to your binary name(s)cmd/myapp-* with one directory for each of your BINSREGISTRY to the Docker registry you want to useVERSION values - git tags or manualALL_PLATFORMSBASE_IMAGE (it must be a manifest-list with support for all
platforms in ALL_PLATFORMS)Dockerfile.in:
USER if you needgo.mod:
This assumes the use of go modules (which is the default for all Go builds as of Go 1.13).
This includes go-licenses and golangci-lint, but they are kept in the tools
sub-module. If you don't want those (or their dependencies, they can be
removed.
Run make or make build to compile your app. This will use docker buildx
(which you need to have installed) to build your app, with the current
directory volume-mounted into place. This will store incremental state for the
fastest possible build. Run make all-build to build for all architectures.
Run make container to build the container image. It will calculate the image
tag based on the most recent git tag, and whether the repo is "dirty" since
that tag (see make version). Run make all-container to build containers
for all supported architectures.
Run make push to push the container image to REGISTRY. Run make all-push
to push the container images for all architectures.
Run make manifest-list to build and push all containers for all
architectures, and then publish a manifest-list for them.
Run make clean to clean up.
Run make help to get a list of available targets.
Run make test and make lint to run tests and linters, respectively. Like
building, this will use docker to execute.
The golangci-lint tool looks for configuration in .golangci.yaml. If that
file is not provided, it will use its own built-in defaults.
(top 24 of 73)
729 followers · starred Aug 2019
609 followers · starred Sep 2016
323 followers · starred Jul 2018
352 followers · starred Mar 2017
A Makefile/Dockerfile example for Go projects.
Makefile
3,332
162 commits
updated Sep 25, 2026
This is a skeleton project for a Go application, which captures the best build techniques I have learned to date. It uses a Makefile to drive the build (the universal API to software projects) and a Dockerfile to build a docker image.
This has only been tested on Linux, and depends on Docker buildx to build.
To use this, simply copy this repo and make the following changes:
Makefile:
BINS to your binary name(s)cmd/myapp-* with one directory for each of your BINSREGISTRY to the Docker registry you want to useVERSION values - git tags or manualALL_PLATFORMSBASE_IMAGE (it must be a manifest-list with support for all
platforms in ALL_PLATFORMS)Dockerfile.in:
USER if you needgo.mod:
This assumes the use of go modules (which is the default for all Go builds as of Go 1.13).
This includes go-licenses and golangci-lint, but they are kept in the tools
sub-module. If you don't want those (or their dependencies, they can be
removed.
Run make or make build to compile your app. This will use docker buildx
(which you need to have installed) to build your app, with the current
directory volume-mounted into place. This will store incremental state for the
fastest possible build. Run make all-build to build for all architectures.
Run make container to build the container image. It will calculate the image
tag based on the most recent git tag, and whether the repo is "dirty" since
that tag (see make version). Run make all-container to build containers
for all supported architectures.
Run make push to push the container image to REGISTRY. Run make all-push
to push the container images for all architectures.
Run make manifest-list to build and push all containers for all
architectures, and then publish a manifest-list for them.
Run make clean to clean up.
Run make help to get a list of available targets.
Run make test and make lint to run tests and linters, respectively. Like
building, this will use docker to execute.
The golangci-lint tool looks for configuration in .golangci.yaml. If that
file is not provided, it will use its own built-in defaults.
(top 24 of 73)
729 followers · starred Aug 2019
609 followers · starred Sep 2016
323 followers · starred Jul 2018
352 followers · starred Mar 2017