-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
352 lines (300 loc) · 13 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
SHELL := /bin/bash
include common.mk
OS ?= linux
ARCH ?= $(shell go env GOARCH)
APP_NAME = embedded-cluster
ADMIN_CONSOLE_CHART_REPO_OVERRIDE =
ADMIN_CONSOLE_IMAGE_OVERRIDE =
ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE =
ADMIN_CONSOLE_KURL_PROXY_IMAGE_OVERRIDE =
K0S_VERSION = v1.30.5+k0s.0-ec.1
K0S_GO_VERSION = v1.30.5+k0s.0
PREVIOUS_K0S_VERSION ?= v1.29.9+k0s.0-ec.0
PREVIOUS_K0S_GO_VERSION ?= v1.29.9+k0s.0
K0S_BINARY_SOURCE_OVERRIDE =
TROUBLESHOOT_VERSION = v0.107.4
KOTS_VERSION = v$(shell awk '/^version/{print $$2}' pkg/addons/adminconsole/static/metadata.yaml | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
# When updating KOTS_BINARY_URL_OVERRIDE, also update the KOTS_VERSION above or
# scripts/ci-upload-binaries.sh may find the version in the cache and not upload the overridden binary.
KOTS_BINARY_URL_OVERRIDE =
# For dev env, build the kots binary in the kots repo with "make kots-linux-arm64" and set this to "../kots/bin/kots"
KOTS_BINARY_FILE_OVERRIDE =
# TODO: move this to a manifest file
LOCAL_ARTIFACT_MIRROR_IMAGE ?= proxy.replicated.com/anonymous/replicated/embedded-cluster-local-artifact-mirror:$(VERSION)
# These are used to override the binary urls in dev and e2e tests
METADATA_K0S_BINARY_URL_OVERRIDE =
METADATA_KOTS_BINARY_URL_OVERRIDE =
METADATA_OPERATOR_BINARY_URL_OVERRIDE =
ifeq ($(K0S_VERSION),v1.30.5+k0s.0-ec.1)
K0S_BINARY_SOURCE_OVERRIDE = https://tf-staging-embedded-cluster-bin.s3.amazonaws.com/custom-k0s-binaries/k0s-v1.30.5%2Bk0s.0-ec.1-$(ARCH)
else ifeq ($(K0S_VERSION),v1.29.9+k0s.0-ec.0)
K0S_BINARY_SOURCE_OVERRIDE = https://tf-staging-embedded-cluster-bin.s3.amazonaws.com/custom-k0s-binaries/k0s-v1.29.9%2Bk0s.0-ec.0-$(ARCH)
else ifeq ($(K0S_VERSION),v1.28.14+k0s.0-ec.0)
K0S_BINARY_SOURCE_OVERRIDE = https://tf-staging-embedded-cluster-bin.s3.amazonaws.com/custom-k0s-binaries/k0s-v1.28.14%2Bk0s.0-ec.0-$(ARCH)
endif
ifneq ($(KOTS_BINARY_FILE_OVERRIDE),)
KOTS_VERSION = kots-dev-$(shell shasum -a 256 $(KOTS_BINARY_FILE_OVERRIDE) | cut -c1-8)
endif
LD_FLAGS = \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.K0sVersion=$(K0S_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.Version=$(VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.TroubleshootVersion=$(TROUBLESHOOT_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.LocalArtifactMirrorImage=$(LOCAL_ARTIFACT_MIRROR_IMAGE) \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.K0sBinaryURLOverride=$(METADATA_K0S_BINARY_URL_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.KOTSBinaryURLOverride=$(METADATA_KOTS_BINARY_URL_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/versions.OperatorBinaryURLOverride=$(METADATA_OPERATOR_BINARY_URL_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.ChartRepoOverride=$(ADMIN_CONSOLE_CHART_REPO_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.KurlProxyImageOverride=$(ADMIN_CONSOLE_KURL_PROXY_IMAGE_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.KotsVersion=$(KOTS_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.AdminConsoleChartRepoOverride=$(ADMIN_CONSOLE_CHART_REPO_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.AdminConsoleImageOverride=$(ADMIN_CONSOLE_IMAGE_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.AdminConsoleMigrationsImageOverride=$(ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.AdminConsoleKurlProxyImageOverride=$(ADMIN_CONSOLE_KURL_PROXY_IMAGE_OVERRIDE)
DISABLE_FIO_BUILD ?= 0
export PATH := $(shell pwd)/bin:$(PATH)
.DEFAULT_GOAL := default
default: build-ttl.sh
split-hyphen = $(word $2,$(subst -, ,$1))
random-string = $(shell LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c6)
.PHONY: pkg/goods/bins/k0s
pkg/goods/bins/k0s:
$(MAKE) output/bins/k0s-$(K0S_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
cp output/bins/k0s-$(K0S_VERSION)-$(ARCH) $@
output/bins/k0s-%:
mkdir -p output/bins
if [ "$(K0S_BINARY_SOURCE_OVERRIDE)" != "" ]; then \
curl --retry 5 --retry-all-errors -fL -o $@ "$(K0S_BINARY_SOURCE_OVERRIDE)" ; \
else \
curl --retry 5 --retry-all-errors -fL -o $@ "https://github.com/k0sproject/k0s/releases/download/$(call split-hyphen,$*,1)/k0s-$(call split-hyphen,$*,1)-$(call split-hyphen,$*,2)" ; \
fi
chmod +x $@
touch $@
.PHONY: pkg/goods/bins/kubectl-support_bundle
pkg/goods/bins/kubectl-support_bundle:
$(MAKE) output/bins/kubectl-support_bundle-$(TROUBLESHOOT_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
cp output/bins/kubectl-support_bundle-$(TROUBLESHOOT_VERSION)-$(ARCH) $@
output/bins/kubectl-support_bundle-%:
mkdir -p output/bins
mkdir -p output/tmp
curl --retry 5 --retry-all-errors -fL -o output/tmp/support-bundle.tar.gz "https://github.com/replicatedhq/troubleshoot/releases/download/$(call split-hyphen,$*,1)/support-bundle_$(OS)_$(call split-hyphen,$*,2).tar.gz"
tar -xzf output/tmp/support-bundle.tar.gz -C output/tmp
mv output/tmp/support-bundle $@
rm -rf output/tmp
touch $@
.PHONY: pkg/goods/bins/kubectl-preflight
pkg/goods/bins/kubectl-preflight:
$(MAKE) output/bins/kubectl-preflight-$(TROUBLESHOOT_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
cp output/bins/kubectl-preflight-$(TROUBLESHOOT_VERSION)-$(ARCH) $@
output/bins/kubectl-preflight-%:
mkdir -p output/bins
mkdir -p output/tmp
curl --retry 5 --retry-all-errors -fL -o output/tmp/preflight.tar.gz https://github.com/replicatedhq/troubleshoot/releases/download/$(call split-hyphen,$*,1)/preflight_$(OS)_$(call split-hyphen,$*,2).tar.gz
tar -xzf output/tmp/preflight.tar.gz -C output/tmp
mv output/tmp/preflight $@
rm -rf output/tmp
touch $@
.PHONY: pkg/goods/bins/local-artifact-mirror
pkg/goods/bins/local-artifact-mirror:
mkdir -p pkg/goods/bins
$(MAKE) -C local-artifact-mirror build OS=$(OS) ARCH=$(ARCH)
cp local-artifact-mirror/bin/local-artifact-mirror-$(OS)-$(ARCH) $@
touch $@
ifndef FIO_VERSION
FIO_VERSION = $(shell curl --retry 5 --retry-all-errors -fsSL https://api.github.com/repos/axboe/fio/releases/latest | jq -r '.tag_name' | cut -d- -f2)
endif
output/bins/fio-%:
mkdir -p output/bins
docker build -t fio --build-arg FIO_VERSION=$(call split-hyphen,$*,1) --build-arg PLATFORM=$(OS)/$(call split-hyphen,$*,2) fio
docker rm -f fio && docker run --name fio fio
docker cp fio:/output/fio $@
docker rm -f fio
touch $@
.PHONY: pkg/goods/bins/fio
pkg/goods/bins/fio:
ifneq ($(DISABLE_FIO_BUILD),1)
$(MAKE) output/bins/fio-$(FIO_VERSION)-$(ARCH)
mkdir -p pkg/goods/bins
cp output/bins/fio-$(FIO_VERSION)-$(ARCH) $@
endif
.PHONY: pkg/goods/internal/bins/kubectl-kots
pkg/goods/internal/bins/kubectl-kots:
mkdir -p pkg/goods/internal/bins
if [ "$(KOTS_BINARY_URL_OVERRIDE)" != "" ]; then \
$(MAKE) output/bins/kubectl-kots-override ; \
cp output/bins/kubectl-kots-override $@ ; \
elif [ "$(KOTS_BINARY_FILE_OVERRIDE)" != "" ]; then \
cp $(KOTS_BINARY_FILE_OVERRIDE) $@ ; \
else \
$(MAKE) output/bins/kubectl-kots-$(KOTS_VERSION)-$(ARCH) ; \
cp output/bins/kubectl-kots-$(KOTS_VERSION)-$(ARCH) $@ ; \
fi
touch $@
output/bins/kubectl-kots-%:
mkdir -p output/bins
mkdir -p output/tmp
curl --retry 5 --retry-all-errors -fL -o output/tmp/kots.tar.gz "https://github.com/replicatedhq/kots/releases/download/$(call split-hyphen,$*,1)/kots_$(OS)_$(call split-hyphen,$*,2).tar.gz"
tar -xzf output/tmp/kots.tar.gz -C output/tmp
mv output/tmp/kots $@
touch $@
.PHONY: output/bins/kubectl-kots-override
output/bins/kubectl-kots-override:
mkdir -p output/bins
mkdir -p output/tmp
curl --retry 5 --retry-all-errors -fL -o output/tmp/kots.tar.gz "$(KOTS_BINARY_URL_OVERRIDE)"
tar -xzf output/tmp/kots.tar.gz -C output/tmp
mv output/tmp/kots $@
touch $@
.PHONY: output/bin/embedded-cluster-release-builder
output/bin/embedded-cluster-release-builder:
mkdir -p output/bin
CGO_ENABLED=0 go build -o output/bin/embedded-cluster-release-builder e2e/embedded-cluster-release-builder/main.go
.PHONY: initial-release
initial-release: export EC_VERSION = $(VERSION)-$(CURRENT_USER)
initial-release: export APP_VERSION = appver-dev-$(call random-string)
initial-release: check-env-EC_VERSION check-env-APP_VERSION
UPLOAD_BINARIES=0 \
./scripts/build-and-release.sh
.PHONY: rebuild-release
rebuild-release: export EC_VERSION = $(VERSION)-$(CURRENT_USER)
rebuild-release: check-env-EC_VERSION check-env-APP_VERSION
UPLOAD_BINARIES=0 \
SKIP_RELEASE=1 \
./scripts/build-and-release.sh
.PHONY: upgrade-release
upgrade-release: export EC_VERSION = $(VERSION)-$(CURRENT_USER)-upgrade
upgrade-release: export APP_VERSION = appver-dev-$(call random-string)-upgrade
upgrade-release: check-env-EC_VERSION check-env-APP_VERSION
UPLOAD_BINARIES=1 \
RELEASE_YAML_DIR=e2e/kots-release-upgrade \
./scripts/build-and-release.sh
.PHONY: go.mod
go.mod: Makefile
go get github.com/k0sproject/k0s@$(K0S_GO_VERSION)
go mod tidy
.PHONY: static
static: pkg/goods/bins/k0s \
pkg/goods/bins/kubectl-preflight \
pkg/goods/bins/kubectl-support_bundle \
pkg/goods/bins/local-artifact-mirror \
pkg/goods/bins/fio \
pkg/goods/internal/bins/kubectl-kots
.PHONY: static-dryrun
static-dryrun:
@mkdir -p pkg/goods/bins pkg/goods/internal/bins
@touch pkg/goods/bins/k0s \
pkg/goods/bins/kubectl-preflight \
pkg/goods/bins/kubectl-support_bundle \
pkg/goods/bins/local-artifact-mirror \
pkg/goods/bins/fio \
pkg/goods/internal/bins/kubectl-kots
.PHONY: embedded-cluster-linux-amd64
embedded-cluster-linux-amd64: export OS = linux
embedded-cluster-linux-amd64: export ARCH = amd64
embedded-cluster-linux-amd64: static go.mod embedded-cluster
mkdir -p ./output/bin
cp ./build/embedded-cluster-$(OS)-$(ARCH) ./output/bin/$(APP_NAME)
.PHONY: embedded-cluster-linux-arm64
embedded-cluster-linux-arm64: export OS = linux
embedded-cluster-linux-arm64: export ARCH = arm64
embedded-cluster-linux-arm64: static go.mod embedded-cluster
mkdir -p ./output/bin
cp ./build/embedded-cluster-$(OS)-$(ARCH) ./output/bin/$(APP_NAME)
.PHONY: embedded-cluster-darwin-arm64
embedded-cluster-darwin-arm64: export OS = darwin
embedded-cluster-darwin-arm64: export ARCH = arm64
embedded-cluster-darwin-arm64: go.mod embedded-cluster
mkdir -p ./output/bin
cp ./build/embedded-cluster-$(OS)-$(ARCH) ./output/bin/$(APP_NAME)
.PHONY: embedded-cluster
embedded-cluster:
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build \
-tags osusergo,netgo \
-ldflags="-s -w $(LD_FLAGS) -extldflags=-static" \
-o ./build/embedded-cluster-$(OS)-$(ARCH) \
./cmd/embedded-cluster
.PHONY: unit-tests
unit-tests:
mkdir -p pkg/goods/bins pkg/goods/internal/bins
touch pkg/goods/bins/BUILD pkg/goods/internal/bins/BUILD # compilation will fail if no files are present
go test -tags exclude_graphdriver_btrfs -v ./pkg/... ./cmd/...
$(MAKE) -C operator test
.PHONY: vet
vet: static
go vet -tags exclude_graphdriver_btrfs ./...
.PHONY: e2e-tests
e2e-tests: embedded-release
go test -timeout 60m -ldflags="$(LD_FLAGS)" -parallel 1 -failfast -v ./e2e
.PHONY: e2e-test
e2e-test:
go test -timeout 60m -ldflags="$(LD_FLAGS)" -v ./e2e -run ^$(TEST_NAME)$$
.PHONY: dryrun-tests
dryrun-tests: export DRYRUN_MATCH = Test
dryrun-tests: static-dryrun
@./scripts/dryrun-tests.sh
.PHONY: build-ttl.sh
build-ttl.sh:
$(MAKE) -C local-artifact-mirror build-ttl.sh \
IMAGE_NAME=$(CURRENT_USER)/embedded-cluster-local-artifact-mirror
make embedded-cluster-linux-$(ARCH) \
LOCAL_ARTIFACT_MIRROR_IMAGE=proxy.replicated.com/anonymous/$(shell cat local-artifact-mirror/build/image)
.PHONY: clean
clean:
rm -rf output
rm -rf pkg/goods/bins/*
rm -rf pkg/goods/internal/bins/*
rm -rf build
rm -rf bin
.PHONY: lint
lint:
golangci-lint run -c .golangci.yml ./... --build-tags exclude_graphdriver_btrfs
.PHONY: lint-and-fix
lint-and-fix:
golangci-lint run --fix -c .golangci.yml ./... --build-tags exclude_graphdriver_btrfs
.PHONY: scan
scan:
trivy fs \
--scanners vuln \
--exit-code=1 \
--severity="HIGH,CRITICAL" \
--ignore-unfixed \
./
.PHONY: buildtools
buildtools:
mkdir -p pkg/goods/bins pkg/goods/internal/bins
touch pkg/goods/bins/BUILD pkg/goods/internal/bins/BUILD # compilation will fail if no files are present
go build -tags exclude_graphdriver_btrfs -o ./output/bin/buildtools ./cmd/buildtools
.PHONY: list-distros
list-distros:
@$(MAKE) -C dev/distros list
.PHONY: create-node%
create-node%: DISTRO = debian-bookworm
create-node%: NODE_PORT = 30000
create-node%: K0S_DATA_DIR = /var/lib/embedded-cluster/k0s
create-node%:
@docker run -d \
--name node$* \
--hostname node$* \
--privileged \
--restart=unless-stopped \
-v $(K0S_DATA_DIR) \
-v $(shell pwd):/replicatedhq/embedded-cluster \
-v $(shell dirname $(shell pwd))/kots:/replicatedhq/kots \
$(if $(filter node0,node$*),-p $(NODE_PORT):$(NODE_PORT)) \
$(if $(filter node0,node$*),-p 30003:30003) \
replicated/ec-distro:$(DISTRO)
@$(MAKE) ssh-node$*
.PHONY: ssh-node%
ssh-node%:
@docker exec -it -w /replicatedhq/embedded-cluster node$* bash
.PHONY: delete-node%
delete-node%:
@docker rm -f --volumes node$*
.PHONY: %-up
%-up:
@dev/scripts/up.sh $*
.PHONY: %-down
%-down:
@dev/scripts/down.sh $*