-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
550 lines (456 loc) · 19.5 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
SHELL:=/bin/bash
.DEFAULT_GOAL := help
OS := $(shell uname -s)
INTERACTIVE := $(shell [ -t 0 ] && echo 1)
root_mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
export REPO_ROOT_DIR := $(patsubst %/,%,$(dir $(root_mkfile_path)))
export REPO_REV ?= $(shell cd $(REPO_ROOT_DIR) && git describe --abbrev=12 --tags --match='v*' HEAD)
export COMMIT := $(shell git log -n1 | grep commit | cut -d' ' -f2)
UID ?= $(shell id -u)
GID ?= $(shell id -g)
USER_NAME ?= $(shell id -u -n)
GROUP_NAME ?= $(shell id -g -n)
COVERAGE ?= $(REPO_ROOT_DIR)/coverage
VERBOSITY ?= 0
INVENTORY_FILE ?= $(REPO_ROOT_DIR)/inventory.yaml
COMMA:=,
export CGO_ENABLED=0
export GO_VERSION := $(shell cat go.mod | grep "go " -m 1 | cut -d " " -f 2)
GOLANG_IMAGE := golang:$(GO_VERSION)
ARCH := $(shell uname -m)
BUILDARCH ?= $(shell echo $(ARCH) | sed 's/x86_64/amd64/g')
export CI ?= no
export DOCKER_SOCKET ?= /var/run/docker.sock
ifeq ($(OS),Darwin)
export DOCKER_SOCKET_GID ?= $(shell /usr/bin/stat -f "%g" $(DOCKER_SOCKET))
else
export DOCKER_SOCKET_GID ?= $(shell stat -c %g $(DOCKER_SOCKET))
endif
export DOCKER_DEVKIT_GO_ENV_ARGS ?= \
--env GOCACHE=/kib/.cache/go-build \
--env GOMODCACHE=/kib/.cache/go-mod \
--env GOLANGCI_LINT_CACHE=/kib/.cache/golangci-lint \
export DOCKER_DEVKIT_ENV_ARGS ?= \
--env CI \
--env GITHUB_TOKEN \
--env BUILD_DRY_RUN \
$(DOCKER_DEVKIT_GO_ENV_ARGS)
export DOCKER_DEVKIT_AWS_ARGS ?= \
--env AWS_PROFILE \
--env AWS_SECRET_ACCESS_KEY \
--env AWS_SESSION_TOKEN \
--env AWS_DEFAULT_REGION \
--volume "$(HOME)/.aws":"/home/$(USER_NAME)/.aws"
DOCKER_GCP_CREDENTIALS_ARGS=--volume "$(HOME)/.gcloud":"/home/$(USER_NAME)/.gcloud" \
--env GOOGLE_APPLICATION_CREDENTIALS=/home/$(USER_NAME)/.gcloud/credentials.json
export DOCKER_DEVKIT_GCP_ARGS ?= \
$(DOCKER_GCP_CREDENTIALS_ARGS)
export DOCKER_DEVKIT_AZURE_ARGS ?= \
--env AZURE_LOCATION \
--env AZURE_CLIENT_ID \
--env AZURE_CLIENT_SECRET \
--env AZURE_SUBSCRIPTION_ID \
--env AZURE_TENANT_ID \
--volume "$(HOME)/.azure":"/home/$(USER_NAME)/.azure"
export DOCKER_DEVKIT_VSPHERE_ARGS ?= \
--env VSPHERE_SERVER \
--env VSPHERE_USERNAME \
--env VSPHERE_PASSWORD \
--env RHSM_USER \
--env RHSM_PASS
export DOCKER_DEVKIT_BASTION_ARGS ?= \
--env SSH_BASTION_USERNAME \
--env SSH_BASTION_HOST \
--env SSH_BASTION_KEY_CONTENTS
ifneq ($(wildcard $(DOCKER_SOCKET)),)
export DOCKER_SOCKET_ARGS ?= \
--volume "$(DOCKER_SOCKET)":/var/run/docker.sock
endif
export DOCKER_DEVKIT_PUSH_ARGS ?= \
--volume "$(HOME)/.docker":"/home/$(USER_NAME)/.docker" \
--env DOCKER_PASS \
--env DOCKER_CLI_EXPERIMENTAL
# ulimit arg is a workaround for golang's "suboptimal" bug workaround that
# manifests itself in alpine images, resulting in packer plugins simply dying.
#
# On LTS distros like Ubuntu, kernel bugs are backported, so the kernel version
# may seem old even though it is not vulnerable. Golang ignores it and just
# looks at the distro+kernel combination to determine if it should panic or
# not. This results in packer silently failing when running in devkit
# container, as it is using Alpine linux. See the issue below for more details:
# https://github.com/docker-library/golang/issues/320
export DOCKER_ULIMIT_ARGS ?= \
--ulimit memlock=67108864:67108864
export DOCKER_DEVKIT_USER_ARGS ?= \
--user $(UID):$(GID) \
--group-add $(DOCKER_SOCKET_GID)
export DOCKER_DEVKIT_SSH_ARGS ?= \
--env SSH_AUTH_SOCK=/run/ssh-agent.sock \
--volume $(SSH_AUTH_SOCK):/run/ssh-agent.sock
export DOCKER_DEVKIT_ARGS ?= \
$(DOCKER_ULIMIT_ARGS) \
$(DOCKER_DEVKIT_USER_ARGS) \
--volume $(REPO_ROOT_DIR):/kib \
--workdir /kib \
$(DOCKER_SOCKET_ARGS) \
$(DOCKER_DEVKIT_AWS_ARGS) \
$(DOCKER_DEVKIT_GCP_ARGS) \
$(DOCKER_DEVKIT_AZURE_ARGS) \
$(DOCKER_DEVKIT_BASTION_ARGS) \
$(DOCKER_DEVKIT_VSPHERE_ARGS) \
$(DOCKER_DEVKIT_PUSH_ARGS) \
$(DOCKER_DEVKIT_ENV_ARGS) \
$(DOCKER_DEVKIT_SSH_ARGS)
export DOCKER_DEVKIT_DEFAULT_ARGS ?= \
--rm \
$(if $(INTERACTIVE),--tty) \
--interactive
ifneq ($(shell git status --porcelain 2>/dev/null; echo $$?), 0)
export GIT_TREE_STATE := dirty
else
export GIT_TREE_STATE :=
endif
# envsubst
# ---------------------------------------------------------------------
export ENVSUBST_VERSION ?= v1.2.0
export ENVSUBST_URL = https://github.com/a8m/envsubst/releases/download/$(ENVSUBST_VERSION)/envsubst-$(shell uname -s)-$(shell uname -m)
export ENVSUBST_ASSETS ?= $(CURDIR)/.local/envsubst/${ENVSUBST_VERSION}
.PHONY: install-envsubst
install-envsubst: ## install envsubst binary
install-envsubst: $(ENVSUBST_ASSETS)/envsubst
$(ENVSUBST_ASSETS)/envsubst:
$(call print-target,install-envsubst)
mkdir -p $(ENVSUBST_ASSETS)
curl -Lf $(ENVSUBST_URL) -o $(ENVSUBST_ASSETS)/envsubst
chmod +x $(ENVSUBST_ASSETS)/envsubst
include hack/pip-packages/Makefile
include test/infra/Makefile
github-token.txt:
echo $(GITHUB_TOKEN) >> github-token.txt
.PHONY: buildx
buildx:
buildx:
docker buildx create --use --name=konvoy-image-builder || true
docker run --privileged --rm tonistiigi/binfmt --install all &>/dev/null || true
###### Devkit container image
DEVKIT_IMAGE_DOCKERFILE ?= Dockerfile.devkit
DEVKIT_IMAGE_NAME ?= mesosphere/konvoy-image-builder-devkit
DEVKIT_IMAGE_TAG ?= $(shell cat ${DEVKIT_IMAGE_DOCKERFILE} requirements.txt requirements-devkit.txt | sha256sum | cut -d" " -f 1)
.PHONY: devkit-image
## first tries to pull an image, if doesn't exist build and push the image
devkit-image:
$(call print-target)
docker image inspect $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG) &>/dev/null || \
docker pull $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG) || \
$(MAKE) devkit-image-amd64 devkit-image-arm64
.PHONY: devkit-image-amd64
devkit-image-amd64:
$(MAKE) devkit-image-build-push BUILDARCH=amd64
.PHONY: devkit-image-arm64
devkit-image-arm64:
$(MAKE) devkit-image-build-push BUILDARCH=arm64
.PHONY: devkit-image-build-push
devkit-image-build-push: github-token.txt buildx
$(call print-target)
docker image inspect $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-$(BUILDARCH) &>/dev/null || \
docker pull $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-$(BUILDARCH) || \
docker buildx build \
--pull \
--push \
--build-arg BUILDARCH=$(BUILDARCH) \
--secret id=githubtoken,src=github-token.txt \
--provenance=false \
--platform linux/$(BUILDARCH) \
--file $(DEVKIT_IMAGE_DOCKERFILE) \
--tag=$(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-$(BUILDARCH) \
$(dir $(DEVKIT_IMAGE_DOCKERFILE))
.PHONY: devkit-image-push-manifest
devkit-image-push-manifest: ## pushes the devkit-image
devkit-image-push-manifest: devkit-image-amd64 devkit-image-arm64
$(call print-target)
docker manifest create \
$(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG) \
--amend $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-amd64 \
--amend $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-arm64
docker manifest push $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)
##### Build KIB container image
export DOCKER_REPOSITORY ?= mesosphere/konvoy-image-builder
export DOCKER_IMG ?= $(DOCKER_REPOSITORY):$(REPO_REV)-$(BUILDARCH)
.PHONY: kib-image-build-amd64
kib-image-build-amd64:
$(MAKE) kib-image-build BUILDARCH=amd64
.PHONY: kib-image-build-arm64
kib-image-build-arm64:
$(MAKE) kib-image-build BUILDARCH=arm64
# we need to push these devkit images up to dockerhub.
# buildx does not pull the base images specified in Dockerfile from local docker cache.
# buildx always attempts to pull it from dockerhub.
# This behavior is not documented. see https://github.com/moby/moby/issues/42893#issuecomment-1241274246
# The latest Docker Engine version 23.0 defaults to buildx for building images.
# The caching improvements in this release might fix this problem.
# see release notes: https://docs.docker.com/engine/release-notes/23.0/#2301
# Always build the kib image to embed `konvoy-imag` binary from current revision
# devkit-image-$(BUILDARCH): will build and push arch specific devkit image to docker hub.
# konvoy-image-$(BUILDARCH): will create arch specific binary in ./bin directory.
# kib-image-build: will create docker image used by konvoy-image-wrapper.
# kib container image is built using './Dockerfile' that has two main dependencies
# (1) The devkit image reference from docker hub.
# The buildx always pulls base images from dockerhub. so this image has to be pushed to registry.
# (2) Arch specific konvoy-image binary file thats get copied in the image
# TODO: revisit this target when moving to docker 23.0.x.
# use 'docker build --platform' instead of 'docker buildx build' to avoid exporing images from buildx cache to docker cache.
.PHONY: kib-image-build
kib-image-build: devkit-image-$(BUILDARCH) konvoy-image-$(BUILDARCH)
docker buildx build \
--file $(REPO_ROOT_DIR)/Dockerfile \
--build-arg BUILDARCH=$(BUILDARCH) \
--build-arg BASE=$(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-$(BUILDARCH) \
--platform linux/$(BUILDARCH) \
--pull \
--load \
--tag=$(DOCKER_REPOSITORY):$(REPO_REV)-$(BUILDARCH) \
$(REPO_ROOT_DIR)
.PHONY: kib-image-push-amd64
kib-image-push-amd64: kib-image-build-amd64
docker push $(DOCKER_REPOSITORY):$(REPO_REV)-amd64
.PHONY: kib-image-push-arm64
kib-image-push-arm64: kib-image-build-arm64
docker push $(DOCKER_REPOSITORY):$(REPO_REV)-arm64
# The arch specific images must be pushed to docker registry in order to create manifest file.
# A manifest file can not be created using locally cached images. see: https://github.com/docker/cli/issues/3350
# TODO: Build and push multi arch image using single command: docker buildx build --platform linux/amd64,linux/arm64 --output=type=registry
.PHONY: kib-image-push-manifest
kib-image-push-manifest: kib-image-push-amd64 kib-image-push-arm64
docker manifest create \
$(DOCKER_REPOSITORY):$(REPO_REV) \
--amend $(DOCKER_REPOSITORY):$(REPO_REV)-arm64 \
--amend $(DOCKER_REPOSITORY):$(REPO_REV)-amd64
docker manifest push $(DOCKER_REPOSITORY):$(REPO_REV)
WHAT ?= bash
.PHONY: provision
provision: build
provision:
./bin/konvoy-image provision --inventory-file $(INVENTORY_FILE) \
-v ${VERBOSITY} \
$(if $(ADDITIONAL_OVERRIDES),--overrides=${ADDITIONAL_OVERRIDES}) \
$(if $(EXTRA_OVERRIDE_VARS), --extra-vars=${EXTRA_OVERRIDE_VARS})
.PHONY: dev
dev: ## dev build
dev: clean generate build lint test mod-tidy build.snapshot
.PHONY: ci
ci: ## CI build
ci: dev diff
.PHONY: clean
clean: ## remove files created during build
$(call print-target)
rm -rf bin
rm -rf dist
rm -rf artifacts
rm -rf "$(REPO_ROOT_DIR)/cmd/konvoy-image-wrapper/image/konvoy-image-builder.tar.gz"
rm -f flatcar-version.yaml
rm -f $(COVERAGE)*
docker image rm $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG) || echo "image already removed"
docker image rm $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-amd64 || echo "image already removed"
docker image rm $(DEVKIT_IMAGE_NAME):$(DEVKIT_IMAGE_TAG)-arm64 || echo "image already removed"
docker buildx rm konvoy-image-builder || echo "image already removed"
.PHONY: generate
generate: ## go generate
$(call print-target)
go generate ./...
###### build arch specific konvoy-image binary
# TODO: refactor targets to remove duplication
bin/konvoy-image: $(REPO_ROOT_DIR)/cmd
bin/konvoy-image: $(shell find $(REPO_ROOT_DIR)/cmd -type f -name '*'.go)
bin/konvoy-image: $(REPO_ROOT_DIR)/pkg
bin/konvoy-image: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.go)
bin/konvoy-image: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.hcl)
bin/konvoy-image:
$(call print-target)
GOARCH=$(BUILDARCH) GOOS=$(GOOS) go build \
-ldflags='-X github.com/mesosphere/konvoy-image-builder/pkg/version.version=$(REPO_REV)' \
-o ./dist/konvoy-image_$(GOOS)_$(GOARCH)/konvoy-image ./cmd/konvoy-image/main.go
mkdir -p bin
ln -sf ../dist/konvoy-image_$(GOOS)_$(GOARCH)/konvoy-image bin/konvoy-image
# Creates bin/konvoy-image-amd64 which will be copied to KIB container image for amd64. see Dockerfile
bin/konvoy-image-amd64: $(REPO_ROOT_DIR)/cmd
bin/konvoy-image-amd64: $(shell find $(REPO_ROOT_DIR)/cmd -type f -name '*'.go)
bin/konvoy-image-amd64: $(REPO_ROOT_DIR)/pkg
bin/konvoy-image-amd64: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.go)
bin/konvoy-image-amd64: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.hcl)
bin/konvoy-image-amd64:
$(call print-target)
GOARCH=amd64 GOOS=$(GOOS) go build \
-ldflags='-X github.com/mesosphere/konvoy-image-builder/pkg/version.version=$(REPO_REV)' \
-o ./dist/konvoy-image_linux_amd64/konvoy-image ./cmd/konvoy-image/main.go
mkdir -p bin
ln -sf ../dist/konvoy-image_linux_amd64/konvoy-image bin/konvoy-image-amd64
# Creates bin/konvoy-image-arm64 which will be copied to KIB container image for arm64. see Dockerfile
bin/konvoy-image-arm64: $(REPO_ROOT_DIR)/cmd
bin/konvoy-image-arm64: $(shell find $(REPO_ROOT_DIR)/cmd -type f -name '*'.go)
bin/konvoy-image-arm64: $(REPO_ROOT_DIR)/pkg
bin/konvoy-image-arm64: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.go)
bin/konvoy-image-arm64: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.hcl)
bin/konvoy-image-arm64:
$(call print-target)
GOARCH=arm64 GOOS=$(GOOS) go build \
-ldflags='-X github.com/mesosphere/konvoy-image-builder/pkg/version.version=$(REPO_REV)' \
-o ./dist/konvoy-image_linux_arm64/konvoy-image ./cmd/konvoy-image/main.go
mkdir -p bin
ln -sf ../dist/konvoy-image_linux_arm64/konvoy-image bin/konvoy-image-arm64
konvoy-image-amd64:
$(MAKE) bin/konvoy-image-amd64 GOOS=linux GOARCH=amd64
konvoy-image-arm64:
$(MAKE) bin/konvoy-image-arm64 GOOS=linux GOARCH=arm64
###### build konvoy image wrapper
bin/konvoy-image-wrapper: kib-image-build-$(BUILDARCH)
$(call print-target)
GOARCH=$(GOARCH) GOOS=$(GOOS) go build \
-ldflags='-X github.com/mesosphere/konvoy-image-builder/pkg/version.version=$(REPO_REV)-$(BUILDARCH)' \
-o ./bin/konvoy-image-wrapper ./cmd/konvoy-image-wrapper/main.go
dist/konvoy-image_linux_$(BUILDARCH)/konvoy-image: $(REPO_ROOT_DIR)/cmd
dist/konvoy-image_linux_$(BUILDARCH)/konvoy-image: $(shell find $(REPO_ROOT_DIR)/cmd -type f -name '*'.go)
dist/konvoy-image_linux_$(BUILDARCH)/konvoy-image: $(REPO_ROOT_DIR)/pkg
dist/konvoy-image_linux_$(BUILDARCH)/konvoy-image: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.go)
dist/konvoy-image_linux_$(BUILDARCH)/konvoy-image: $(shell find $(REPO_ROOT_DIR)/pkg -type f -name '*'.hcl)
dist/konvoy-image_linux_$(BUILDARCH)/konvoy-image:
$(call print-target)
goreleaser build --snapshot --clean --id konvoy-image --single-target
.PHONY: build
build: bin/konvoy-image
build: ## go build
.PHONY: build-wrapper
build-wrapper: bin/konvoy-image-wrapper
.PHONY: docs
docs: build
$(REPO_ROOT_DIR)/bin/konvoy-image generate-docs $(REPO_ROOT_DIR)/docs/cli
.PHONY: docs.check
docs.check: docs
docs.check:
@test -z "$(shell git status --porcelain -- $(REPO_ROOT_DIR)/docs)" \
|| (echo ''; \
echo 'Need docs update:'; \
echo ''; \
git status --porcelain -- "$(REPO_ROOT_DIR)/docs"; \
echo ''; \
echo 'Run `make docs` and commit the results'; \
exit 1)
.PHONY: lint
lint: ## golangci-lint
$(call print-target)
golangci-lint run -c .golangci.yml --fix
# Add a convience alias
.PHONY: super-linter
super-linter: super-lint
.PHONY: super-lint
include $(REPO_ROOT_DIR)/.github/super-linter.env
export
export DOCKER_SUPER_LINTER_ARGS ?= \
--env RUN_LOCAL=true \
--env-file $(REPO_ROOT_DIR)/.github/super-linter.env \
--volume $(REPO_ROOT_DIR):/tmp/lint
export DOCKER_SUPER_LINTER_VERSION ?= $(shell \
grep 'uses: super-linter/super-linter' $(REPO_ROOT_DIR)/.github/workflows/lint.yml | cut -d@ -f2 \
)
export DOCKER_SUPER_LINTER_IMG := ghcr.io/super-linter/super-linter:$(DOCKER_SUPER_LINTER_VERSION)
super-lint: ## run all linting with super-linter
$(call print-target)
docker run \
--rm \
$(if $(INTERACTIVE),--tty) \
--interactive \
$(DOCKER_SUPER_LINTER_ARGS) \
$(DOCKER_SUPER_LINTER_IMG)
.PHONY: super-lint-shell
super-lint-shell: ## open a shell in the super-linter container
$(call print-target)
docker run \
--rm \
$(if $(INTERACTIVE),--tty) \
--interactive \
$(DOCKER_SUPER_LINTER_ARGS) \
--workdir=/tmp/lint \
--entrypoint="/bin/bash" \
$(DOCKER_SUPER_LINTER_IMG) -l
.PHONY: test
test: ## go test with race detector and code coverage
$(call print-target)
CGO_ENABLED=1 go test $(shell go list ./... | grep -v e2e) -- -race -short -v
.PHONY: integration-test
integration-test: ## go test with race detector for integration tests
$(call print-target)
CGO_ENABLED=1 go test -race -run Integration -v ./...
.PHONY: mod-tidy
mod-tidy: ## go mod tidy
$(call print-target)
go mod tidy
GORELEASER_SINGLE_TARGET ?= true
.PHONY: build.snapshot
build.snapshot: dist/konvoy-image_linux_amd64/konvoy-image
build.snapshot:
$(call print-target)
goreleaser build --parallelism=1 --snapshot --single-target=$(GORELEASER_SINGLE_TARGET) --clean
.PHONY: diff
diff: ## git diff
$(call print-target)
git diff --exit-code
RES=$$(git status --porcelain) ; if [ -n "$$RES" ]; then echo $$RES && exit 1 ; fi
.PHONY: release
release:
$(call print-target)
DOCKER_BUILDKIT=1 goreleaser release --clean --parallelism=1 --timeout=2h
.PHONY: release-snapshot
release-snapshot:
$(call print-target)
DOCKER_BUILDKIT=1 goreleaser --parallelism=1 --clean --snapshot --timeout=2h
.PHONY: go-clean
go-clean: ## go clean build, test and modules caches
$(call print-target)
go clean -r -i -cache -testcache -modcache
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[.0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-45s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
define print-target
@printf "Executing target: \033[36m$@\033[0m\n"
endef
cmd/konvoy-image-wrapper/image/konvoy-image-builder.tar.gz: kib-image-push-manifest
# we need to build the appropriate image for the bundle we're creating
# followed by saving it as just image name so that we can put in the release tar
# the docker images are published before this by hack/release.sh, making this safe.
docker pull $(DOCKER_REPOSITORY):$(REPO_REV)-$(BUILDARCH)
docker tag $(DOCKER_REPOSITORY):$(REPO_REV)-$(BUILDARCH) $(DOCKER_REPOSITORY):$(REPO_REV)
docker save $(DOCKER_REPOSITORY):$(REPO_REV) | gzip -c - > "$(REPO_ROOT_DIR)/cmd/konvoy-image-wrapper/image/konvoy-image-builder.tar.gz"
export GITHUB_CLI_VERSION=2.45.0
export GITHUB_CLI_ASSETS=$(CURDIR)/.local/github_cli/
export GITHUB_CLI_URL_GOOS := $(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
ifeq ($(GOOS),darwin)
export GITHUB_CLI_URL_GOOS=macOS
endif
export GITHUB_CLI_BIN=$(GITHUB_CLI_ASSETS)/gh
export GITHUB_CLI_URL=https://github.com/cli/cli/releases/download/v$(GITHUB_CLI_VERSION)/gh_$(GITHUB_CLI_VERSION)_$(GITHUB_CLI_URL_GOOS)_amd64.tar.gz
.PHONY: install-github
install-github:
install-github: $(GITHUB_CLI_ASSETS)/gh
$(GITHUB_CLI_ASSETS)/gh:
mkdir -p $(GITHUB_CLI_ASSETS) && \
cd $(GITHUB_CLI_ASSETS) && \
curl -qL $(GITHUB_CLI_URL) -o gh.tar.gz && \
tar fxz gh.tar.gz && \
mv $(GITHUB_CLI_ASSETS)/gh_$(GITHUB_CLI_VERSION)_$(GITHUB_CLI_URL_GOOS)_amd64/bin/gh . && \
rm -rf gh.tar.gz gh_$(GITHUB_CLI_VERSION)_$(GITHUB_CLI_URL_GOOS)_amd64
export SEMVER_CLI_INSTALL_URL=https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
export SEMVER_CLI_ASSETS=$(CURDIR)/.local/semver-cli/
export SEMVER_CLI_BIN=$(SEMVER_CLI_ASSETS)/semver
.PHONY: install-semver
install-semver:
install-semver:
mkdir -p $(SEMVER_CLI_ASSETS) && \
cd $(SEMVER_CLI_ASSETS) && \
wget -qO semver $(SEMVER_CLI_INSTALL_URL) && \
chmod +x semver
.PHONY: version-diff
version-diff:
version-diff: install-github install-semver
hack/version-diff.sh
build-for-podman: kib-image-build-amd64
docker tag $(DOCKER_REPOSITORY):$(REPO_REV)-$(BUILDARCH) $(DOCKER_REPOSITORY):$(COMMIT)
docker save $(DOCKER_REPOSITORY):$(COMMIT) | gzip -c - > "$(REPO_ROOT_DIR)/cmd/konvoy-image-wrapper/image/konvoy-image-builder.tar.gz"