Skip to content

Instantly share code, notes, and snippets.

@bneil
Last active May 8, 2019 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bneil/272414f758754764f2d8ec07bdf8b710 to your computer and use it in GitHub Desktop.
Save bneil/272414f758754764f2d8ec07bdf8b710 to your computer and use it in GitHub Desktop.
My Docker/GoLang Makefile
## Basic GoLang Makefile
##
## inspired by https://gist.github.com/turtlemonvh/38bd3d73e61769767c35931d8c70ccb4
## But this has more dockerism's
BINARY = thing
VET_REPORT = reports/vet.report
TEST_REPORT = reports/tests.xml
GOARCH = amd64
DOCKER_HUB = gitlab.com/bneil
# Version is used to hook into jenkins/concourse
VERSION?=local
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-s -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT} -X main.BRANCH=${BRANCH}"
# Build the project
# should probably be replaced with gox
all: clean test vet linux darwin windows
local: linux docker
release: linux
deploy:
docker push ${DOCKER_HUB}/${BINARY}:${VERSION} ;
docker:
docker build --label branch=${BRANCH} --label commit=${COMMIT} --label version=${VERSION} -t ${DOCKER_HUB}/${BINARY}:${VERSION} .
linux:
GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -a -installsuffix cgo -o ${BINARY}-linux-${GOARCH} cmd/${BINARY}/main.go
darwin:
GOOS=darwin GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH} cmd/${BINARY}/main.go
windows:
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o cmd\${BINARY}\${BINARY}-windows-${GOARCH}.exe .
test:
go get github.com/tebeka/go2xunit;
go test -v ./... 2>&1 | go2xunit -output ${TEST_REPORT};
vet:
go vet ./... > ${VET_REPORT} 2>&1 ;
fmt:
go fmt $$(go list ./...) ;
clean:
-rm -f ${TEST_REPORT}
-rm -f ${VET_REPORT}
-rm -f ${BINARY}-*
.PHONY: linux darwin windows test vet fmt clean docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment