Skip to content
A Makefile/Dockerfile example for Go projects.
Makefile Shell Go
Branch: master
Clone or download

Latest commit

thockin Add `make help`
Manually apply PR #25, since it languished (my fault), and expand on it.

Thanks to Damian ONeill (@damianoneill) for the original PR.
Latest commit afae457 May 23, 2020


Type Name Latest commit message Commit time
Failed to load latest commit information.
build Rename VERSION -> Version Dec 3, 2019
cmd Add support for multiple binaries May 23, 2020
pkg/version Rename VERSION -> Version Dec 3, 2019
.gitignore Simplify push target Dec 18, 2019 use vendor in tests Mar 25, 2019
LICENSE Initial commit Sep 21, 2016
Makefile Add `make help` May 23, 2020 Add `make help` May 23, 2020
cloudbuild.yaml add cloudbuild Dec 3, 2019

Go app template build environment

Build Status

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 to build.

Customizing it

To use this, simply copy these files and make the following changes:


  • change BINS to your binary name(s)
  • replace cmd/myapp-* with one directory for each of your BINS
  • change REGISTRY to the Docker registry you want to use
  • maybe change SRC_DIRS if you use some other layout
  • choose a strategy for VERSION values - git tags or manual

  • maybe change or remove the USER if you need

Go Modules

This assumes the use of go modules (which will be the default for all Go builds as of Go 1.13) and vendoring (which reasonable minds might disagree about). You will need to run go mod vendor to create a vendor directory when you have dependencies.


Run make or make build to compile your app. This will use a Docker image 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 clean to clean up.

Run make help to get a list of available targets.

You can’t perform that action at this time.