-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
79 lines (64 loc) · 2.1 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
SHELL=/bin/bash -o pipefail
REGISTRY ?= appscode
BIN ?= golang-dev
IMAGE := $(REGISTRY)/$(BIN)
VERSION ?= 1.23.2
SRC_REG ?=
DOCKER_PLATFORMS := linux/amd64 linux/arm64
PLATFORM ?= $(firstword $(DOCKER_PLATFORMS))
TAG = $(VERSION)_$(subst /,_,$(PLATFORM))
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
ifeq (,$(SRC_REG))
container:
@echo "container: $(IMAGE):$(TAG)"
@docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(TAG) -f Dockerfile .
@echo
else
container:
@echo "container: $(IMAGE):$(TAG)"
@docker tag $(SRC_REG)/$(BIN):$(TAG) $(IMAGE):$(TAG)
@echo
endif
push: container
@docker push $(IMAGE):$(TAG)
@echo "pushed: $(IMAGE):$(TAG)"
@echo
# https://stackoverflow.com/a/3732456
VER_MAJOR := $(shell echo $(VERSION) | cut -f1 -d.)
VER_MINOR := $(shell echo $(VERSION) | cut -f2 -d.)
Mm := $(VER_MAJOR).$(VER_MINOR)
.PHONY: docker-manifest
docker-manifest:
docker manifest create -a $(IMAGE):$(VERSION) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION)_$(subst /,_,$(PLATFORM)))
docker manifest push $(IMAGE):$(VERSION)
docker manifest create -a $(IMAGE):$(Mm) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(VERSION)_$(subst /,_,$(PLATFORM)))
docker manifest push $(IMAGE):$(Mm)
.PHONY: release
release:
@$(MAKE) all-push docker-manifest --no-print-directory
.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):$(TAG)
@echo "Image has been pushed successfully into kind cluster."