forked from vmware/vic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
296 lines (234 loc) · 10.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
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
# Copyright 2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO ?= go
GOVERSION ?= go1.6
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ifeq ($(USER),vagrant)
# assuming we are in a shared directory where host arch is different from the guest
BIN_ARCH := -$(OS)
endif
BASE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BIN ?= bin
IGNORE := $(shell mkdir -p $(BIN))
export GOPATH ?= $(shell echo $(CURDIR) | sed -e 's,/src/.*,,')
SWAGGER ?= $(GOPATH)/bin/swagger$(BIN_ARCH)
GOVET ?= $(GOPATH)/bin/vet$(BIN_ARCH)
GOIMPORTS ?= $(GOPATH)/bin/goimports$(BIN_ARCH)
GOLINT ?= $(GOPATH)/bin/golint$(BIN_ARCH)
GVT ?= $(GOPATH)/bin/gvt$(BIN_ARCH)
.PHONY: all tools clean test check \
goversion govet goimports gvt gopath \
isos tethers apiservers copyright
.DEFAULT_GOAL := all
# target aliases - environment variable definition
docker-engine-api := $(BIN)/docker-engine-server
portlayerapi := $(BIN)/port-layer-server
portlayerapi-client := apiservers/portlayer/client/port_layer_client.go
portlayerapi-server := apiservers/portlayer/restapi/server.go
imagec := $(BIN)/imagec
vicadmin := $(BIN)/vicadmin
rpctool := $(BIN)/rpctool
tether-linux := $(BIN)/tether-linux
tether-windows := $(BIN)/tether-windows.exe
appliance := $(BIN)/appliance.iso
appliance-staging := $(BIN)/appliance-staging.tgz
bootstrap := $(BIN)/bootstrap.iso
bootstrap-staging := $(BIN)/bootstrap-staging.tgz
bootstrap-staging-debug := $(BIN)/bootstrap-staging-debug.tgz
bootstrap-debug := $(BIN)/bootstrap-debug.iso
iso-base := $(BIN)/iso-base.tgz
install := $(BIN)/install.sh
go-lint := $(BIN)/.golint
go-vet := $(BIN)/.govet
go-imports := $(BIN)/.goimports
# target aliases - target mapping
docker-engine-api: $(docker-engine-api)
portlayerapi: $(portlayerapi)
portlayerapi-client: $(portlayerapi-client)
portlayerapi-server: $(portlayerapi-server)
imagec: $(imagec)
vicadmin: $(vicadmin)
rpctool: $(rpctool)
tether-linux: $(tether-linux)
tether-windows: $(tether-windows)
appliance: $(appliance)
appliance-staging: $(appliance-staging)
bootstrap: $(bootstrap)
bootstrap-staging: $(bootstrap-staging)
bootstrap-debug: $(bootstrap-debug)
bootstrap-staging-debug: $(bootstrap-staging-debug)
iso-base: $(iso-base)
install: $(install)
swagger: $(SWAGGER)
golint: $(go-lint)
govet: $(go-vet)
goimports: $(go-imports)
# convenience targets
all: components tethers isos install
tools: $(GOIMPORTS) $(GOVET) $(GVT) $(GOLINT) $(SWAGGER) goversion
check: goversion goimports govet golint copyright whitespace
apiservers: $(portlayerapi) $(docker-engine-api)
components: check apiservers $(imagec) $(vicadmin) $(rpctool)
isos: $(appliance) $(bootstrap)
tethers: $(tether-linux) $(tether-windows)
# utility targets
goversion:
@echo checking go version...
@( $(GO) version | grep -q $(GOVERSION) ) || ( echo "Please install $(GOVERSION) (found: $$($(GO) version))" && exit 1 )
$(GOIMPORTS): vendor/manifest
@echo building $(GOIMPORTS)...
$(GO) build -o $(GOIMPORTS) ./vendor/golang.org/x/tools/cmd/goimports
$(GOVET): vendor/manifest
@echo building $(GOVET)...
$(GO) build -o $(GOVET) ./vendor/golang.org/x/tools/cmd/vet
$(GVT):
@echo getting gvt
$(GO) get -u github.com/FiloSottile/gvt
$(GOLINT): vendor/manifest
@echo building $(GOLINT)...
$(GO) build -o $(GOLINT) ./vendor/github.com/golang/lint/golint
$(SWAGGER): vendor/manifest
@echo building $(SWAGGER)...
@$(GO) build -o $(SWAGGER) ./vendor/github.com/go-swagger/go-swagger/cmd/swagger
copyright:
@echo "checking copyright in header..."
scripts/header-check.sh
whitespace:
@echo "checking whitespace..."
scripts/whitespace-check.sh
# exit 1 if golint complains about anything other than comments
golintf = $(GOLINT) $(1) | sh -c "! grep -v 'should have comment'"
$(go-lint): $(GOLINT)
@echo checking go lint...
@ #$(call golintf,github.com/vmware/vic/bootstrap/...) # this is commented out due to number of warnings
@$(call golintf,github.com/vmware/vic/cmd/imagec/...)
@$(call golintf,github.com/vmware/vic/cmd/vicadmin/...)
@$(call golintf,github.com/vmware/vic/pkg/...)
@$(call golintf,github.com/vmware/vic/portlayer/...)
@$(call golintf,github.com/vmware/vic/apiservers/portlayer/restapi/handlers/...)
@$(call golintf,github.com/vmware/vic/apiservers/engine/server/...)
@$(call golintf,github.com/vmware/vic/apiservers/engine/backends/...)
@touch $@
# For use by external tools such as emacs or for example:
# GOPATH=$(make gopath) go get ...
gopath:
@echo -n $(GOPATH)
$(go-imports): $(GOIMPORTS) $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "apiservers/portlayer") $(PORTLAYER_DEPS)
@echo checking go imports...
@! $(GOIMPORTS) -d $$(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1 | egrep -v '^$$'
@touch $@
$(go-vet): $(GOVET) $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "apiservers/portlayer") $(PORTLAYER_DEPS)
@echo checking go vet...
@$(GOVET) -all -shadow $$(find . -type f -name '*.go' -not -path "./vendor/*")
@touch $@
vendor: $(GVT)
@echo restoring vendor
$(GOPATH)/bin/gvt restore
integration-tests: Dockerfile.integration-tests tests/imagec.bats tests/helpers/helpers.bash components
@echo Running integration tests
@docker build -t imagec_tests -f Dockerfile.integration-tests .
docker run -e BIN=$(BIN) --rm imagec_tests
TEST_DIRS=github.com/vmware/vic/cmd/tether/...
TEST_DIRS+=github.com/vmware/vic/cmd/imagec
TEST_DIRS+=github.com/vmware/vic/cmd/vicadmin
TEST_DIRS+=github.com/vmware/vic/cmd/rpctool
TEST_DIRS+=github.com/vmware/vic/portlayer/...
TEST_DIRS+=github.com/vmware/vic/pkg/...
TEST_DIRS+=github.com/vmware/vic/apiservers/portlayer/...
test:
# test everything but vendor
ifdef DRONE
@echo generate coverage report
scripts/coverage.sh $(TEST_DIRS)
else
$(foreach var,$(TEST_DIRS), $(GO) test -v $(TEST_OPTS) $(var);)
endif
$(tether-linux): $(shell find cmd/tether -name '*.go') metadata/*.go
@echo building tether-linux
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -tags netgo -installsuffix netgo -o ./$@ ./cmd/tether
$(tether-windows): $(shell find cmd/tether -name '*.go') metadata/*.go
@echo building tether-windows
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GO) build -tags netgo -installsuffix netgo -o ./$@ ./cmd/tether
$(rpctool): cmd/rpctool/*.go
ifeq ($(OS),linux)
@echo building rpctool
@GOARCH=amd64 GOOS=linux $(GO) build -o ./$@ --ldflags '-extldflags "-static"' ./$(dir $<)
else
@echo skipping rpctool, cannot cross compile cgo
endif
$(vicadmin): cmd/vicadmin/*.go pkg/vsphere/session/*.go
@echo building vicadmin
@GOARCH=amd64 GOOS=linux $(GO) build -o ./$@ --ldflags '-extldflags "-static"' ./$(dir $<)
$(imagec): cmd/imagec/*.go $(portlayerapi-client)
@echo building imagec...
@CGO_ENABLED=0 $(GO) build -o ./$@ --ldflags '-extldflags "-static"' ./$(dir $<)
$(docker-engine-api): $(portlayerapi-client) apiservers/engine/server/*.go apiservers/engine/backends/*.go
ifeq ($(OS),linux)
@echo Building docker-engine-api server...
@$(GO) build -o $@ ./apiservers/engine/server
else
@echo skipping docker-engine-api server, cannot build on non-linux
endif
# Common portlayer dependencies between client and server
PORTLAYER_DEPS ?= apiservers/portlayer/swagger.yml \
apiservers/portlayer/restapi/configure_port_layer.go \
apiservers/portlayer/restapi/options/*.go apiservers/portlayer/restapi/handlers/*.go
$(portlayerapi-client): $(PORTLAYER_DEPS) $(SWAGGER)
@echo regenerating swagger models and operations for Portlayer API client...
@$(SWAGGER) generate client -A PortLayer -t $(realpath $(dir $<)) -f $<
$(portlayerapi-server): $(PORTLAYER_DEPS) $(SWAGGER)
@echo regenerating swagger models and operations for Portlayer API server...
@$(SWAGGER) generate server -A PortLayer -t $(realpath $(dir $<)) -f $<
$(portlayerapi): $(portlayerapi-server) $(shell find pkg/ apiservers/engine/ -name '*.go') metadata/*.go
@echo building Portlayer API server...
@$(GO) build -o $@ ./apiservers/portlayer/cmd/port-layer-server
$(iso-base): isos/base.sh isos/base/*.repo isos/base/isolinux/** isos/base/xorriso-options.cfg
@echo building iso-base docker image
@$< -c $(BIN)/yum-cache.tgz -p $@
# appliance staging - allows for caching of package install
$(appliance-staging): isos/appliance-staging.sh $(iso-base)
@echo staging for VCH appliance
@$< -c $(BIN)/yum-cache.tgz -p $(iso-base) -o $@
# main appliance target - depends on all top level component targets
$(appliance): isos/appliance.sh isos/appliance/* $(rpctool) $(vicadmin) $(imagec) $(portlayerapi) $(docker-engine-api) $(appliance-staging)
@echo building VCH appliance ISO
@$< -p $(appliance-staging) -b $(BIN)
# main bootstrap target
$(bootstrap): isos/bootstrap.sh $(tether-linux) $(rpctool) $(bootstrap-staging) isos/bootstrap/*
@echo "Making bootstrap iso"
@$< -p $(bootstrap-staging) -b $(BIN)
$(bootstrap-debug): isos/bootstrap.sh $(tether-linux) $(rpctool) $(bootstrap-staging-debug) isos/bootstrap/*
@echo "Making bootstrap-debug iso"
@$< -p $(bootstrap-staging-debug) -b $(BIN) -d true
$(bootstrap-staging): isos/bootstrap-staging.sh $(iso-base)
@echo staging for bootstrap
@$< -c $(BIN)/yum-cache.tgz -p $(iso-base) -o $@
$(bootstrap-staging-debug): isos/bootstrap-staging.sh $(iso-base)
@echo staging debug for bootstrap
@$< -c $(BIN)/yum-cache.tgz -p $(iso-base) -o $@ -d true
$(install): install/install.sh
@echo Building installer
@cp $< $@
clean:
rm -rf $(BIN)
@echo removing swagger generated files...
rm -f ./apiservers/portlayer/restapi/doc.go
rm -f ./apiservers/portlayer/restapi/embedded_spec.go
rm -f ./apiservers/portlayer/restapi/server.go
rm -rf ./apiservers/portlayer/client/
rm -rf ./apiservers/portlayer/cmd/
rm -rf ./apiservers/portlayer/models/
rm -rf ./apiservers/portlayer/restapi/operations/
rm -fr ./tests/helpers/bats-assert/
rm -fr ./tests/helpers/bats-support/