github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/Makefile (about) 1 # Copyright 2018-2020 The OpenEBS Authors. All rights reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # Default behaviour is not to use BUILDX until the Travis workflow is deprecated. 16 BUILDX:=false 17 18 # ============================================================================== 19 # Build Options 20 21 # set the shell to bash in case some environments use sh 22 SHELL:=/bin/bash 23 24 # VERSION is the version of the binary. 25 VERSION:=$(shell git describe --tags --always) 26 27 # Determine the arch/os 28 ifeq (${XC_OS}, ) 29 XC_OS:=$(shell go env GOOS) 30 endif 31 export XC_OS 32 33 ifeq (${XC_ARCH}, ) 34 XC_ARCH:=$(shell go env GOARCH) 35 endif 36 export XC_ARCH 37 38 ARCH:=${XC_OS}_${XC_ARCH} 39 export ARCH 40 41 ifeq (${BASE_DOCKER_IMAGEARM64}, ) 42 BASE_DOCKER_IMAGEARM64 = "arm64v8/ubuntu:18.04" 43 export BASE_DOCKER_IMAGEARM64 44 endif 45 46 ifeq (${BASEIMAGE}, ) 47 ifeq ($(ARCH),linux_arm64) 48 BASEIMAGE:=${BASE_DOCKER_IMAGEARM64} 49 else 50 # The ubuntu:16.04 image is being used as base image. 51 BASEIMAGE:=ubuntu:16.04 52 endif 53 endif 54 export BASEIMAGE 55 56 # The images can be pushed to any docker/image registeries 57 # like docker hub, quay. The registries are specified in 58 # the `build/push` script. 59 # 60 # The images of a project or company can then be grouped 61 # or hosted under a unique organization key like `openebs` 62 # 63 # Each component (container) will be pushed to a unique 64 # repository under an organization. 65 # Putting all this together, an unique uri for a given 66 # image comprises of: 67 # <registry url>/<image org>/<image repo>:<image-tag> 68 # 69 # IMAGE_ORG can be used to customize the organization 70 # under which images should be pushed. 71 # By default the organization name is `openebs`. 72 73 ifeq (${IMAGE_ORG}, ) 74 IMAGE_ORG="openebs" 75 export IMAGE_ORG 76 endif 77 78 # Specify the date of build 79 DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') 80 81 # Specify the docker arg for repository url 82 ifeq (${DBUILD_REPO_URL}, ) 83 DBUILD_REPO_URL="https://github.com/openebs/node-disk-manager" 84 export DBUILD_REPO_URL 85 endif 86 87 # Specify the docker arg for website url 88 ifeq (${DBUILD_SITE_URL}, ) 89 DBUILD_SITE_URL="https://openebs.io" 90 export DBUILD_SITE_URL 91 endif 92 93 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} 94 95 # Initialize the NDM DaemonSet variables 96 # Specify the NDM DaemonSet binary name 97 NODE_DISK_MANAGER=ndm 98 # Specify the sub path under ./cmd/ for NDM DaemonSet 99 BUILD_PATH_NDM=ndm_daemonset 100 # Name of the image for NDM DaemoneSet 101 DOCKER_IMAGE_NDM:=${IMAGE_ORG}/node-disk-manager-${XC_ARCH}:ci 102 103 # Initialize the NDM Operator variables 104 # Specify the NDM Operator binary name 105 NODE_DISK_OPERATOR=ndo 106 # Specify the sub path under ./cmd/ for NDM Operator 107 BUILD_PATH_NDO=manager 108 # Name of the image for ndm operator 109 DOCKER_IMAGE_NDO:=${IMAGE_ORG}/node-disk-operator-${XC_ARCH}:ci 110 111 # Initialize the NDM Exporter variables 112 # Specfiy the NDM Exporter binary name 113 NODE_DISK_EXPORTER=exporter 114 # Specify the sub path under ./cmd/ for NDM Exporter 115 BUILD_PATH_EXPORTER=ndm-exporter 116 # Name of the image for ndm exporter 117 DOCKER_IMAGE_EXPORTER:=${IMAGE_ORG}/node-disk-exporter-${XC_ARCH}:ci 118 119 # Compile binaries and build docker images 120 .PHONY: build 121 build: clean build.common docker.ndm docker.ndo docker.exporter 122 123 .PHONY: build.common 124 build.common: license-check version 125 126 # If there are any external tools need to be used, they can be added by defining a EXTERNAL_TOOLS variable 127 # Bootstrap the build by downloading additional tools 128 .PHONY: bootstrap 129 bootstrap: 130 @for tool in $(EXTERNAL_TOOLS) ; do \ 131 echo "Installing $$tool" ; \ 132 go get -u $$tool; \ 133 done 134 135 .PHONY: install-dep 136 install-dep: 137 @echo "--> Installing external dependencies for building node-disk-manager" 138 @sudo $(PWD)/build/install-dep.sh 139 140 .PHONY: install-test-infra 141 install-test-infra: 142 @echo "--> Installing test infra for running integration tests" 143 # installing test infrastructure is dependent on the platform 144 $(PWD)/build/install-test-infra.sh ${XC_ARCH} 145 146 .PHONY: header 147 header: 148 @echo "----------------------------" 149 @echo "--> node-disk-manager " 150 @echo "----------------------------" 151 @echo 152 153 # -composite: avoid "literal copies lock value from fakePtr" 154 .PHONY: vet 155 vet: 156 go list ./... | grep -v "./vendor/*" | xargs go vet -composites 157 158 .PHONY: fmt 159 fmt: 160 find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l 161 162 163 .PHONY: controller-gen 164 controller-gen: 165 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; 166 167 manifests: controller-gen 168 @echo "+ Generating NDM manifest" 169 $(PWD)/build/generate-manifests.sh 170 171 # shellcheck target for checking shell scripts linting 172 .PHONY: shellcheck 173 shellcheck: getshellcheck 174 find . -type f -name "*.sh" | grep -v "./vendor/*" | xargs /tmp/shellcheck-stable/shellcheck 175 176 .PHONY: getshellcheck 177 getshellcheck: 178 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/ 179 .PHONY: version 180 version: 181 @echo $(VERSION) 182 183 .PHONY: test 184 test: vet fmt 185 @echo "--> Running go test"; 186 $(PWD)/build/test.sh ${XC_ARCH} 187 188 .PHONY: integration-test 189 integration-test: 190 @echo "--> Running integration test" 191 $(PWD)/build/integration-test.sh ${XC_ARCH} 192 193 .PHONY: Dockerfile.ndm 194 Dockerfile.ndm: ./build/ndm-daemonset/Dockerfile.in 195 sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@ 196 197 .PHONY: Dockerfile.ndo 198 Dockerfile.ndo: ./build/ndm-operator/Dockerfile.in 199 sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@ 200 201 .PHONY: Dockerfile.exporter 202 Dockerfile.exporter: ./build/ndm-exporter/Dockerfile.in 203 sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@ 204 205 .PHONY: build.ndm 206 build.ndm: 207 @echo '--> Building node-disk-manager binary...' 208 @pwd 209 @CTLNAME=${NODE_DISK_MANAGER} BUILDPATH=${BUILD_PATH_NDM} sh -c "'$(PWD)/build/build.sh'" 210 @echo '--> Built binary.' 211 @echo 212 213 .PHONY: docker.ndm 214 docker.ndm: build.ndm Dockerfile.ndm 215 @echo "--> Building docker image for ndm-daemonset..." 216 @sudo docker build -t "$(DOCKER_IMAGE_NDM)" ${DBUILD_ARGS} -f Dockerfile.ndm . 217 @echo "--> Build docker image: $(DOCKER_IMAGE_NDM)" 218 @echo 219 220 .PHONY: build.ndo 221 build.ndo: 222 @echo '--> Building node-disk-operator binary...' 223 @pwd 224 @CTLNAME=${NODE_DISK_OPERATOR} BUILDPATH=${BUILD_PATH_NDO} sh -c "'$(PWD)/build/build.sh'" 225 @echo '--> Built binary.' 226 @echo 227 228 .PHONY: docker.ndo 229 docker.ndo: build.ndo Dockerfile.ndo 230 @echo "--> Building docker image for ndm-operator..." 231 @sudo docker build -t "$(DOCKER_IMAGE_NDO)" ${DBUILD_ARGS} -f Dockerfile.ndo . 232 @echo "--> Build docker image: $(DOCKER_IMAGE_NDO)" 233 @echo 234 235 .PHONY: build.exporter 236 build.exporter: 237 @echo '--> Building node-disk-exporter binary...' 238 @pwd 239 @CTLNAME=${NODE_DISK_EXPORTER} BUILDPATH=${BUILD_PATH_EXPORTER} sh -c "'$(PWD)/build/build.sh'" 240 @echo '--> Built binary.' 241 @echo 242 243 .PHONY: docker.exporter 244 docker.exporter: build.exporter Dockerfile.exporter 245 @echo "--> Building docker image for ndm-exporter..." 246 @sudo docker build -t "$(DOCKER_IMAGE_EXPORTER)" ${DBUILD_ARGS} -f Dockerfile.exporter . 247 @echo "--> Build docker image: $(DOCKER_IMAGE_EXPORTER)" 248 @echo 249 250 # Minimum version of protoc should be 3.12 251 .PHONY: protos 252 protos: 253 protoc -I . ndm.proto --go_out=plugins=grpc:. 254 255 .PHONY: deps 256 deps: header 257 @echo '--> Resolving dependencies...' 258 go mod tidy 259 go mod verify 260 go mod vendor 261 @echo '--> Depedencies resolved.' 262 @echo 263 264 .PHONY: clean 265 clean: header 266 @echo '--> Cleaning directory...' 267 rm -rf bin 268 rm -rf ${GOPATH}/bin/${NODE_DISK_MANAGER} 269 rm -rf ${GOPATH}/bin/${NODE_DISK_OPERATOR} 270 rm -rf ${GOPATH}/bin/${NODE_DISK_EXPORTER} 271 rm -rf Dockerfile.ndm 272 rm -rf Dockerfile.ndo 273 rm -rf Dockerfile.exporter 274 @echo '--> Done cleaning.' 275 @echo 276 277 .PHONY: license-check 278 license-check: 279 @echo "--> Checking license header..." 280 @licRes=$$(for file in $$(find . -type f -regex '.*\.sh\|.*\.go\|.*Docker.*\|.*\Makefile*' ! -path './vendor/*' ) ; do \ 281 awk 'NR<=5' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \ 282 done); \ 283 if [ -n "$${licRes}" ]; then \ 284 echo "license header checking failed:"; echo "$${licRes}"; \ 285 exit 1; \ 286 fi 287 @echo "--> Done checking license." 288 @echo 289 290 .PHONY: push 291 push: 292 DIMAGE=${IMAGE_ORG}/node-disk-manager-${XC_ARCH} ./build/push; 293 DIMAGE=${IMAGE_ORG}/node-disk-operator-${XC_ARCH} ./build/push; 294 DIMAGE=${IMAGE_ORG}/node-disk-exporter-${XC_ARCH} ./build/push; 295 296 297 #----------------------------------------------------------------------------- 298 # Target: docker.buildx.ndm docker.buildx.ndo docker.buildx.exporter 299 #----------------------------------------------------------------------------- 300 301 include Makefile.buildx.mk