-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
executable file
·279 lines (237 loc) · 9.85 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
# vim: set foldmethod=indent foldnestmax=1 foldcolumn=1:
EUID := $(shell id -u -r)
ifneq ($(EUID),0)
_SUDO = sudo
endif
# CICD defines _GITLAB_USER and other vars, and so CICD should not to include Makefile-vars-git-ignored.
# See Makefile-vars-git-ignored for and example. This file is not checked in by design.
ifneq ($(_GITLAB_USER),gitlab-user-name)
include Makefile-vars-git-ignored
endif
include Makefile-help
include Makefile-git
include Makefile-e2e
include Makefile-release
include Makefile-metrics
_GOCMD ?= $(shell which go)
# Go parameters.
# Timestamp go binary. See var compileDate in main.go.
_GOBUILD = $(_GOCMD) build -ldflags "-X main.compileDate=$$(date -u +%Y-%m-%d_%H:%M:%S_%Z) -X main.gitHash=$$(git rev-parse HEAD) -X main.version=$(_IMAGE_TAG) -X main.goVersion='$$(go version | sed 's/ /_/g')"
_GOCLEAN = $(_GOCMD) clean
_GOTEST = $(_GOCMD) test
_GOMOD = $(_GOCMD) mod
_GOFMT = gofmt
_GOLINT = golangci-lint
_LOCALDIR ?= $(shell pwd)
# Docker image tag. Read from env or use default
_IMAGE_TAG ?= v2.18.0
_GITLAB_REPO = git.infinidat.com:4567
_BINARY_NAME = infinibox-csi-driver
_DRIVER_IMAGE = infinidat-csi-driver
_art_dir = artifact
# For Development Build #################################################################
# Docker.io username and tag
_DOCKER_USER = infinidat
_DOCKER_BASE_IMAGE = redhat/ubi9:latest
# For Production Build ##################################################################
ifeq ($(env),prod)
_IMAGE_TAG=$(_IMAGE_TAG)
# For Production
# Do not change following values unless change in production version or username
# For docker.io
_DOCKER_USER=infinidat
_IMAGE_TAG=$(_IMAGE_TAG)
endif
# For Production Build ##################################################################
##@ Go
.PHONY: clean
clean: ## Clean source.
$(_GOCLEAN)
rm -f $(_BINARY_NAME)
.PHONY: build
build: ## Build source.
@echo -e $(_begin)
$(_GOBUILD) -o $(_BINARY_NAME) -v
make -f Makefile-iboxreplica build
@echo -e $(_finish)
.PHONY: build-e2e
build-e2e: ## Build e2e source.
@echo -e $(_begin)
go test -c ./e2e/fc/fc_test.go -o /tmp/e2e -v
go test -c ./e2e/fcanno/fc_test.go -o /tmp/e2e -v
#go test -c ./e2e/grpc/listvolumes_test.go -o /tmp/e2e -v
go test -c ./e2e/iscsi/iscsi_test.go -o /tmp/e2e -v
go test -c ./e2e/iscsianno/iscsi_test.go -o /tmp/e2e -v
go test -c ./e2e/iscsichap/iscsichap_test.go -o /tmp/e2e -v
go test -c ./e2e/iscsimutualchap/iscsimutualchap_test.go -o /tmp/e2e -v
go test -c ./e2e/metrics/metrics_test.go -o /tmp/e2e -v
go test -c ./e2e/nfs/nfs_test.go -o /tmp/e2e -v
go test -c ./e2e/nfsanno/nfs_test.go -o /tmp/e2e -v
go test -c ./e2e/treeq/*.go -o /tmp/e2e -v
go test -c ./e2e/treeqanno/treeq_test.go -o /tmp/e2e -v
@echo -e $(_finish)
.PHONY: rebuild
rebuild: clean ## Rebuild source (all packages)
$(_GOBUILD) -o $(_BINARY_NAME) -v -a
.PHONY: test
test: build ## Unit test source.
@echo -e $(_begin)
$(_GOTEST) -v ./... -tags unit
@echo -e $(_finish)
.PHONY: test-one-thing
test-one-thing: build lint ## Unit test source, but just run one test.
@echo -e $(_begin)
@printf "\nFrom $(_TEST_ONE_THING_DIR)/, running test $(_TEST_ONE_THING)\n\n"
@sleep 1
@cd "$(_TEST_ONE_THING_DIR)" && \
$(_GOTEST) -v -run "$(_TEST_ONE_THING)" \
&& printf "\nTest passed = From $(_TEST_ONE_THING_DIR)/, ran test $(_TEST_ONE_THING)\n\n" \
|| (printf "\nTest failed - From $(_TEST_ONE_THING_DIR)/, ran test $(_TEST_ONE_THING)\n\n"; false)
@echo -e $(_finish)
.PHONY: test-find-fails
test-find-fails: ## Find and summarize failing tests.
@echo -e $(_begin)
@$(_make) test | grep " --- FAIL:"
@echo -e $(_finish)
.PHONY: lint
lint: build ## Lint source.
@echo -e $(_begin)
@$(_GOLINT) run
@echo -e $(_finish)
.PHONY: fmt
fmt: build ## Format and simplify source.
@echo -e $(_begin)
$(_GOFMT) -s -w .
@echo -e $(_finish)
.PHONY: modverify
modverify: ## Verify dependencies have expected content.
$(_GOMOD) verify
.PHONY: modtidy
modtidy: ## Add missing and remove unused modules.
$(_GOMOD) tidy
.PHONY: moddownload
moddownload: ## Download modules to local cache.
$(_GOMOD) download
##@ Cross compilation
.PHONY: build-linux
build-linux: ## Cross compile CSI driver for Linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(_GOBUILD) -o $(_BINARY_NAME) -v
##@ Docker
.PHONY: image
image: build lint test ## Build and tag CSI driver docker image.
@echo -e $(_begin)
@echo "Pulling base image $(_DOCKER_BASE_IMAGE)"
@docker pull $(_DOCKER_BASE_IMAGE)
@export HEAD=$$(git rev-parse --short HEAD); \
export BLAME_MACHINE=$$(hostname); \
export BLAME_USER=$${USER}; \
export BLAME_BUILD_TIME="$$(date)"; \
echo "Building CSI driver image [$(_IMAGE_TAG)] from commit [$$HEAD] at [$$BLAME_BUILD_TIME]"; \
docker build $(OPTIONAL_DOCKER_BUILD_FLAGS) -t "$(_DOCKER_USER)/$(_DRIVER_IMAGE):$(_IMAGE_TAG)" \
--build-arg IMAGE_TAG="$(_IMAGE_TAG)" \
--build-arg VCS_REF="$$HEAD" \
--build-arg BLAME_MACHINE="$$BLAME_MACHINE" \
--build-arg BLAME_USER="$$BLAME_USER" \
--build-arg BLAME_BUILD_TIME="$$BLAME_BUILD_TIME" \
--pull \
-f Dockerfile .
@# TODO tag cmd needs review.
docker tag $(_DOCKER_USER)/$(_DRIVER_IMAGE):$(_IMAGE_TAG) $(_GITLAB_USER)/infinidat-csi-driver/$(_DRIVER_IMAGE):$(_IMAGE_TAG)
@echo -e $(_finish)
.PHONY: docker-login-docker
docker-login-docker: ## Login to Dockerhub.
@docker login
.PHONY: docker-pull-gitlab
docker-pull-gitlab: ## Pull all images using tag, e.g. _IMAGE_TAG=v2.18.0 make docker-pull-gitlab
@echo -e $(_begin)
@declare -a images=($(_IMAGE_NAMES)); \
for image in $${images[@]}; do \
docker pull $(_GITLAB_REPO)/host-opensource/infinidat-csi-releases/$${image}:$(_IMAGE_TAG) || \
exit 1; \
done
@echo -e $(_finish)
.PHONY: image-push
image-push: ## Tag and push CSI driver image to gitlab.
$(eval _TARGET_IMAGE=$(_GITLAB_REPO)/$(_GITLAB_USER)/infinidat-csi-driver/$(_DRIVER_IMAGE):$(_IMAGE_TAG))
docker tag $(_GITLAB_USER)/infinidat-csi-driver/$(_DRIVER_IMAGE):$(_IMAGE_TAG) $(_TARGET_IMAGE)
docker push $(_GITLAB_REPO)/$(_GITLAB_USER)/infinidat-csi-driver/$(_DRIVER_IMAGE):$(_IMAGE_TAG)
.PHONY: docker-push-redhat
docker-push-redhat: ## Login, tag and push to Red Hat.
@# Ref: https://connect.redhat.com/projects/5e9f4fa0ebed1415210b4b24/images/upload-image
@echo "The password is a token acquired by https://connect.redhat.com/projects/5e9f4fa0ebed1415210b4b24/images/upload-image"
docker login -u unused scan.connect.redhat.com
docker tag $(_GITLAB_REPO)/$(_GITLAB_USER)/$(_DRIVER_IMAGE):$(_IMAGE_TAG) scan.connect.redhat.com/ospid-956ccd64-1dcf-4d00-ba98-336497448906/$(_DRIVER_IMAGE):$(_IMAGE_TAG)
docker push scan.connect.redhat.com/ospid-956ccd64-1dcf-4d00-ba98-336497448906/$(_DRIVER_IMAGE):$(_IMAGE_TAG)
.PHONY: docker-push-all
docker-push-all: image-push docker-push-redhat docker-push-dockerhub ## Push to both Gitlab, Red Hat and Dockerhub.
.PHONY: buildlocal
buildlocal: build docker-build clean
.PHONY: all
all: build image image-push clean
.PHONY: docker-image-save
docker-image-save: ## Save image to gzipped tar file to _art_dir.
mkdir -p $(_art_dir) && \
docker save $(_DOCKER_USER)/$(_DRIVER_IMAGE):$(_IMAGE_TAG) \
| gzip > ./$(_art_dir)/$(_DRIVER_IMAGE)_$(_IMAGE_TAG)_docker-image.tar.gz
.PHONY: docker-helm-chart-save
docker-helm-chart-save: ## Save the helm chart to a tarball in _art_dir.
mkdir -p $(_art_dir) && \
tar cvfz ./$(_art_dir)/$(_DOCKER_IMAGE)_$(_IMAGE_TAG)_helm-chart.tar.gz deploy/helm
@# --exclude='*.un~'
.PHONY: docker-save
docker-save: docker-image-save docker-helm-chart-save ## Save the image and the helm chart to the _art_dir so that they may be provided to others.
.PHONY: docker-load-help
docker-load-help: ## Show a hint for how to load a docker image.
@echo "docker load < <docker image tar file>"
.PHONY: docker-rmi-dangling
docker-rmi-dangling: ## Remove docker images that are dangling to recover disk space.
@echo -e $(_begin)
docker rmi $$(docker images -q -f dangling=true)
@echo -e $(_finish)
.PHONY: docker-push-host-opensource
docker-push-host-opensource: ## Push CSI driver images to host-opensource.
@echo -e $(_begin)
docker tag git.infinidat.com:4567/$(_GITLAB_USER)/infinidat-csi-driver/infinidat-csi-driver:$(_IMAGE_TAG) \
git.infinidat.com:4567/host-opensource/infinidat-csi-driver/infinidat-csi-driver:$(_IMAGE_TAG)
docker push git.infinidat.com:4567/host-opensource/infinidat-csi-driver/infinidat-csi-driver:$(_IMAGE_TAG)
@echo -e $(_finish)
.PHONY: docker-push-dockerhub
docker-push-dockerhub: docker-login-docker ## Push host-opensource CSI driver images to dockerhub.
@echo -e $(_begin)
@declare -a images=($(_IMAGE_NAMES)); \
for image in $${images[@]}; do \
docker tag $(_GITLAB_REPO)/host-opensource/infinidat-csi-releases/$${image}:$(_IMAGE_TAG) \
infinidat/$${image}:$(_IMAGE_TAG) && \
docker push infinidat/$${image}:$(_IMAGE_TAG) || \
exit 1; \
done
@echo -e $(_finish)
.PHONY: github-push
_GIT_REMOTE ?= [email protected]:Infinidat/infinibox-csi-driver.git
_GIT_PUSH_OPTIONS ?=
github-push: ## Push develop to Github with optional git push options.
@echo -e $(_begin)
git push $(_GIT_PUSH_OPTIONS) "$(_GIT_REMOTE)" develop:develop
@echo -e $(_finish)
.PHONY: version
version: ## Show tool versions.
@echo -e $(_begin)
@$(_GOCMD) version
@echo "_IMAGE_TAG: $(_IMAGE_TAG)"
@echo -e $(_finish)
# Force the _check-make-vars-defined recipe to always run. Verify our make variables have been defined.
# While Makefile will not usually have changed, its prerequisite will have to run regardless.
# Do not use .PHONY on this Makefile rule.
Makefile: _check-make-vars-defined
.PHONY: _check-make-vars-defined
_check-make-vars-defined:
@#Verify our make variables have been defined.
ifndef _GITLAB_USER
$(error _GITLAB_USER is not set)
endif
ifndef _TEST_ONE_THING_DIR
$(error _TEST_ONE_THING_DIR is not set)
endif
ifndef _TEST_ONE_THING
$(error _TEST_ONE_THING is not set)
endif