go-build-template

A Makefile/Dockerfile example for Go projects.

Github星跟踪图

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:

Makefile:

  • change BIN to your binary name
  • rename cmd/myapp to cmd/$BIN
  • 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

Dockerfile.in:

  • 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.

Building

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.

主要指标

概览
名称与所有者thockin/go-build-template
主编程语言Makefile
编程语言Makefile (语言数: 3)
平台
许可证Apache License 2.0
所有者活动
创建于2016-09-21 03:16:57
推送于2025-08-21 20:17:18
最后一次提交2025-08-21 13:17:10
发布数0
用户参与
星数3.3k
关注者数52
派生数431
提交数156
已启用问题?
问题数56
打开的问题数7
拉请求数60
打开的拉请求数0
关闭的拉请求数21
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?