go-build-template/README.md

47 lines
1.8 KiB
Markdown
Raw Normal View History

2016-09-21 04:15:39 +00:00
# Go app template build environment
[![Build Status](https://travis-ci.org/thockin/go-build-template.svg?branch=master)](https://travis-ci.org/thockin/go-build-template)
2016-09-21 04:15:39 +00:00
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
2017-10-25 17:55:43 +00:00
- rename `cmd/myapp` to `cmd/$BIN`
2016-09-21 04:15:39 +00:00
- change `REGISTRY` to the Docker registry you want to use
- maybe change `SRC_DIRS` if you use some other layout
2016-10-01 03:28:27 +00:00
- choose a strategy for `VERSION` values - git tags or manual
2016-09-21 04:15:39 +00:00
Dockerfile.in:
- maybe change or remove the `USER` if you need
2016-09-21 04:15:39 +00:00
2019-03-22 17:45:18 +00:00
## Go Modules
This assumes the use of go modules (which will be the default for all Go builds
2019-03-25 15:31:26 +00:00
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.
2019-03-22 17:45:18 +00:00
2016-09-21 04:15:39 +00:00
## 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.
2016-09-21 04:15:39 +00:00
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 architectures.
2016-09-21 04:15:39 +00:00
Run `make push` to push the container image to `REGISTRY`. Run `make all-push`
to push the container images for all architectures.
2016-09-21 04:15:39 +00:00
Run `make clean` to clean up.