forked from anuvu/nomad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
314 lines (268 loc) · 8.97 KB
/
GNUmakefile
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
SHELL = bash
PROJECT_ROOT := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
THIS_OS := $(shell uname)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
GO_LDFLAGS := "-X github.com/hashicorp/nomad/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"
GO_TAGS =
default: help
ifeq (,$(findstring $(THIS_OS),Darwin Linux FreeBSD))
$(error Building Nomad is currently only supported on Darwin and Linux.)
endif
# On Linux we build for Linux, Windows, and potentially Linux+LXC
ifeq (Linux,$(THIS_OS))
# Detect if we have LXC on the path
ifeq (0,$(shell pkg-config --exists lxc; echo $$?))
HAS_LXC="true"
endif
ifeq ($(TRAVIS),true)
$(info Running in Travis, verbose mode is disabled)
else
VERBOSE="true"
endif
ALL_TARGETS += linux_386 \
linux_amd64 \
linux_arm \
linux_arm64 \
windows_386 \
windows_amd64
ifeq ("true",$(HAS_LXC))
ALL_TARGETS += linux_amd64-lxc
endif
endif
# On MacOS, we only build for MacOS
ifeq (Darwin,$(THIS_OS))
ALL_TARGETS += darwin_amd64
endif
# On FreeBSD, we only build for FreeBSD
ifeq (FreeBSD,$(THIS_OS))
ALL_TARGETS += freebsd_amd64
endif
pkg/darwin_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for darwin/amd64
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@"
pkg/freebsd_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for freebsd/amd64
@echo "==> Building $@..."
@CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@"
pkg/linux_386/nomad: $(SOURCE_FILES) ## Build Nomad for linux/386
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=linux GOARCH=386 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@"
pkg/linux_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for linux/amd64
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@"
pkg/linux_arm/nomad: $(SOURCE_FILES) ## Build Nomad for linux/arm
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-linux-gnueabihf-gcc-5 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@"
pkg/linux_arm64/nomad: $(SOURCE_FILES) ## Build Nomad for linux/arm64
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-5 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@"
# If CGO support for Windows is ever required, set the following variables
# in the environment for `go build` for both the windows/amd64 and the
# windows/386 targets:
# CC=i686-w64-mingw32-gcc
# CXX=i686-w64-mingw32-g++
pkg/windows_386/nomad: $(SOURCE_FILES) ## Build Nomad for windows/386
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=windows GOARCH=386 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@.exe"
pkg/windows_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for windows/amd64
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=windows GOARCH=amd64 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS)" \
-o "$@.exe"
pkg/linux_amd64-lxc/nomad: $(SOURCE_FILES) ## Build Nomad+LXC for linux/amd64
@echo "==> Building $@ with tags $(GO_TAGS)..."
@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build \
-ldflags $(GO_LDFLAGS) \
-tags "$(GO_TAGS) lxc" \
-o "$@"
# Define package targets for each of the build targets we actually have on this system
define makePackageTarget
pkg/$(1).zip: pkg/$(1)/nomad
@echo "==> Packaging for $(1)..."
@zip -j pkg/$(1).zip pkg/$(1)/*
endef
# Reify the package targets
$(foreach t,$(ALL_TARGETS),$(eval $(call makePackageTarget,$(t))))
.PHONY: bootstrap
bootstrap: deps lint-deps # Install all dependencies
.PHONY: deps
deps: ## Install build and development dependencies
@echo "==> Updating build dependencies..."
go get -u github.com/kardianos/govendor
go get -u github.com/ugorji/go/codec/codecgen
go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/elazarl/go-bindata-assetfs/...
go get -u github.com/a8m/tree/cmd/tree
go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt
.PHONY: lint-deps
lint-deps: ## Install linter dependencies
@echo "==> Updating linter dependencies..."
go get -u github.com/alecthomas/gometalinter
gometalinter --install
.PHONY: check
check: ## Lint the source code
@echo "==> Linting source code..."
@gometalinter \
--deadline 10m \
--vendor \
--exclude='.*\.generated\.go' \
--exclude='.*bindata_assetfs\.go' \
--skip="ui/" \
--sort="path" \
--aggregate \
--enable-gc \
--disable-all \
--enable goimports \
--enable misspell \
--enable vet \
--enable deadcode \
--enable varcheck \
--enable ineffassign \
--enable structcheck \
--enable unconvert \
--enable gofmt \
./...
@echo "==> Spell checking website..."
@misspell -error -source=text website/source/
.PHONY: checkscripts
checkscripts: ## Lint shell scripts
@echo "==> Linting scripts..."
@shellcheck ./scripts/*
generate: LOCAL_PACKAGES = $(shell go list ./... | grep -v '/vendor/')
generate: ## Update generated code
@go generate $(LOCAL_PACKAGES)
vendorfmt:
@echo "--> Formatting vendor/vendor.json"
test -x $(GOPATH)/bin/vendorfmt || go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt
vendorfmt
changelogfmt:
@echo "--> Making [GH-xxxx] references clickable..."
@sed -E 's|([^\[])\[GH-([0-9]+)\]|\1[[GH-\2](https://github.com/hashicorp/nomad/issues/\2)]|g' CHANGELOG.md > changelog.tmp && mv changelog.tmp CHANGELOG.md
.PHONY: dev
dev: GOOS=$(shell go env GOOS)
dev: GOARCH=$(shell go env GOARCH)
dev: GOPATH=$(shell go env GOPATH)
dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)$(if $(HAS_LXC),-lxc)/nomad
dev: vendorfmt changelogfmt ## Build for the current development platform
@echo "==> Removing old development build..."
@rm -f $(PROJECT_ROOT)/$(DEV_TARGET)
@rm -f $(PROJECT_ROOT)/bin/nomad
@rm -f $(GOPATH)/bin/nomad
@$(MAKE) --no-print-directory \
$(DEV_TARGET) \
GO_TAGS="nomad_test $(NOMAD_UI_TAG)"
@mkdir -p $(PROJECT_ROOT)/bin
@mkdir -p $(GOPATH)/bin
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin
.PHONY: prerelease
prerelease: GO_TAGS=ui
prerelease: check generate ember-dist static-assets ## Generate all the static assets for a Nomad release
.PHONY: release
release: GO_TAGS=ui
release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform.
@echo "==> Results:"
@tree --dirsfirst $(PROJECT_ROOT)/pkg
.PHONY: test
test: ## Run the Nomad test suite and/or the Nomad UI test suite
@if [ ! $(SKIP_NOMAD_TESTS) ]; then \
make test-nomad; \
fi
@if [ $(RUN_UI_TESTS) ]; then \
make test-ui; \
fi
.PHONY: test-nomad
test-nomad: dev ## Run Nomad test suites
@echo "==> Running Nomad test suites:"
@NOMAD_TEST_RKT=1 \
go test $(if $(VERBOSE),-v) \
-cover \
-timeout=900s \
-tags="nomad_test $(if $(HAS_LXC),lxc)" ./... $(if $(VERBOSE), >test.log ; echo $$? > exit-code)
@if [ $(VERBOSE) ] ; then \
bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \
fi
.PHONY: clean
clean: GOPATH=$(shell go env GOPATH)
clean: ## Remove build artifacts
@echo "==> Cleaning build artifacts..."
@rm -rf "$(PROJECT_ROOT)/bin/"
@rm -rf "$(PROJECT_ROOT)/pkg/"
@rm -f "$(GOPATH)/bin/nomad"
.PHONY: travis
travis: ## Run Nomad test suites with output to prevent timeouts under Travis CI
@sh -C "$(PROJECT_ROOT)/scripts/travis.sh"
.PHONY: testcluster
testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary.
vagrant up nomad-server01 \
nomad-server02 \
nomad-server03 \
nomad-client01 \
nomad-client02 \
nomad-client03 \
$(if $(PROVIDER),--provider $(PROVIDER))
.PHONY: static-assets
static-assets: ## Compile the static routes to serve alongside the API
@echo "--> Generating static assets"
@go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui ./ui/dist/...
@mv bindata_assetfs.go command/agent
.PHONY: test-ui
test-ui: ## Run Nomad UI test suite
@echo "--> Installing JavaScript assets"
@cd ui && npm rebuild node-sass
@cd ui && yarn install
@echo "--> Running ember tests"
@cd ui && phantomjs --version
@cd ui && npm test
.PHONY: ember-dist
ember-dist: ## Build the static UI assets from source
@echo "--> Installing JavaScript assets"
@cd ui && yarn install
@cd ui && npm rebuild node-sass
@echo "--> Building Ember application"
@cd ui && npm run build
.PHONY: dev-ui
dev-ui: ember-dist static-assets
@$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in
HELP_FORMAT=" \033[36m%-25s\033[0m %s\n"
.PHONY: help
help: ## Display this usage information
@echo "Valid targets:"
@grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \
sort | \
awk 'BEGIN {FS = ":.*?## "}; \
{printf $(HELP_FORMAT), $$1, $$2}'
@echo ""
@echo "This host will build the following targets if 'make release' is invoked:"
@echo $(ALL_TARGETS) | sed 's/^/ /'