forked from vmware/cloud-director-named-disk-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
259 lines (197 loc) · 10.4 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
LINT_VERSION := 1.51.2
GOSEC_VERSION := "v2.16.0"
GOLANGCI_EXIT_CODE ?= 1
# Set PATH to pick up cached tools. The additional 'sed' is required for cross-platform support of quoting the args to 'env'
SHELL := /usr/bin/env PATH=$(shell echo $(GITROOT)/bin:${PATH} | sed 's/ /\\ /g') bash
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN = $(shell go env GOPATH)/bin
else
GOBIN = $(shell go env GOBIN)
endif
GITCOMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null)
GITROOT ?= $(shell git rev-parse --show-toplevel)
CSI_IMG := cloud-director-named-disk-csi-driver
ARTIFACT_IMG := csi-crs-airgapped
VERSION ?= $(shell cat $(GITROOT)/release/version)
PLATFORM ?= linux/amd64
OS ?= linux
ARCH ?= amd64
CGO ?= 0
CSI_NODE_DRIVER_REGISTRAR_VERSION ?= v2.2.0
CSI_ATTACHER_VERSION ?= v3.2.1
CSI_PROVISIONER_VERSION ?= v2.2.2
GOLANGCI_LINT ?= bin/golangci-lint
GOSEC ?= bin/gosec
SHELLCHECK ?= bin/shellcheck
.PHONY: all
all: vendor lint dev
.PHONY: csi
capvcd: vendor lint docker-build-csi ## Run checks, and build csi docker image.
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: vendor
vendor: ## Update go mod dependencies.
go mod edit -go=1.20
go mod tidy -compat=1.20
go mod vendor
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Run golangci-lint against code.
$(GOLANGCI_LINT) run --issues-exit-code $(GOLANGCI_EXIT_CODE)
.PHONY: gosec
gosec: $(GOSEC) ## Run gosec against code.
$(GOSEC) -conf .gosec.json ./...
.PHONY: shellcheck
shellcheck: $(SHELLCHECK) ## Run shellcheck against code.
find . -name '*.*sh' -not -path '*/vendor/*' | xargs $(SHELLCHECK) --color
.PHONY: lint
lint: lint-deps golangci-lint gosec shellcheck ## Run golangci-lint, gosec, shellcheck.
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix
.PHONY: test
test:
go test -tags testing -v github.com/vmware/cloud-director-named-disk-csi-driver/pkg/vcdclient -cover -count=1
go test -tags testing -v github.com/vmware/cloud-director-named-disk-csi-driver/pkg/config -cover -count=1
.PHONY: integration-test
integration-test: test
go test -tags="testing integration" -v github.com/vmware/cloud-director-named-disk-csi-driver/vcdclient -cover -count=1
##@ Build
.PHONY: build
build: bin ## Build CSI binary. To be used from within a Dockerfile
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=$(CGO) go build -ldflags "-s -w -X github.com/vmware/cloud-director-named-disk-csi-driver/version.Version=$(VERSION)" -o bin/cloud-director-named-disk-csi-driver cmd/csi/main.go
.PHONY: docker-build-csi
docker-build-csi: manifests build
docker build \
--platform $(PLATFORM) \
--file Dockerfile \
--tag $(CSI_IMG):$(VERSION) \
--build-arg CSI_BUILD_DIR=bin \
.
.PHONY: docker-build-artifacts
docker-build-artifacts: release-prep
docker build \
--platform $(PLATFORM) \
--file artifacts/Dockerfile \
--tag $(ARTIFACT_IMG):$(VERSION) \
.
.PHONY: docker-build
docker-build: docker-build-csi docker-build-artifacts ## Build CSI docker image and artifact image.
##@ Gobuild
.PHONY: gobuild
gobuild: vendor manifests release-prep build docker-build docker-archive publish
.PHONY: dev-build
dev-build: VERSION := $(VERSION)-${BUILD_TAG}-$(GITCOMMIT)
dev-build: gobuild
.PHONY: rc-build
rc-build: gobuild
.PHONY: docker-archive
docker-archive:
mkdir -p build/docker
docker save -o build/docker/$(CSI_IMG)_$(VERSION).tar $(CSI_IMG):$(VERSION)
docker save -o build/docker/$(ARTIFACT_IMG)_$(VERSION).tar $(ARTIFACT_IMG):$(VERSION)
gzip build/docker/$(CSI_IMG)_$(VERSION).tar
gzip build/docker/$(ARTIFACT_IMG)_$(VERSION).tar
.PHONY: publish
publish:
cp -R build/docker ${PUBLISH_DIR}
.PHONY: gcr-csi-gobuild
gcr-csi-gobuild:
mkdir -p build/docker
docker pull registry.k8s.io/sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION)
docker pull registry.k8s.io/sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION)
docker pull registry.k8s.io/sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION)
docker tag registry.k8s.io/sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION) sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION)
docker tag registry.k8s.io/sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION) sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION)
docker tag registry.k8s.io/sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION) sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION)
docker save -o build/docker/csi-node-driver-registrar_$(CSI_NODE_DRIVER_REGISTRAR_VERSION).tar sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION)
docker save -o build/docker/csi-attacher_$(CSI_ATTACHER_VERSION).tar sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION)
docker save -o build/docker/csi-provisioner_$(CSI_PROVISIONER_VERSION).tar sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION)
gzip build/docker/csi-node-driver-registrar_$(CSI_NODE_DRIVER_REGISTRAR_VERSION).tar
gzip build/docker/csi-attacher_$(CSI_ATTACHER_VERSION).tar
gzip build/docker/csi-provisioner_$(CSI_PROVISIONER_VERSION).tar
##@ Publish
.PHONY: dev
dev: VERSION := $(VERSION)-$(GITCOMMIT)
dev: git-check release ## Build development images and push to registry.
.PHONY: release
release: docker-build docker-push ## Build release images and push to registry.
.PHONY: release-prep
release-prep: ## Generate BOM and dependencies files.
sed -e "s/__VERSION__/$(VERSION)/g" artifacts/default-csi-controller-crs-airgap.yaml.template > artifacts/csi-controller-crs-airgap.yaml.template
sed -e "s/__VERSION__/$(VERSION)/g" artifacts/default-csi-node-crs-airgap.yaml.template > artifacts/csi-node-crs-airgap.yaml.template
sed -e "s/__VERSION__/$(VERSION)/g" artifacts/bom.json.template > artifacts/bom.json
sed -e "s/__VERSION__/$(VERSION)/g" artifacts/dependencies.txt.template > artifacts/dependencies.txt
.PHONY: manifests
manifests: ## Generate CSI manifests
sed -e "s/__VERSION__/$(VERSION)/g" manifests/csi-controller.yaml.template > manifests/csi-controller.yaml
sed -e "s/__VERSION__/$(VERSION)/g" manifests/csi-controller-crs.yaml.template > manifests/csi-controller-crs.yaml
sed -e "s/__VERSION__/$(VERSION)/g" manifests/csi-node.yaml.template > manifests/csi-node.yaml
sed -e "s/__VERSION__/$(VERSION)/g" manifests/csi-node-crs.yaml.template > manifests/csi-node-crs.yaml
.PHONY: gcr-csi
gcr-csi:
docker pull registry.k8s.io/sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION)
docker pull registry.k8s.io/sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION)
docker pull registry.k8s.io/sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION)
docker tag registry.k8s.io/sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION) projects-stg.registry.vmware.com/vmware-cloud-director/sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION)
docker tag registry.k8s.io/sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION) projects-stg.registry.vmware.com/vmware-cloud-director/sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION)
docker tag registry.k8s.io/sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION) projects-stg.registry.vmware.com/vmware-cloud-director/sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION)
.PHONY: docker-push-csi
docker-push-csi: # Push CSI image to registry.
docker tag $(CSI_IMG)/$(VERSION) projects-stg.registry.vmware.com/vmware-cloud-director/$(CSI_IMG):$(VERSION)
docker push projects-stg.registry.vmware.com/vmware-cloud-director/$(CSI_IMG):$(VERSION)
.PHONY: docker-push-artifacts
docker-push-artifacts: # Push artifacts image to registry
docker tag $(ARTIFACT_IMG):$(VERSION) projects-stg.registry.vmware.com/vmware-cloud-director/$(ARTIFACT_IMG):$(VERSION)
docker push projects-stg.registry.vmware.com/vmware-cloud-director/$(ARTIFACT_IMG):$(VERSION)
.PHONY: docker-push-gcr-csi
docker-push-gcr-csi: gcr-csi ## Publish GCR images to container registry.
docker push projects-stg.registry.vmware.com/vmware-cloud-director/sig-storage/csi-node-driver-registrar:$(CSI_NODE_DRIVER_REGISTRAR_VERSION)
docker push projects-stg.registry.vmware.com/vmware-cloud-director/sig-storage/csi-attacher:$(CSI_ATTACHER_VERSION)
docker push projects-stg.registry.vmware.com/vmware-cloud-director/sig-storage/csi-provisioner:$(CSI_PROVISIONER_VERSION)
.PHONY: docker-push
docker-push: docker-push-csi docker-push-artifacts docker-push-gcr-csi ## Push images to container registry.
##@ Dependencies
.PHONY: lint-deps
lint-deps: $(GOLANGCI_LINT) $(GOSEC) $(SHELLCHECK) ## Download lint dependencies locally.
.PHONY: clean
clean:
rm -rf bin
rm \
artifacts/csi-controller-crs-airgap.yaml.template \
artifacts/csi-node-crs-airgap.yaml.template \
artifacts/bom.json \
artifacts/dependencies.txt
bin:
mkdir -p bin
$(GOLANGCI_LINT): bin
@set -o pipefail && \
wget -q -O - https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GITROOT)/bin v$(LINT_VERSION);
$(GOSEC): bin
@GOBIN=$(GITROOT)/bin go install github.com/securego/gosec/v2/cmd/gosec@${GOSEC_VERSION}
$(SHELLCHECK): bin
@cd bin && \
set -o pipefail && \
wget -q -O - https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.$$(uname).x86_64.tar.xz | tar -xJv --strip-components=1 shellcheck-stable/shellcheck && \
chmod +x $(GITROOT)/bin/shellcheck
.PHONY: git-check
git-check:
@git diff --exit-code --quiet artifacts/ cmd/ manifests/ pkg/ Dockerfile || (echo 'Uncommitted changes found. Please commit your changes before proceeding.'; exit 1)