-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (75 loc) · 2.52 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
CLIENT_IMAGE ?= akitasoftware/demo-client
SERVER_IMAGE ?= akitasoftware/demo-server
CONFIG_FILE ?= application.yml
TAG ?= latest
LATEST ?= true
BUILDER=buildx-multi-arch
INFO_COLOR = \033[0;36m
NO_COLOR = \033[m
build-client: ## Build the demo client
docker build --tag=$(CLIENT_IMAGE):$(TAG) --secret id=application.yml,src=$(CONFIG_FILE) -f client/Dockerfile client
.PHONY: build-client
build-server: ## Build the demo server
docker build --tag=$(SERVER_IMAGE):$(TAG) -f server/Dockerfile server
.PHONY: build-server
build-images: build-client build-server ## Build the demo images
prepare-buildx: ## Create buildx builder for multi-arch build, if not exists
docker buildx inspect $(BUILDER) || docker buildx create --name=$(BUILDER) --driver=docker-container --driver-opt=network=host
.PHONY: prepare-buildx
# Check if the specified tag exists remotely
define check_remote_tag
@if docker pull $(1):$(TAG) >/dev/null 2>&1; then \
echo "Error: Image $(1):$(TAG) already exists in the registry."; \
exit 1; \
fi
endef
push-client: prepare-buildx ## Push the demo client image to the registry
$(call check_remote_tag,$(CLIENT_IMAGE))
ifeq ($(LATEST),true)
docker buildx build \
--push \
--builder=$(BUILDER) \
--platform=linux/amd64,linux/arm64 \
--secret id=application.yml,src=$(CONFIG_FILE) \
--build-arg TAG=$(TAG) \
--tag=$(CLIENT_IMAGE):$(TAG) \
--tag=$(CLIENT_IMAGE):latest \
-f client/Dockerfile client
else
docker buildx build \
--push \
--builder=$(BUILDER) \
--platform=linux/amd64,linux/arm64 \
--secret id=application.yml,src=$(CONFIG_FILE) \
--build-arg TAG=$(TAG) \
--tag=$(CLIENT_IMAGE):$(TAG) \
-f client/Dockerfile client
endif
.PHONY: push-client
push-server: prepare-buildx
$(call check_remote_tag,$(SERVER_IMAGE))
ifeq ($(LATEST),true)
docker buildx build \
--push \
--builder=$(BUILDER) \
--platform=linux/amd64,linux/arm64 \
--build-arg TAG=$(TAG) \
--tag=$(SERVER_IMAGE):$(TAG) \
--tag=$(SERVER_IMAGE):latest \
-f server/Dockerfile server
else
docker buildx build \
--push \
--builder=$(BUILDER) \
--platform=linux/amd64,linux/arm64 \
--build-arg TAG=$(TAG) \
--tag=$(SERVER_IMAGE):$(TAG) \
-f server/Dockerfile server
endif
.PHONY: push-server
push-images: push-client push-server ## Push the demo images to the registry
.PHONY: push-images
help: ## Show this help
@echo Please specify a build target. The choices are:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}'
.PHONY: help