-
Notifications
You must be signed in to change notification settings - Fork 113
/
Makefile
301 lines (251 loc) · 8.98 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
297
298
299
300
301
# Copyright 2018-2020 The OpenEBS Authors. 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.
# Default behaviour is not to use BUILDX until the Travis workflow is deprecated.
BUILDX:=false
# ==============================================================================
# Build Options
# set the shell to bash in case some environments use sh
SHELL:=/bin/bash
# VERSION is the version of the binary.
VERSION:=$(shell git describe --tags --always)
# Determine the arch/os
ifeq (${XC_OS}, )
XC_OS:=$(shell go env GOOS)
endif
export XC_OS
ifeq (${XC_ARCH}, )
XC_ARCH:=$(shell go env GOARCH)
endif
export XC_ARCH
ARCH:=${XC_OS}_${XC_ARCH}
export ARCH
ifeq (${BASE_DOCKER_IMAGEARM64}, )
BASE_DOCKER_IMAGEARM64 = "arm64v8/ubuntu:18.04"
export BASE_DOCKER_IMAGEARM64
endif
ifeq (${BASEIMAGE}, )
ifeq ($(ARCH),linux_arm64)
BASEIMAGE:=${BASE_DOCKER_IMAGEARM64}
else
# The ubuntu:16.04 image is being used as base image.
BASEIMAGE:=ubuntu:16.04
endif
endif
export BASEIMAGE
# 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/node-disk-manager"
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 RELEASE_TAG=${RELEASE_TAG}
# Initialize the NDM DaemonSet variables
# Specify the NDM DaemonSet binary name
NODE_DISK_MANAGER=ndm
# Specify the sub path under ./cmd/ for NDM DaemonSet
BUILD_PATH_NDM=ndm_daemonset
# Name of the image for NDM DaemoneSet
DOCKER_IMAGE_NDM:=${IMAGE_ORG}/node-disk-manager-${XC_ARCH}:ci
# Initialize the NDM Operator variables
# Specify the NDM Operator binary name
NODE_DISK_OPERATOR=ndo
# Specify the sub path under ./cmd/ for NDM Operator
BUILD_PATH_NDO=manager
# Name of the image for ndm operator
DOCKER_IMAGE_NDO:=${IMAGE_ORG}/node-disk-operator-${XC_ARCH}:ci
# Initialize the NDM Exporter variables
# Specfiy the NDM Exporter binary name
NODE_DISK_EXPORTER=exporter
# Specify the sub path under ./cmd/ for NDM Exporter
BUILD_PATH_EXPORTER=ndm-exporter
# Name of the image for ndm exporter
DOCKER_IMAGE_EXPORTER:=${IMAGE_ORG}/node-disk-exporter-${XC_ARCH}:ci
# Compile binaries and build docker images
.PHONY: build
build: clean build.common docker.ndm docker.ndo docker.exporter
.PHONY: build.common
build.common: license-check version
# If there are any external tools need to be used, they can be added by defining a EXTERNAL_TOOLS variable
# Bootstrap the build by downloading additional tools
.PHONY: bootstrap
bootstrap:
@for tool in $(EXTERNAL_TOOLS) ; do \
echo "Installing $$tool" ; \
go get -u $$tool; \
done
.PHONY: install-dep
install-dep:
@echo "--> Installing external dependencies for building node-disk-manager"
@sudo $(PWD)/build/install-dep.sh
.PHONY: install-test-infra
install-test-infra:
@echo "--> Installing test infra for running integration tests"
# installing test infrastructure is dependent on the platform
$(PWD)/build/install-test-infra.sh ${XC_ARCH}
.PHONY: header
header:
@echo "----------------------------"
@echo "--> node-disk-manager "
@echo "----------------------------"
@echo
# -composite: avoid "literal copies lock value from fakePtr"
.PHONY: vet
vet:
go list ./... | grep -v "./vendor/*" | xargs go vet -composites
.PHONY: fmt
fmt:
find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l
.PHONY: controller-gen
controller-gen:
TMP_DIR=$(shell mktemp -d) && cd $$TMP_DIR && go mod init tmp && go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0 && rm -rf $$TMP_DIR;
manifests: controller-gen
@echo "+ Generating NDM manifest"
$(PWD)/build/generate-manifests.sh
# shellcheck target for checking shell scripts linting
.PHONY: shellcheck
shellcheck: getshellcheck
find . -type f -name "*.sh" | grep -v "./vendor/*" | xargs /tmp/shellcheck-stable/shellcheck
.PHONY: getshellcheck
getshellcheck:
wget -c 'https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz' --no-check-certificate -O - | tar -xvJ -C /tmp/
.PHONY: version
version:
@echo $(VERSION)
.PHONY: test
test: vet fmt
@echo "--> Running go test";
$(PWD)/build/test.sh ${XC_ARCH}
.PHONY: integration-test
integration-test:
@echo "--> Running integration test"
$(PWD)/build/integration-test.sh ${XC_ARCH}
.PHONY: Dockerfile.ndm
Dockerfile.ndm: ./build/ndm-daemonset/Dockerfile.in
sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@
.PHONY: Dockerfile.ndo
Dockerfile.ndo: ./build/ndm-operator/Dockerfile.in
sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@
.PHONY: Dockerfile.exporter
Dockerfile.exporter: ./build/ndm-exporter/Dockerfile.in
sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@
.PHONY: build.ndm
build.ndm:
@echo '--> Building node-disk-manager binary...'
@pwd
@CTLNAME=${NODE_DISK_MANAGER} BUILDPATH=${BUILD_PATH_NDM} sh -c "'$(PWD)/build/build.sh'"
@echo '--> Built binary.'
@echo
.PHONY: docker.ndm
docker.ndm: build.ndm Dockerfile.ndm
@echo "--> Building docker image for ndm-daemonset..."
@sudo docker build -t "$(DOCKER_IMAGE_NDM)" ${DBUILD_ARGS} -f Dockerfile.ndm .
@echo "--> Build docker image: $(DOCKER_IMAGE_NDM)"
@echo
.PHONY: build.ndo
build.ndo:
@echo '--> Building node-disk-operator binary...'
@pwd
@CTLNAME=${NODE_DISK_OPERATOR} BUILDPATH=${BUILD_PATH_NDO} sh -c "'$(PWD)/build/build.sh'"
@echo '--> Built binary.'
@echo
.PHONY: docker.ndo
docker.ndo: build.ndo Dockerfile.ndo
@echo "--> Building docker image for ndm-operator..."
@sudo docker build -t "$(DOCKER_IMAGE_NDO)" ${DBUILD_ARGS} -f Dockerfile.ndo .
@echo "--> Build docker image: $(DOCKER_IMAGE_NDO)"
@echo
.PHONY: build.exporter
build.exporter:
@echo '--> Building node-disk-exporter binary...'
@pwd
@CTLNAME=${NODE_DISK_EXPORTER} BUILDPATH=${BUILD_PATH_EXPORTER} sh -c "'$(PWD)/build/build.sh'"
@echo '--> Built binary.'
@echo
.PHONY: docker.exporter
docker.exporter: build.exporter Dockerfile.exporter
@echo "--> Building docker image for ndm-exporter..."
@sudo docker build -t "$(DOCKER_IMAGE_EXPORTER)" ${DBUILD_ARGS} -f Dockerfile.exporter .
@echo "--> Build docker image: $(DOCKER_IMAGE_EXPORTER)"
@echo
# Minimum version of protoc should be 3.12
.PHONY: protos
protos:
protoc -I . ndm.proto --go_out=plugins=grpc:.
.PHONY: deps
deps: header
@echo '--> Resolving dependencies...'
go mod tidy
go mod verify
go mod vendor
@echo '--> Depedencies resolved.'
@echo
.PHONY: clean
clean: header
@echo '--> Cleaning directory...'
rm -rf bin
rm -rf ${GOPATH}/bin/${NODE_DISK_MANAGER}
rm -rf ${GOPATH}/bin/${NODE_DISK_OPERATOR}
rm -rf ${GOPATH}/bin/${NODE_DISK_EXPORTER}
rm -rf Dockerfile.ndm
rm -rf Dockerfile.ndo
rm -rf Dockerfile.exporter
@echo '--> Done cleaning.'
@echo
.PHONY: license-check
license-check:
@echo "--> Checking license header..."
@licRes=$$(for file in $$(find . -type f -regex '.*\.sh\|.*\.go\|.*Docker.*\|.*\Makefile*' ! -path './vendor/*' ) ; do \
awk 'NR<=5' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi
@echo "--> Done checking license."
@echo
.PHONY: push
push:
DIMAGE=${IMAGE_ORG}/node-disk-manager-${XC_ARCH} ./build/push;
DIMAGE=${IMAGE_ORG}/node-disk-operator-${XC_ARCH} ./build/push;
DIMAGE=${IMAGE_ORG}/node-disk-exporter-${XC_ARCH} ./build/push;
#-----------------------------------------------------------------------------
# Target: docker.buildx.ndm docker.buildx.ndo docker.buildx.exporter
#-----------------------------------------------------------------------------
include Makefile.buildx.mk