-
Notifications
You must be signed in to change notification settings - Fork 201
/
GNUmakefile
345 lines (284 loc) · 10.3 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
# 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 the source code directories
PACKAGES = $(shell go list ./... | grep -v 'vendor\|pkg/client/generated\|tests')
# list only the integration tests code directories
PACKAGES_IT = $(shell go list ./... | grep -v 'vendor\|pkg/client/generated' | grep 'tests')
GO111MODULE ?= on
export GO111MODULE
# 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/upgrade/v1alpha1 \
openebs.io/snapshot/v1 \
openebs.io/ndm/v1alpha1
# Tools required for different make targets or for development purposes
EXTERNAL_TOOLS=\
golang.org/x/tools/cmd/cover \
github.com/axw/gocov/gocov \
gopkg.in/matm/v1/gocov-html \
github.com/golang/protobuf/[email protected]
# 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:v%=%)
export BASE_TAG
endif
# The images can be pushed to any docker/image registeries
# like docker hub, quay. The registries are specified in
# the `build/push` script.
#
# The images of a project or company can then be grouped
# or hosted under a unique organization key like `openebs`
#
# Each component (container) will be pushed to a unique
# repository under an organization.
# Putting all this together, an unique uri for a given
# image comprises of:
# <registry url>/<image org>/<image repo>:<image-tag>
#
# IMAGE_ORG can be used to customize the organization
# under which images should be pushed.
# By default the organization name is `openebs`.
ifeq (${IMAGE_ORG}, )
IMAGE_ORG = openebs
export IMAGE_ORG
endif
# Specify the date of build
DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Specify the docker arg for repository url
ifeq (${DBUILD_REPO_URL}, )
DBUILD_REPO_URL="https://github.com/openebs/maya"
export DBUILD_REPO_URL
endif
# Specify the docker arg for website url
ifeq (${DBUILD_SITE_URL}, )
DBUILD_SITE_URL="https://openebs.io"
export DBUILD_SITE_URL
endif
export DBUILD_ARGS=--build-arg DBUILD_DATE=${DBUILD_DATE} --build-arg DBUILD_REPO_URL=${DBUILD_REPO_URL} --build-arg DBUILD_SITE_URL=${DBUILD_SITE_URL} --build-arg ARCH=${ARCH}
# Specify the name of cstor-base image
CSTOR_BASE_IMAGE_AMD64= ${IMAGE_ORG}/cstor-base:${BASE_TAG}
export CSTOR_BASE_IMAGE_AMD64
ifeq (${CSTOR_BASE_IMAGE_ARM64}, )
CSTOR_BASE_IMAGE_ARM64= ${IMAGE_ORG}/cstor-base:${BASE_TAG}
export CSTOR_BASE_IMAGE_ARM64
endif
# Specify the name of base image for ARM64
ifeq (${BASE_DOCKER_IMAGE_ARM64}, )
BASE_DOCKER_IMAGE_ARM64 = "arm64v8/ubuntu:18.04"
export BASE_DOCKER_IMAGE_ARM64
endif
# Specify the name of base image for PPC64LE
ifeq (${BASE_DOCKER_IMAGE_PPC64LE}, )
BASE_DOCKER_IMAGE_PPC64LE = "ubuntu:18.04"
export BASE_DOCKER_IMAGE_PPC64LE
endif
include ./buildscripts/mayactl/Makefile.mk
include ./buildscripts/apiserver/Makefile.mk
include ./buildscripts/upgrade/Makefile.mk
include ./buildscripts/cstor-pool-mgmt/Makefile.mk
include ./buildscripts/cstor-volume-mgmt/Makefile.mk
include ./buildscripts/admission-server/Makefile.mk
.PHONY: all
all: compile-tests apiserver-image pool-mgmt-image volume-mgmt-image \
admission-server-image upgrade-image
.PHONY: all.arm64
all.arm64: apiserver-image.arm64 pool-mgmt-image.arm64 volume-mgmt-image.arm64 \
admission-server-image.arm64 upgrade-image.arm64
.PHONY: initialize
initialize: bootstrap
.PHONY: deps
deps:
@echo "--> Tidying up submodules"
@go mod tidy
@echo "--> Veryfying submodules"
@go mod verify
.PHONY: verify-deps
verify-deps: deps
@if !(git diff --quiet HEAD -- go.sum go.mod); then \
echo "go module files are out of date, please commit the changes to go.mod and go.sum"; exit 1; \
fi
.PHONY: vendor
vendor: go.mod go.sum deps
@go mod vendor
.PHONY: clean
clean: cleanup-upgrade
go clean -testcache
rm -rf bin
rm -rf ${GOPATH}/pkg/*
.PHONY: release
release:
@$(MAKE) bin
# Run the bootstrap target once before trying cov
.PHONY: cov
cov:
gocov test ./... | gocov-html > /tmp/coverage.html
@cat /tmp/coverage.html
# Verifies compilation issues if any in integration test code
.PHONY: compile-tests
compile-tests:
@echo "--> Running go vet on tests"
@for test in $(PACKAGES_IT) ; do \
go vet $$test; \
done
.PHONY: test
test: format
@echo "--> Running go test" ;
@go test $(PACKAGES)
.PHONY: testv
testv: format
@echo "--> Running go test verbose" ;
@go test -v $(PACKAGES)
.PHONY: cover
cover:
go list ./... | grep -v vendor | xargs -n1 go test --cover
.PHONY: format
format:
@echo "--> Running go fmt"
@go fmt $(PACKAGES) $(PACKAGES_IT)
# Target to run gometalinter in Travis (deadcode, golint, errcheck, unconvert, goconst)
.PHONY: golint-travis
golint-travis:
@gometalinter.v1 --install
-gometalinter.v1 --config=metalinter.config ./...
# Run the bootstrap target once before trying gometalinter in Develop environment
.PHONY: golint
golint:
@gometalinter.v1 --install
@gometalinter.v1 --vendor --deadline=600s ./...
.PHONY: vet
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
.PHONY: bootstrap
bootstrap:
@for tool in $(EXTERNAL_TOOLS) ; do \
echo "+ Installing $$tool" ; \
cd && GO111MODULE=on go get $$tool; \
done
# code generation for custom resources
.PHONY: kubegen2
kubegen2: deepcopy2 clientset2 lister2 informer2
# code generation for custom resources
.PHONY: kubegen1
kubegen1:
./buildscripts/code-gen.sh ${GENS} ${OUTPUT_PKG} ${APIS_PKG} ${GROUPS_WITH_VERSIONS} --go-header-file ${BOILERPLATE_TEXT_PATH}
# code generation for custom resources
.PHONY: kubegen
kubegen: kubegendelete kubegen1 kubegen2
# deletes generated code by codegen
.PHONY: kubegendelete
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
.PHONY: generated_files
generated_files: kubegen protobuf
# builds vendored version of deepcopy-gen tool
.PHONY: deepcopy2
deepcopy2:
@go install -mod=vendor ./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
.PHONY: clientset2
clientset2:
@go install -mod=vendor ./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
.PHONY: lister2
lister2:
@go install -mod=vendor ./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
.PHONY: informer2
informer2:
@go install -mod=vendor ./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
.PHONY: install
install: bin/maya/${MAYACTL}
install -o root -g root -m 0755 ./bin/maya/${MAYACTL} /usr/local/bin/${MAYACTL}
# Push images
.PHONY: deploy-images
deploy-images:
@./buildscripts/deploy.sh
include Makefile.buildx.mk