-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (68 loc) · 2.26 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
SHELL=/bin/bash -o pipefail
REGISTRY ?= ghcr.io/kubedb
BIN ?= proxysql
IMAGE := $(REGISTRY)/$(BIN)
TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "")
DOCKER_PLATFORMS := linux/amd64 linux/arm64
ARCH := $(subst x86_64,amd64,$(subst aarch64,arm64,$(shell uname -m)))
PLATFORM ?= linux/$(ARCH)
VERSION = $(TAG)_$(subst /,_,$(PLATFORM))
DB_REGISTRY ?= proxysql
DB_BIN ?= proxysql
DB_TAG ?= 2.6.3-debian
ifeq ($(ARCH),arm64)
DB_TAG := $(TAG)_$(ARCH)
endif
DB_IMAGE ?= $(DB_REGISTRY)/$(DB_BIN):$(DB_TAG)
BUILD_DIRS := bin
$(BUILD_DIRS):
@mkdir -p $@
container-%:
@$(MAKE) container \
--no-print-directory \
PLATFORM=$(subst _,/,$*)
push-%:
@$(MAKE) push \
--no-print-directory \
PLATFORM=$(subst _,/,$*)
all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS)))
all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS)))
.PHONY: container
container: $(BUILD_DIRS)
@echo "container: $(IMAGE):$(VERSION)"
@rm -rf bin/.dockerfile; \
sed \
-e 's|{PROXYSQL_IMAGE}|$(DB_IMAGE)|g' \
Dockerfile > bin/.dockerfile; \
docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f bin/.dockerfile .
@echo
push: container
@docker push $(IMAGE):$(VERSION)
@echo "pushed: $(IMAGE):$(VERSION)"
@echo
.PHONY: docker-manifest
docker-manifest:
docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM)))
docker manifest push $(IMAGE):$(TAG)
.PHONY: release
release:
@$(MAKE) all-push docker-manifest --no-print-directory
.PHONY: version
version:
@echo ::set-output name=version::$(VERSION)
.PHONY: fmt
fmt:
@find . -path ./vendor -prune -o -name '*.sh' -exec shfmt -l -w -ci -i 4 {} \;
.PHONY: verify
verify: fmt
@if !(git diff --exit-code HEAD); then \
echo "files are out of date, run make fmt"; exit 1; \
fi
.PHONY: ci
ci: verify
# make and load docker image to kind cluster
.PHONY: push-to-kind
push-to-kind: container
@echo "Loading docker image into kind cluster...."
@kind load docker-image $(IMAGE):$(VERSION)
@echo "Image has been pushed successfully into kind cluster."