forked from openebs-archive/maya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
394 lines (331 loc) · 14.1 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# Copyright © 2017 The OpenEBS Authors
#
# 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.
include buildscripts/common.mk
# list only maya source code directories
PACKAGES = $(shell go list ./... | grep -v 'vendor\|pkg/client/generated\|tests')
# list maya source code directories along with integration-test code
PACKAGES_IT = $(shell go list ./... | grep 'tests')
# Lint our code. Reference: https://golang.org/cmd/vet/
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
-nilfunc -printf -rangeloops -shift -structtags -unsafeptr
# API_PKG sets namespace where the API resources are defined
API_PKG := github.com/openebs/maya/pkg
# Default arguments for code gen script
# OUTPUT_PKG is the path of directory where you want to keep the generated code
OUTPUT_PKG=github.com/openebs/maya/pkg/client/generated
# APIS_PKG is the path where apis group and schema exists.
APIS_PKG=github.com/openebs/maya/pkg/apis
# GENS is an argument which generates different type of code.
# Possible values: all, deepcopy, client, informers, listers.
GENS=all
# GROUPS_WITH_VERSIONS is the group containing different versions of the resources.
GROUPS_WITH_VERSIONS=openebs.io:v1alpha1
# BOILERPLATE_TEXT_PATH is the boilerplate text(go comment) that is put at the top of every generated file.
# This boilerplate text is nothing but the license information.
BOILERPLATE_TEXT_PATH=buildscripts/custom-boilerplate.go.txt
# ALL_API_GROUPS has the list of all API resources from various groups
ALL_API_GROUPS=\
openebs.io/runtask/v1beta1 \
openebs.io/openebscluster/v1alpha1 \
openebs.io/catalog/v1alpha1 \
openebs.io/kubeassert/v1alpha1 \
openebs.io/upgrade/v1alpha1 \
openebs.io/snapshot/v1alpha1
# Tools required for different make targets or for development purposes
EXTERNAL_TOOLS=\
github.com/golang/dep/cmd/dep \
golang.org/x/tools/cmd/cover \
github.com/axw/gocov/gocov \
gopkg.in/matm/v1/gocov-html \
github.com/ugorji/go/codec/codecgen \
gopkg.in/alecthomas/gometalinter.v1 \
github.com/golang/protobuf/protoc-gen-go
# list only our .go files i.e. exlcudes any .go files from the vendor directory
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
ifeq (${IMAGE_TAG}, )
IMAGE_TAG = ci
export IMAGE_TAG
endif
ifeq (${TRAVIS_TAG}, )
BASE_TAG = ci
export BASE_TAG
else
BASE_TAG = ${TRAVIS_TAG}
export BASE_TAG
endif
CSTOR_BASE_IMAGE= openebs/cstor-base:${BASE_TAG}
# Specify the name for the binaries
MAYACTL=mayactl
APISERVER=maya-apiserver
WEBHOOK=admission-server
POOL_MGMT=cstor-pool-mgmt
VOLUME_MGMT=cstor-volume-mgmt
EXPORTER=maya-exporter
OPENEBS_CLUSTER=openebs-cluster
UPGRADE=upgrade
# Specify the date o build
BUILD_DATE = $(shell date +'%Y%m%d%H%M%S')
include ./buildscripts/provisioner-localpv/Makefile.mk
all: mayactl apiserver-image exporter-image pool-mgmt-image volume-mgmt-image admission-server-image upgrade-image provisioner-localpv-image
mayactl:
@echo "----------------------------"
@echo "--> mayactl "
@echo "----------------------------"
@PNAME="maya" CTLNAME=${MAYACTL} sh -c "'$(PWD)/buildscripts/build.sh'"
initialize: bootstrap
deps:
dep ensure
clean:
go clean -testcache
rm -rf bin
rm -rf ${GOPATH}/bin/${MAYACTL}
rm -rf ${GOPATH}/bin/${APISERVER}
rm -rf ${GOPATH}/bin/${POOL_MGMT}
rm -rf ${GOPATH}/bin/${VOLUME_MGMT}
rm -rf ${GOPATH}/bin/${OPENEBS_CLUSTER}
rm -rf ${GOPATH}/bin/${UPGRADE}
rm -rf ${GOPATH}/pkg/*
release:
@$(MAKE) bin
# Run the bootstrap target once before trying cov
cov:
gocov test ./... | gocov-html > /tmp/coverage.html
@cat /tmp/coverage.html
# Verifies the compilation issues in integratio test
# TODO: Currently we are checking only for integration-test package
precompile:
@echo "--> Running go vet on integration-test"
@for test in $(PACKAGES_IT) ; do \
go vet $$test; \
done
test: format
@echo "--> Running go test" ;
@go test $(PACKAGES)
testv: format
@echo "--> Running go test verbose" ;
@go test -v $(PACKAGES)
cover:
go list ./... | grep -v vendor | xargs -n1 go test --cover
format:
@echo "--> Running go fmt"
@go fmt $(PACKAGES)
# Target to run gometalinter in Travis (deadcode, golint, errcheck, unconvert, goconst)
golint-travis:
@gometalinter.v1 --install
-gometalinter.v1 --config=metalinter.config ./...
# Run the bootstrap target once before trying gometalinter in Develop environment
golint:
@gometalinter.v1 --install
@gometalinter.v1 --vendor --deadline=600s ./...
vet:
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
go get golang.org/x/tools/cmd/vet; \
fi
@echo "--> Running go tool vet ..."
@go tool vet $(VETARGS) ${GOFILES_NOVENDOR} ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "[LINT] Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
fi
@git grep -n `echo "log"".Print"` | grep -v 'vendor/' ; if [ $$? -eq 0 ]; then \
echo "[LINT] Found "log"".Printf" calls. These should use Maya's logger instead."; \
fi
# Bootstrap the build by downloading additional tools
bootstrap:
@for tool in $(EXTERNAL_TOOLS) ; do \
echo "+ Installing $$tool" ; \
go get -u $$tool; \
done
# code generation for custom resources
kubegen2: deepcopy2 clientset2 lister2 informer2
# code generation for custom resources
kubegen1:
./buildscripts/code-gen.sh ${GENS} ${OUTPUT_PKG} ${APIS_PKG} ${GROUPS_WITH_VERSIONS} --go-header-file ${BOILERPLATE_TEXT_PATH}
# code generation for custom resources
kubegen: kubegendelete kubegen1 kubegen2
# deletes generated code by codegen
kubegendelete:
@rm -rf pkg/client/generated/clientset
@rm -rf pkg/client/generated/listers
@rm -rf pkg/client/generated/informers
@rm -rf pkg/client/generated/openebs.io
# code generation for custom resources and protobuf
generated_files: kubegen protobuf
# builds vendored version of deepcopy-gen tool
deepcopy2:
@go install ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
@for apigrp in $(ALL_API_GROUPS) ; do \
echo "+ Generating deepcopy funcs for $$apigrp" ; \
deepcopy-gen \
--input-dirs $(API_PKG)/apis/$$apigrp \
--output-file-base zz_generated.deepcopy \
--go-header-file ./buildscripts/custom-boilerplate.go.txt; \
done
# builds vendored version of client-gen tool
clientset2:
@go install ./vendor/k8s.io/code-generator/cmd/client-gen
@for apigrp in $(ALL_API_GROUPS) ; do \
echo "+ Generating clientsets for $$apigrp" ; \
client-gen \
--fake-clientset=true \
--input $$apigrp \
--input-base $(API_PKG)/apis \
--clientset-path $(API_PKG)/client/generated/$$apigrp/clientset \
--go-header-file ./buildscripts/custom-boilerplate.go.txt; \
done
# builds vendored version of lister-gen tool
lister2:
@go install ./vendor/k8s.io/code-generator/cmd/lister-gen
@for apigrp in $(ALL_API_GROUPS) ; do \
echo "+ Generating lister for $$apigrp" ; \
lister-gen \
--input-dirs $(API_PKG)/apis/$$apigrp \
--output-package $(API_PKG)/client/generated/$$apigrp/lister \
--go-header-file ./buildscripts/custom-boilerplate.go.txt; \
done
# builds vendored version of informer-gen tool
informer2:
@go install ./vendor/k8s.io/code-generator/cmd/informer-gen
@for apigrp in $(ALL_API_GROUPS) ; do \
echo "+ Generating informer for $$apigrp" ; \
informer-gen \
--input-dirs $(API_PKG)/apis/$$apigrp \
--output-package $(API_PKG)/client/generated/$$apigrp/informer \
--versioned-clientset-package $(API_PKG)/client/generated/$$apigrp/clientset/internalclientset \
--listers-package $(API_PKG)/client/generated/$$apigrp/lister \
--go-header-file ./buildscripts/custom-boilerplate.go.txt; \
done
# You might need to use sudo
install: bin/maya/${MAYACTL}
install -o root -g root -m 0755 ./bin/maya/${MAYACTL} /usr/local/bin/${MAYACTL}
#Use this to build cstor-pool-mgmt
cstor-pool-mgmt:
@echo "----------------------------"
@echo "--> cstor-pool-mgmt "
@echo "----------------------------"
@PNAME="cstor-pool-mgmt" CTLNAME=${POOL_MGMT} sh -c "'$(PWD)/buildscripts/build.sh'"
pool-mgmt-image: cstor-pool-mgmt
@echo "----------------------------"
@echo "--> cstor-pool-mgmt image "
@echo "----------------------------"
@cp bin/cstor-pool-mgmt/${POOL_MGMT} buildscripts/cstor-pool-mgmt/
@cd buildscripts/cstor-pool-mgmt && sudo docker build -t openebs/cstor-pool-mgmt:${IMAGE_TAG} --build-arg BASE_IMAGE=${CSTOR_BASE_IMAGE} --build-arg BUILD_DATE=${BUILD_DATE} . --no-cache
@rm buildscripts/cstor-pool-mgmt/${POOL_MGMT}
#Use this to build cstor-volume-mgmt
cstor-volume-mgmt:
@echo "----------------------------"
@echo "--> cstor-volume-mgmt "
@echo "----------------------------"
@PNAME="cstor-volume-mgmt" CTLNAME=${VOLUME_MGMT} sh -c "'$(PWD)/buildscripts/build.sh'"
protobuf:
@echo "----------------------------"
@echo "--> protobuf "
@echo "----------------------------"
@protoc -I $(PWD)/pkg/apis/openebs.io/v1alpha1/ \
-I${GOPATH}/src \
--go_out=plugins=grpc:$(PWD)/pkg/client/generated/cstor-volume-mgmt/v1alpha1 \
$(PWD)/pkg/apis/openebs.io/v1alpha1/cstorvolume.proto
volume-mgmt-image: cstor-volume-mgmt
@echo "----------------------------"
@echo "--> cstor-volume-mgmt image "
@echo "----------------------------"
@cp bin/cstor-volume-mgmt/${VOLUME_MGMT} buildscripts/cstor-volume-mgmt/
@cd buildscripts/cstor-volume-mgmt && sudo docker build -t openebs/cstor-volume-mgmt:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/cstor-volume-mgmt/${VOLUME_MGMT}
# Use this to build only the maya-exporter.
exporter:
@echo "----------------------------"
@echo "--> maya-exporter "
@echo "----------------------------"
@PNAME="exporter" CTLNAME=${EXPORTER} sh -c "'$(PWD)/buildscripts/build.sh'"
# m-exporter image. This is going to be decoupled soon.
exporter-image: exporter
@echo "----------------------------"
@echo "--> m-exporter image "
@echo "----------------------------"
@cp bin/exporter/${EXPORTER} buildscripts/exporter/
@cd buildscripts/exporter && sudo docker build -t openebs/m-exporter:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} --build-arg BASE_IMAGE=${CSTOR_BASE_IMAGE} .
@rm buildscripts/exporter/${EXPORTER}
admission-server-image:
@echo "----------------------------"
@echo "--> admission-server image "
@echo "----------------------------"
@PNAME=${WEBHOOK} CTLNAME=${WEBHOOK} sh -c "'$(PWD)/buildscripts/build.sh'"
@cp bin/${WEBHOOK}/${WEBHOOK} buildscripts/admission-server/
@cd buildscripts/${WEBHOOK} && sudo docker build -t openebs/admission-server:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/${WEBHOOK}/${WEBHOOK}
# Use this to build only the maya apiserver.
apiserver:
@echo "----------------------------"
@echo "--> maya-apiserver "
@echo "----------------------------"
@PNAME="apiserver" CTLNAME=${APISERVER} sh -c "'$(PWD)/buildscripts/build.sh'"
# Currently both mayactl & apiserver binaries are pushed into
# m-apiserver image. This is going to be decoupled soon.
apiserver-image: mayactl apiserver
@echo "----------------------------"
@echo "--> apiserver image "
@echo "----------------------------"
@cp bin/apiserver/${APISERVER} buildscripts/apiserver/
@cp bin/maya/${MAYACTL} buildscripts/apiserver/
@cd buildscripts/apiserver && sudo docker build -t openebs/m-apiserver:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/apiserver/${APISERVER}
@rm buildscripts/apiserver/${MAYACTL}
# build openebs cluster binary
openebs-cluster:
@echo "----------------------------"
@echo "--> ${OPENEBS_CLUSTER} "
@echo "----------------------------"
@PNAME=${OPENEBS_CLUSTER} CTLNAME=${OPENEBS_CLUSTER} sh -c "'$(PWD)/buildscripts/build.sh'"
# build openebs cluster image
openebs-cluster-image: openebs-cluster
@echo "----------------------------"
@echo "--> ${OPENEBS_CLUSTER} image"
@echo "----------------------------"
@cp bin/${OPENEBS_CLUSTER}/${OPENEBS_CLUSTER} buildscripts/${OPENEBS_CLUSTER}/
@cd buildscripts/${OPENEBS_CLUSTER} && sudo docker build -t openebs/${OPENEBS_CLUSTER}:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/${OPENEBS_CLUSTER}/${OPENEBS_CLUSTER}
rhel-apiserver-image: mayactl apiserver
@echo "----------------------------"
@echo "--> rhel based apiserver image"
@echo "----------------------------"
@cp bin/apiserver/${APISERVER} buildscripts/apiserver/
@cp bin/maya/${MAYACTL} buildscripts/apiserver/
@cd buildscripts/apiserver && sudo docker build -t openebs/m-apiserver:${IMAGE_TAG} -f Dockerfile.rhel --build-arg VERSION=${VERSION} .
@rm buildscripts/apiserver/${APISERVER}
@rm buildscripts/apiserver/${MAYACTL}
# Push images
deploy-images:
@DIMAGE="openebs/m-apiserver" ./buildscripts/push
@DIMAGE="openebs/m-exporter" ./buildscripts/push
@DIMAGE="openebs/cstor-pool-mgmt" ./buildscripts/push
@DIMAGE="openebs/cstor-volume-mgmt" ./buildscripts/push
@DIMAGE="openebs/admission-server" ./buildscripts/push
@DIMAGE="openebs/m-upgrade" ./buildscripts/push
@DIMAGE="openebs/provisioner-localpv" ./buildscripts/push
# build upgrade binary
upgrade:
@echo "----------------------------"
@echo "--> ${UPGRADE} "
@echo "----------------------------"
@PNAME=${UPGRADE} CTLNAME=${UPGRADE} CGO_ENABLED=0 sh -c "'$(PWD)/buildscripts/build.sh'"
# build upgrade image
upgrade-image: upgrade
@echo "----------------------------"
@echo "--> ${UPGRADE} image"
@echo "----------------------------"
@cp bin/${UPGRADE}/${UPGRADE} buildscripts/${UPGRADE}/
@cd buildscripts/${UPGRADE} && sudo docker build -t openebs/m-upgrade:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} .
@rm buildscripts/${UPGRADE}/${UPGRADE}
.PHONY: all bin cov integ test vet test-nodep apiserver image apiserver-image golint deploy kubegen kubegen2 generated_files deploy-images admission-server-image upgrade upgrade-image testv