forked from projectcalico/typha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
335 lines (298 loc) · 12.5 KB
/
Makefile
File metadata and controls
335 lines (298 loc) · 12.5 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
###############################################################################
# The build architecture is select by setting the ARCH variable.
# For example: When building on ppc64le you could use ARCH=ppc64le make <....>.
# When ARCH is undefined it defaults to amd64.
ARCH?=amd64
ifeq ($(ARCH),amd64)
ARCHTAG?=
GO_BUILD_VER?=v0.9
endif
ifeq ($(ARCH),ppc64le)
ARCHTAG:=-ppc64le
GO_BUILD_VER?=latest
endif
help:
@echo "Typha Makefile"
@echo
@echo "Dependencies: docker 1.12+; go 1.8+"
@echo
@echo "Initial set-up:"
@echo
@echo " make update-tools Update/install the go build dependencies."
@echo
@echo "Builds:"
@echo
@echo " make all Build all the binary packages."
@echo " make calico/typha Build calico/typha docker image."
@echo
@echo "Tests:"
@echo
@echo " make ut Run UTs."
@echo " make go-cover-browser Display go code coverage in browser."
@echo
@echo "Maintenance:"
@echo
@echo " make update-vendor Update the vendor directory with new "
@echo " versions of upstream packages. Record results"
@echo " in glide.lock."
@echo " make go-fmt Format our go code."
@echo " make clean Remove binary files."
# Disable make's implicit rules, which are not useful for golang, and slow down the build
# considerably.
.SUFFIXES:
all: calico/typha bin/typha-client-$(ARCH)
test: ut
GO_BUILD_CONTAINER?=calico/go-build$(ARCHTAG):$(GO_BUILD_VER)
# Figure out version information. To support builds from release tarballs, we default to
# <unknown> if this isn't a git checkout.
GIT_COMMIT:=$(shell git rev-parse HEAD || echo '<unknown>')
BUILD_ID:=$(shell git rev-parse HEAD || uuidgen | sed 's/-//g')
GIT_DESCRIPTION:=$(shell git describe --tags || echo '<unknown>')
# Calculate a timestamp for any build artefacts.
DATE:=$(shell date -u +'%FT%T%z')
# List of Go files that are generated by the build process. Builds should
# depend on these, clean removes them.
GENERATED_GO_FILES:=
# All Typha go files.
TYPHA_GO_FILES:=$(shell find . $(foreach dir,$(NON_TYPHA_DIRS),-path ./$(dir) -prune -o) -type f -name '*.go' -print) $(GENERATED_GO_FILES)
# Figure out the users UID/GID. These are needed to run docker containers
# as the current user and ensure that files built inside containers are
# owned by the current user.
MY_UID:=$(shell id -u)
MY_GID:=$(shell id -g)
# Build the calico/typha docker image, which contains only Typha.
.PHONY: calico/typha
calico/typha: bin/calico-typha-$(ARCH)
rm -rf docker-image/bin
mkdir -p docker-image/bin
cp bin/calico-typha-$(ARCH) docker-image/bin/
docker build --pull -t calico/typha$(ARCHTAG) docker-image -f docker-image/Dockerfile$(ARCHTAG)
# Pre-configured docker run command that runs as this user with the repo
# checked out to /code, uses the --rm flag to avoid leaving the container
# around afterwards.
DOCKER_RUN_RM:=docker run --rm --user $(MY_UID):$(MY_GID) -v $${PWD}:/code
DOCKER_RUN_RM_ROOT:=docker run --rm -v $${PWD}:/code
# Allow libcalico-go and the ssh auth sock to be mapped into the build container.
ifdef LIBCALICOGO_PATH
EXTRA_DOCKER_ARGS += -v $(LIBCALICOGO_PATH):/go/src/github.com/projectcalico/libcalico-go:ro
endif
ifdef SSH_AUTH_SOCK
EXTRA_DOCKER_ARGS += -v $(SSH_AUTH_SOCK):/ssh-agent --env SSH_AUTH_SOCK=/ssh-agent
endif
DOCKER_GO_BUILD := mkdir -p .go-pkg-cache && \
docker run --rm \
--net=host \
$(EXTRA_DOCKER_ARGS) \
-e LOCAL_USER_ID=$(MY_UID) \
-v $${PWD}:/go/src/github.com/projectcalico/typha:rw \
-v $${PWD}/.go-pkg-cache:/go/pkg:rw \
-w /go/src/github.com/projectcalico/typha \
$(GO_BUILD_CONTAINER)
# Update the vendored dependencies with the latest upstream versions matching
# our glide.yaml. If there area any changes, this updates glide.lock
# as a side effect. Unless you're adding/updating a dependency, you probably
# want to use the vendor target to install the versions from glide.lock.
.PHONY: update-vendor
update-vendor:
mkdir -p $$HOME/.glide
$(DOCKER_GO_BUILD) glide up --strip-vendor
touch vendor/.up-to-date
# vendor is a shortcut for force rebuilding the go vendor directory.
.PHONY: vendor
vendor vendor/.up-to-date: glide.lock
mkdir -p $$HOME/.glide
$(DOCKER_GO_BUILD) glide install --strip-vendor
touch vendor/.up-to-date
# Linker flags for building Typha.
#
# We use -X to insert the version information into the placeholder variables
# in the buildinfo package.
#
# We use -B to insert a build ID note into the executable, without which, the
# RPM build tools complain.
LDFLAGS:=-ldflags "\
-X github.com/projectcalico/typha/pkg/buildinfo.GitVersion=$(GIT_DESCRIPTION) \
-X github.com/projectcalico/typha/pkg/buildinfo.BuildDate=$(DATE) \
-X github.com/projectcalico/typha/pkg/buildinfo.GitRevision=$(GIT_COMMIT) \
-B 0x$(BUILD_ID)"
bin/calico-typha-$(ARCH): $(TYPHA_GO_FILES) vendor/.up-to-date
@echo Building typha...
mkdir -p bin
$(DOCKER_GO_BUILD) \
sh -c 'go build -v -i -o $@ -v $(LDFLAGS) "github.com/projectcalico/typha/cmd/calico-typha" && \
( ldd $@ 2>&1 | grep -q -e "Not a valid dynamic program" \
-e "not a dynamic executable" || \
( echo "Error: bin/calico-typha was not statically linked"; false ) )'
bin/typha-client-$(ARCH): $(TYPHA_GO_FILES) vendor/.up-to-date
@echo Building typha client...
mkdir -p bin
$(DOCKER_GO_BUILD) \
sh -c 'go build -v -i -o $@ -v $(LDFLAGS) "github.com/projectcalico/typha/cmd/typha-client" && \
( ldd $@ 2>&1 | grep -q -e "Not a valid dynamic program" \
-e "not a dynamic executable" || \
( echo "Error: bin/typha-client was not statically linked"; false ) )'
# Install or update the tools used by the build
.PHONY: update-tools
update-tools:
go get -u github.com/Masterminds/glide
go get -u github.com/onsi/ginkgo/ginkgo
# Run go fmt on all our go files.
.PHONY: go-fmt goimports
go-fmt goimports:
$(DOCKER_GO_BUILD) sh -c 'glide nv -x | \
grep -v -e "^\\.$$" | \
xargs goimports -w -local github.com/projectcalico/'
check-licenses/dependency-licenses.txt: vendor/.up-to-date
$(DOCKER_GO_BUILD) sh -c 'licenses ./cmd/calico-typha > check-licenses/dependency-licenses.tmp && \
mv check-licenses/dependency-licenses.tmp check-licenses/dependency-licenses.txt'
.PHONY: ut
ut combined.coverprofile: vendor/.up-to-date $(TYPHA_GO_FILES)
@echo Running Go UTs.
$(DOCKER_GO_BUILD) ./utils/run-coverage
bin/check-licenses: $(TYPHA_GO_FILES)
$(DOCKER_GO_BUILD) go build -v -i -o $@ "github.com/projectcalico/typha/check-licenses"
.PHONY: check-licenses
check-licenses: check-licenses/dependency-licenses.txt bin/check-licenses
@echo Checking dependency licenses
$(DOCKER_GO_BUILD) bin/check-licenses
.PHONY: go-meta-linter
go-meta-linter: vendor/.up-to-date $(GENERATED_GO_FILES)
# Run staticcheck stand-alone since gometalinter runs concurrent copies, which
# uses a lot of RAM.
$(DOCKER_GO_BUILD) sh -c 'glide nv | xargs -n 3 staticcheck'
$(DOCKER_GO_BUILD) gometalinter --enable-gc \
--deadline=300s \
--disable-all \
--enable=goimports \
--enable=errcheck \
--vendor ./...
.PHONY: static-checks
static-checks:
$(MAKE) go-meta-linter check-licenses
.PHONY: ut-no-cover
ut-no-cover: vendor/.up-to-date $(TYPHA_GO_FILES)
@echo Running Go UTs without coverage.
$(DOCKER_GO_BUILD) ginkgo -r $(GINKGO_OPTIONS)
.PHONY: ut-watch
ut-watch: vendor/.up-to-date $(TYPHA_GO_FILES)
@echo Watching go UTs for changes...
$(DOCKER_GO_BUILD) ginkgo watch -r $(GINKGO_OPTIONS)
# Launch a browser with Go coverage stats for the whole project.
.PHONY: cover-browser
cover-browser: combined.coverprofile
go tool cover -html="combined.coverprofile"
.PHONY: cover-report
cover-report: combined.coverprofile
# Print the coverage. We use sed to remove the verbose prefix and trim down
# the whitespace.
@echo
@echo ======== All coverage =========
@echo
@$(DOCKER_GO_BUILD) sh -c 'go tool cover -func combined.coverprofile | \
sed 's=github.com/projectcalico/typha/==' | \
column -t'
@echo
@echo ======== Missing coverage only =========
@echo
@$(DOCKER_GO_BUILD) sh -c "go tool cover -func combined.coverprofile | \
sed 's=github.com/projectcalico/typha/==' | \
column -t | \
grep -v '100\.0%'"
.PHONY: upload-to-coveralls
upload-to-coveralls: combined.coverprofile
ifndef COVERALLS_REPO_TOKEN
$(error COVERALLS_REPO_TOKEN is undefined - run using make upload-to-coveralls COVERALLS_REPO_TOKEN=abcd)
endif
$(DOCKER_GO_BUILD) goveralls -repotoken=$(COVERALLS_REPO_TOKEN) -coverprofile=combined.coverprofile
bin/calico-typha.transfer-url: bin/calico-typha-$(ARCH)
$(DOCKER_GO_BUILD) sh -c 'curl --upload-file bin/calico-typha-$(ARCH) https://transfer.sh/calico-typha > $@'
.PHONY: clean
clean:
rm -rf bin \
docker-image/bin \
build \
$(GENERATED_GO_FILES) \
.glide \
vendor \
.go-pkg-cache \
check-licenses/dependency-licenses.txt \
release-notes-*
find . -name "*.coverprofile" -type f -delete
find . -name "coverage.xml" -type f -delete
find . -name ".coverage" -type f -delete
find . -name "*.pyc" -type f -delete
.PHONY: release release-once-tagged
release: clean
ifndef VERSION
$(error VERSION is undefined - run using make release VERSION=X.Y.Z)
endif
ifeq ($(GIT_COMMIT),<unknown>)
$(error git commit ID couldn't be determined, releases must be done from a git working copy)
endif
$(DOCKER_GO_BUILD) utils/tag-release.sh $(VERSION)
.PHONY: continue-release
continue-release:
@echo "Edited release notes are:"
@echo
@cat ./release-notes-$(VERSION)
@echo
@echo "Hit Return to go ahead and create the tag, or Ctrl-C to cancel."
@bash -c read
# Create annotated release tag.
git tag $(VERSION) -F ./release-notes-$(VERSION)
rm ./release-notes-$(VERSION)
# Now decouple onto another make invocation, as we want some variables
# (GIT_DESCRIPTION and BUNDLE_FILENAME) to be recalculated based on the
# new tag.
$(MAKE) release-once-tagged
release-once-tagged:
@echo
@echo "Will now build release artifacts..."
@echo
$(MAKE) bin/calico-typha-$(ARCH) calico/typha
docker tag calico/typha$(ARCHTAG) calico/typha$(ARCHTAG):$(VERSION)
docker tag calico/typha$(ARCHTAG) quay.io/calico/typha$(ARCHTAG):latest
docker tag calico/typha$(ARCHTAG):$(VERSION) quay.io/calico/typha$(ARCHTAG):$(VERSION)
@echo
@echo "Checking built typha has correct version..."
@if docker run quay.io/calico/typha$(ARCHTAG):$(VERSION) calico-typha --version | grep -q '$(VERSION)$$'; \
then \
echo "Check successful."; \
else \
echo "Incorrect version in docker image!"; \
false; \
fi
@echo
@echo "Typha release artifacts have been built:"
@echo
@echo "- Binary: bin/calico-typha-$(ARCH)"
@echo "- Docker container image: calico/typha$(ARCHTAG):$(VERSION)"
@echo "- Same, tagged for Quay: quay.io/calico/typha$(ARCHTAG):$(VERSION)"
@echo
@echo "Now to publish this release to Github:"
@echo
@echo "- Push the new tag ($(VERSION)) to https://github.com/projectcalico/typha"
@echo "- Go to https://github.com/projectcalico/typha/releases/tag/$(VERSION)"
@echo "- Copy the tag content (release notes) shown on that page"
@echo "- Go to https://github.com/projectcalico/typha/releases/new?tag=$(VERSION)"
@echo "- Name the GitHub release:"
@echo " - For a stable release: 'Typha $(VERSION)'"
@echo " - For a test release: 'Typha $(VERSION) pre-release for testing'"
@echo "- Paste the copied tag content into the large textbox"
@echo "- Add an introduction message and, for a significant release,"
@echo " append information about where to get the release. (See the 2.2.0"
@echo " release for an example.)"
@echo "- Attach the binary"
@echo "- Click the 'This is a pre-release' checkbox, if appropriate"
@echo "- Click 'Publish release'"
@echo
@echo "Then, push the versioned docker images to Dockerhub and Quay:"
@echo
@echo "- docker push calico/typha$(ARCHTAG):$(VERSION)"
@echo "- docker push quay.io/calico/typha$(ARCHTAG):$(VERSION)"
@echo
@echo "If this is the latest release from the most recent stable"
@echo "release series, also push the 'latest' tag:"
@echo
@echo "- docker push calico/typha$(ARCHTAG):latest"
@echo "- docker push quay.io/calico/typha$(ARCHTAG):latest"