-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (58 loc) · 2.05 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
SHELL=/bin/bash -o pipefail
REGISTRY ?= ghcr.io/masudur-rahman
BIN ?= golang
IMAGE := $(REGISTRY)/$(BIN)
VERSION ?= 1.23
SRC_REG ?=
DOCKER_PLATFORMS := linux/arm64 linux/amd64 #windows/amd64
PLATFORM ?= $(firstword $(DOCKER_PLATFORMS))
TAG = $(VERSION)_$(subst /,_,$(PLATFORM))
#TAG = $(VERSION)
BUILDX_PLATFORMS := linux/arm64,linux/amd64
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)
buildx:
docker buildx build --platform $(BUILDX_PLATFORMS) --load --pull -t $(IMAGE):$(Mm) -f Dockerfile .
.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
# 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."