forked from hashicorp/consul-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
175 lines (155 loc) · 5.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Metadata about this makefile and position
MKFILE_PATH := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(dir $(realpath $(MKFILE_PATH)))
CURRENT_DIR := $(CURRENT_DIR:/=)
# Get the project metadata
GOVERSION := 1.8
VERSION := 0.18.1.dev
PROJECT := github.com/hashicorp/consul-template
OWNER := $(dir $(PROJECT))
OWNER := $(notdir $(OWNER:/=))
NAME := $(notdir $(PROJECT))
EXTERNAL_TOOLS =
# Current system information (this is the invoking system)
ME_OS = $(shell go env GOOS)
ME_ARCH = $(shell go env GOARCH)
# Default os-arch combination to build
XC_OS ?= darwin freebsd linux netbsd openbsd solaris windows
XC_ARCH ?= 386 amd64 arm
XC_EXCLUDE ?= darwin/arm solaris/386 solaris/arm windows/arm
# GPG Signing key (blank by default, means no GPG signing)
GPG_KEY ?=
# List of tests to run
TEST ?= ./...
# List all our actual files, excluding vendor
GOFILES = $(shell go list $(TEST) | grep -v /vendor/)
# Tags specific for building
GOTAGS ?=
# Number of procs to use
GOMAXPROCS ?= 4
# bin builds the project by invoking the compile script inside of a Docker
# container. Invokers can override the target OS or architecture using
# environment variables.
bin:
@echo "==> Building ${PROJECT}..."
@docker run \
--interactive \
--tty \
--rm \
--dns=8.8.8.8 \
--env="VERSION=${VERSION}" \
--env="PROJECT=${PROJECT}" \
--env="OWNER=${OWNER}" \
--env="NAME=${NAME}" \
--env="GOMAXPROCS=${GOMAXPROCS}" \
--env="GOTAGS=${GOTAGS}" \
--env="XC_OS=${XC_OS}" \
--env="XC_ARCH=${XC_ARCH}" \
--env="XC_EXCLUDE=${XC_EXCLUDE}" \
--env="DIST=${DIST}" \
--workdir="/go/src/${PROJECT}" \
--volume="${CURRENT_DIR}:/go/src/${PROJECT}" \
"golang:${GOVERSION}" /usr/bin/env sh -c "scripts/compile.sh"
# bin-local builds the project using the local go environment. This is only
# recommended for advanced users or users who do not wish to use the Docker
# build process.
bin-local:
@echo "==> Building ${PROJECT} (locally)..."
@env \
VERSION="${VERSION}" \
PROJECT="${PROJECT}" \
OWNER="${OWNER}" \
NAME="${NAME}" \
GOMAXPROCS="${GOMAXPROCS}" \
GOTAGS="${GOTAGS}" \
XC_OS="${XC_OS}" \
XC_ARCH="${XC_ARCH}" \
XC_EXCLUDE="${XC_EXCLUDE}" \
DIST="${DIST}" \
/usr/bin/env sh -c "scripts/compile.sh"
# bootstrap installs the necessary go tools for development or build
bootstrap:
@echo "==> Bootstrapping ${PROJECT}..."
@for t in ${EXTERNAL_TOOLS}; do \
echo "--> Installing $$t" ; \
go get -u "$$t"; \
done
# deps gets all the dependencies for this repository and vendors them.
deps:
@echo "==> Updating dependencies..."
@docker run \
--interactive \
--tty \
--rm \
--dns=8.8.8.8 \
--env="GOMAXPROCS=${GOMAXPROCS}" \
--workdir="/go/src/${PROJECT}" \
--volume="${CURRENT_DIR}:/go/src/${PROJECT}" \
"golang:${GOVERSION}" /usr/bin/env sh -c "scripts/deps.sh"
# dev builds the project for the current system as defined by go env.
dev:
@env \
XC_OS="${ME_OS}" \
XC_ARCH="${ME_ARCH}" \
$(MAKE) -f "${MKFILE_PATH}" bin
@echo "--> Moving into bin/"
@mkdir -p "${CURRENT_DIR}/bin/"
@cp "${CURRENT_DIR}/pkg/${ME_OS}_${ME_ARCH}/${NAME}" "${CURRENT_DIR}/bin/"
ifdef GOPATH
@echo "--> Moving into GOPATH/"
@mkdir -p "${GOPATH}/bin/"
@cp "${CURRENT_DIR}/pkg/${ME_OS}_${ME_ARCH}/${NAME}" "${GOPATH}/bin/"
endif
# dist builds the binaries and then signs and packages them for distribution
dist:
ifndef GPG_KEY
@echo "==> WARNING: No GPG key specified! Without a GPG key, this release"
@echo " will not be signed. Abort now to prevent building an"
@echo " unsigned release, or wait 5 seconds to continue."
@echo ""
@echo "--> Press CTRL + C to abort..."
@sleep 5
endif
@${MAKE} -f "${MKFILE_PATH}" bin DIST=1
@echo "==> Tagging release (v${VERSION})..."
ifdef GPG_KEY
@git commit --allow-empty --gpg-sign="${GPG_KEY}" -m "Release v${VERSION}"
@git tag -a -m "Version ${VERSION}" -s -u "${GPG_KEY}" "v${VERSION}" master
@gpg --default-key "${GPG_KEY}" --detach-sig "${CURRENT_DIR}/pkg/dist/${NAME}_${VERSION}_SHA256SUMS"
else
@git commit --allow-empty -m "Release v${VERSION}"
@git tag -a -m "Version ${VERSION}" "v${VERSION}" master
endif
@echo "--> Do not forget to run:"
@echo ""
@echo " git push && git push --tags"
@echo ""
@echo "And then upload the binaries in dist/ to GitHub!"
# docker builds the docker container
docker:
@echo "==> Building container..."
@docker build \
--pull \
--rm \
--file="docker/Dockerfile" \
--tag="${OWNER}/${NAME}" \
--tag="${OWNER}/${NAME}:${VERSION}" \
"${CURRENT_DIR}"
# docker-push pushes the container to the registry
docker-push:
@echo "==> Pushing to Docker registry..."
@docker push "${OWNER}/${NAME}:latest"
@docker push "${OWNER}/${NAME}:${VERSION}"
# generate runs the code generator
generate:
@echo "==> Generating ${PROJECT}..."
@go generate ${GOFILES}
# test runs the test suite
test:
@echo "==> Testing ${PROJECT}..."
@go test -timeout=60s -parallel=5 -tags="${GOTAGS}" ${GOFILES} ${TESTARGS}
# test-race runs the race checker
test-race:
@echo "==> Testing ${PROJECT} (race)..."
@go test -timeout=60s -race -tags="${GOTAGS}" ${GOFILES} ${TESTARGS}
.PHONY: bin bin-local bootstrap deps dev dist docker docker-push generate test test-race