-
Notifications
You must be signed in to change notification settings - Fork 108
/
Makefile
270 lines (245 loc) · 13.2 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
# Copyright 2022 DigitalOcean
#
# 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.
NAME=do-csi-plugin
OS ?= linux
# Get Go version from go.mod file.
GO_VERSION := $(shell go mod edit -print | grep -E '^go [[:digit:].]*' | cut -d' ' -f2)
ifeq ($(strip $(shell git status --porcelain 2>/dev/null)),)
GIT_TREE_STATE=clean
else
GIT_TREE_STATE=dirty
endif
COMMIT ?= $(shell git rev-parse HEAD)
LDFLAGS ?= -X github.com/digitalocean/csi-digitalocean/driver.version=${VERSION} -X github.com/digitalocean/csi-digitalocean/driver.commit=${COMMIT} -X github.com/digitalocean/csi-digitalocean/driver.gitTreeState=${GIT_TREE_STATE}
PKG ?= github.com/digitalocean/csi-digitalocean/cmd/do-csi-plugin
ifneq ($(VERSION),)
VERSION := $(shell /bin/echo -n "$(VERSION)" | tr -c '[:alnum:]._-' '-')
else
VERSION ?= $(shell cat VERSION)
endif
KUBERNETES_VERSION ?= 1.31.0
DOCKER_REPO ?= digitalocean/do-csi-plugin
CANONICAL_RUNNER_IMAGE = digitalocean/k8s-e2e-test-runner
RUNNER_IMAGE ?= $(CANONICAL_RUNNER_IMAGE)
# Max Volumes to a Single Droplet is 7
INTEGRATION_PARALLEL ?= 7
ifneq ($(RUNNER_IMAGE_TAG_PREFIX),)
RUNNER_IMAGE_TAG_PREFIX := $(shell /bin/echo -n "$(RUNNER_IMAGE_TAG_PREFIX)" | tr -c '[:alnum:]._-' '-')
RUNNER_IMAGE_TAG_PREFIX := $(RUNNER_IMAGE_TAG_PREFIX)-
endif
all: check-unused test
publish: clean compile build push
.PHONY: update-k8s
update-k8s:
scripts/update-k8s.sh $(NEW_KUBERNETES_VERSION)
sed -i.sedbak "s/^KUBERNETES_VERSION.*/KUBERNETES_VERSION ?= $(NEW_KUBERNETES_VERSION)/" Makefile
rm -f Makefile.sedbak
.PHONY: bump-version
bump-version:
@[ "${NEW_VERSION}" ] || ( echo "NEW_VERSION must be set (ex. make NEW_VERSION=v1.x.x bump-version)"; exit 1 )
@(echo ${NEW_VERSION} | grep -E "^v") || ( echo "NEW_VERSION must be a semver ('v' prefix is required)"; exit 1 )
@echo "Bumping VERSION from $(VERSION) to $(NEW_VERSION)"
@echo $(NEW_VERSION) > VERSION
@cp -r deploy/kubernetes/releases/csi-digitalocean-dev deploy/kubernetes/releases/csi-digitalocean-${NEW_VERSION}
@sed -i.sedbak 's#digitalocean/do-csi-plugin:dev#digitalocean/do-csi-plugin:${NEW_VERSION}#g' deploy/kubernetes/releases/csi-digitalocean-${NEW_VERSION}/*
@git add --intent-to-add deploy/kubernetes/releases/csi-digitalocean-${NEW_VERSION}
@sed -i.sedbak '/^# This file is only for development use/d' deploy/kubernetes/releases/csi-digitalocean-${NEW_VERSION}/*
$(eval NEW_DATE = $(shell date +%Y.%m.%d))
@sed -i.sedbak 's/## unreleased/## ${NEW_VERSION} - ${NEW_DATE}/g' CHANGELOG.md
@ echo '## unreleased\n' | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md
@rm -f deploy/kubernetes/releases/csi-digitalocean-${NEW_VERSION}/*.sedbak CHANGELOG.md.sedbak
.PHONY: compile
compile:
@echo "==> Building the project"
# Do not embed VCS data as this seems to fail in the Alpine container. This
# should be fine for now given we manually inject build information.
# TODO(timoreimann): move away from custom build information injection in
# favor of Go native's one.
@docker run --rm -e GOOS=${OS} -e GOARCH=amd64 -v ${PWD}/:/app -w /app golang:${GO_VERSION}-alpine sh -c 'apk add git && go build -buildvcs=false -mod=vendor -o cmd/do-csi-plugin/${NAME} -ldflags "$(LDFLAGS)" ${PKG}'
.PHONY: check-unused
check-unused: vendor
@git diff --exit-code -- go.sum go.mod vendor/ || ( echo "there are uncommitted changes to the Go modules and/or vendor files -- please run 'make vendor' and commit the changes first"; exit 1 )
.PHONY: test
test:
@echo "==> Testing all packages"
@GO111MODULE=on go test -mod=vendor -v ./...
.PHONY: test-e2e
test-e2e:
@echo "==> Started end-to-end tests"
@GO111MODULE=on GOFLAGS=-mod=vendor ./test/e2e/e2e.sh $(E2E_ARGS)
.PHONY: build
build:
@echo "==> Building the docker image"
@docker build -t $(DOCKER_REPO):$(VERSION) cmd/do-csi-plugin -f cmd/do-csi-plugin/Dockerfile
.PHONY: push
push:
# Permit releasing to the canonical container repository only if VERSION adheres to semver.
ifeq ($(DOCKER_REPO),digitalocean/do-csi-plugin)
@echo "${VERSION}" | grep -Eq "^v[0-9]+\.[0-9]+\.[0-9]+(-[[:alnum:]]+)?$$" || ( echo "VERSION \"${VERSION}\" does not adhere to semver"; exit 1 )
endif
@echo "==> Publishing $(DOCKER_REPO):$(VERSION)"
@docker push $(DOCKER_REPO):$(VERSION)
@echo "==> Your image is now available at $(DOCKER_REPO):$(VERSION)"
# runner-build builds the e2e test runner image. Sadly, this is much harder to
# do cache-efficiently than it should be for Docker multi-stage builds since
# those require build targets to be pushed and referenced individually. See
# https://andrewlock.net/caching-docker-layers-on-serverless-build-hosts-with-multi-stage-builds---target,-and---cache-from/
# for more context.
#
# The Makefile target implementation does a lot of pulling and employs
# --cache-from heavily to ensure building the image works as fast as possible.
# In particular, building the layers that compile the individual Kubernetes
# releases can take a fairly long time otherwise.
#
# The build uses the following, customizable variables:
#
# - RUNNER_IMAGE: Overwrite the runner image to be build and pushed.
# - RUNNER_IMAGE_TAG_PREFIX: A prefix before the tag. This is to allow building
# images specific to PRs during CI, using the remote branch name as the
# prefix. For master builds during CI, the prefix will be left empty.
#
# CANONICAL_RUNNER_IMAGE is not overwriteable; it references the canonical
# runner image name as a cache source only.
.PHONY: runner-build
runner-build:
@echo "pulling cache images"
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder || true
@docker pull $(CANONICAL_RUNNER_IMAGE):builder || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 || true
@docker pull $(CANONICAL_RUNNER_IMAGE):tests-1.31 || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 || true
@docker pull $(CANONICAL_RUNNER_IMAGE):tests-1.30 || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 || true
@docker pull $(CANONICAL_RUNNER_IMAGE):tests-1.29 || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28 || true
@docker pull $(CANONICAL_RUNNER_IMAGE):tests-1.28 || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tools || true
@docker pull $(CANONICAL_RUNNER_IMAGE):tools || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)runtime || true
@docker pull $(CANONICAL_RUNNER_IMAGE):runtime || true
@docker pull $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)latest || true
@docker pull $(CANONICAL_RUNNER_IMAGE):latest || true
@echo "building target builder"
@docker build --target builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder -f test/e2e/Dockerfile test/e2e
@echo "building target tests-1.31"
@docker build --target tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 -f test/e2e/Dockerfile test/e2e
@echo "building target tests-1.30"
@docker build --target tests-1.30 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.30 \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 -f test/e2e/Dockerfile test/e2e
@echo "building target tests-1.29"
@docker build --target tests-1.29 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.30 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.29 \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 -f test/e2e/Dockerfile test/e2e
@echo "building target tests-1.28"
@docker build --target tests-1.28 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.30 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.29 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.28 \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28 -f test/e2e/Dockerfile test/e2e
@echo "building target tools"
@docker build --target tools \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.30 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.29 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.28 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tools \
--cache-from $(CANONICAL_RUNNER_IMAGE):tools \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tools -f test/e2e/Dockerfile test/e2e
@echo "building target runtime"
@docker build --target runtime \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.30 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.29 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.28 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tools \
--cache-from $(CANONICAL_RUNNER_IMAGE):tools \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)runtime \
--cache-from $(CANONICAL_RUNNER_IMAGE):runtime \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)runtime -f test/e2e/Dockerfile test/e2e
@echo "building final image"
@docker build \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder \
--cache-from $(CANONICAL_RUNNER_IMAGE):builder \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.31 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.30 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.29 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28 \
--cache-from $(CANONICAL_RUNNER_IMAGE):tests-1.28 \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tools \
--cache-from $(CANONICAL_RUNNER_IMAGE):tools \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)runtime \
--cache-from $(CANONICAL_RUNNER_IMAGE):runtime \
--cache-from $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)latest \
--cache-from $(CANONICAL_RUNNER_IMAGE):latest \
-t $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)latest -f test/e2e/Dockerfile test/e2e
runner-push: runner-build
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)builder
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.31
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.30
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.29
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tests-1.28
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)tools
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)runtime
@docker push $(RUNNER_IMAGE):$(RUNNER_IMAGE_TAG_PREFIX)latest
.PHONY: vendor
vendor:
@GO111MODULE=on go mod tidy
@GO111MODULE=on go mod vendor
.PHONY: clean
clean:
@echo "==> Cleaning releases"
@GOOS=${OS} go clean -i -x ./...