-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
224 lines (165 loc) · 7.51 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
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)
CPI_IMG := cloud-provider-for-cloud-director
ARTIFACT_IMG := cpi-crs-airgapped
VERSION ?= $(shell cat $(GITROOT)/release/version)
PLATFORM ?= linux/amd64
OS ?= linux
ARCH ?= amd64
CGO ?= 0
GOLANGCI_LINT ?= bin/golangci-lint
GOSEC ?= bin/gosec
SHELLCHECK ?= bin/shellcheck
.PHONY: all
all: vendor lint dev
.PHONY: cpi
cpi: vendor lint docker-build-cpi ## Run checks, and build cpi 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.22
go mod tidy -compat=1.22
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-provider-for-cloud-director/pkg/vcdclient -cover -count=1
go test -tags testing -v github.com/vmware/cloud-provider-for-cloud-director/pkg/config -cover -count=1
.PHONY: integration-test
integration-test: test
go test -tags="testing integration" -v github.com/vmware/cloud-provider-for-cloud-director/vcdclient -cover -count=1
##@ Gobuild
.PHONY: gobuild
gobuild: vendor manifests release-prep build docker-build docker-archive publish
.PHONY: dev-build
# BUILD_TAG will be set during the build so it is not defined as it's not expected to be used by anything else here.
dev-build: VERSION := $(VERSION)-${BUILD_TAG}-$(GITCOMMIT)
dev-build: gobuild
.PHONY: rc-build
rc-build: gobuild
# docker-archive target saves the artifacts as .tar.gz to build/docker path which gets published as deliverables.
.PHONY: docker-archive
docker-archive:
mkdir -p build/docker
docker save -o build/docker/$(CPI_IMG)_$(VERSION).tar $(CPI_IMG):$(VERSION)
docker save -o build/docker/$(ARTIFACT_IMG)_$(VERSION).tar $(ARTIFACT_IMG):$(VERSION)
gzip build/docker/$(CPI_IMG)_$(VERSION).tar
gzip build/docker/$(ARTIFACT_IMG)_$(VERSION).tar
# publish target publishes all the contents inside of build/docker. PUBLISH_DIR will be set during the build so it is not defined.
.PHONY: publish
publish:
cp -R build/docker ${PUBLISH_DIR}
##@ 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-provider-for-cloud-director/release.Version=$(VERSION)" -o bin/cloud-provider-for-cloud-director cmd/ccm/main.go
.PHONY: docker-build-cpi
docker-build-cpi: manifests build
docker build \
--platform $(PLATFORM) \
--file Dockerfile \
--tag $(CPI_IMG):$(VERSION) \
--build-arg CPI_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-cpi docker-build-artifacts ## Build CPI docker image and artifact image.
##@ 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-cloud-director-ccm-crs-airgap.yaml.template > artifacts/cloud-director-ccm-crs-airgap.yaml.template
sed -e "s/__VERSION__/$(VERSION)/g" artifacts/dependencies.txt.template > artifacts/dependencies.txt
sed -e "s/__VERSION__/$(VERSION)/g" artifacts/bom.json.template > artifacts/bom.json
.PHONY: manifests
manifests: ## Generate CPI manifests
sed -e "s/__VERSION__/$(VERSION)/g" manifests/cloud-director-ccm.yaml.template > manifests/cloud-director-ccm.yaml
sed -e "s/__VERSION__/$(VERSION)/g" manifests/cloud-director-ccm-crs.yaml.template > manifests/cloud-director-ccm-crs.yaml
.PHONY: docker-push-cpi
docker-push-cpi: # Push CPI image to registry.
docker tag $(CPI_IMG):$(VERSION) projects-stg.registry.vmware.com/vmware-cloud-director/$(CPI_IMG):$(VERSION)
docker push projects-stg.registry.vmware.com/vmware-cloud-director/$(CPI_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
docker-push: docker-push-cpi docker-push-artifacts ## 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/cloud-director-ccm-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)