-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
139 lines (110 loc) · 3.38 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
.PHONY: all
all: build-images
CURRENT_DIR ?= $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
TOP_DIR ?= $(CURRENT_DIR)
IMAGE_TAG ?= latest
BUILDER_IMAGE ?= ghcr.io/drogue-iot/builder:0.2.4
# evaluate which container tool we use
ifeq (, $(shell which podman 2>/dev/null))
CONTAINER ?= docker
else
CONTAINER ?= podman
CONTAINER_SAVE_OPTS ?= --multi-image-archive
endif
# evaluate the arguments we need for this container tool
ifeq ($(CONTAINER),docker)
TEST_CONTAINER_ARGS ?= -v /var/run/docker.sock:/var/run/docker.sock:z --network drogue
CONTAINER_ARGS ?= -u "$(shell id -u):$(shell id -g)" $(patsubst %,--group-add %,$(shell id -G ))
else ifeq ($(CONTAINER),podman)
TEST_CONTAINER_ARGS ?= --security-opt label=disable -v $(XDG_RUNTIME_DIR)/podman/podman.sock:/var/run/docker.sock:z
CONTAINER_ARGS ?= --userns=keep-id
endif
MODULES= \
backend \
injector \
processor \
server \
database-migration \
waker \
debugger \
#
# Check if we have a container registry set.
#
.PHONY: require-container-registry
require-container-registry:
ifndef CONTAINER_REGISTRY
$(error CONTAINER_REGISTRY is undefined)
endif
#
# Build, tag, and push all images
#
.PHONY: images
images: require-container-registry build-images tag-images push-images
#
# Build all images, including this binaries
#
.PHONY: build-images
build-images:
set -e; \
for i in $(MODULES); do \
$(CONTAINER) build $(TOP_DIR) --build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) --target $${i} -t localhost/drogue-doppelgaenger-$${i}:latest; \
done
#
# Tag all images from that last build
#
.PHONY: tag-images
tag-images: require-container-registry
set -e; \
for i in $(MODULES); do \
$(CONTAINER) tag localhost/drogue-doppelgaenger-$${i}:latest $(CONTAINER_REGISTRY)/drogue-doppelgaenger-$${i}:$(IMAGE_TAG); \
done
#
# Push all tagged images
#
.PHONY: push-images
push-images: require-container-registry
set -e; \
cd $(TOP_DIR); \
for i in $(MODULES); do \
env CONTAINER=$(CONTAINER) ./scripts/bin/retry.sh push -q $(CONTAINER_REGISTRY)/drogue-doppelgaenger-$${i}:$(IMAGE_TAG) & \
done; \
wait
#
# Save all images
#
.PHONY: save-images
save-images:
mkdir -p "$(TOP_DIR)/build/images"
rm -Rf "$(TOP_DIR)/build/images/all.tar"
$(CONTAINER) save $(CONTAINER_SAVE_OPTS) -o "$(TOP_DIR)/build/images/all.tar" $(addprefix localhost/drogue-doppelgaenger-, $(addsuffix :latest, $(MODULES)))
#
# Load image into kind
#
.PHONY: kind-load
kind-load: require-container-registry
for i in $(MODULES); do \
kind load docker-image $(CONTAINER_REGISTRY)/drogue-doppelgaenger-$${i}:$(IMAGE_TAG); \
done
#
# Do a local deploy
#
# For a local deploy, we allow using the default container registry of the project
#
.PHONY: deploy
deploy: CONTAINER_REGISTRY ?= "ghcr.io/drogue-iot"
deploy:
test -d deploy/helm/charts || git submodule update --init
env ./scripts/drgadm deploy \
-s drogueCloudTwin.defaults.images.repository=$(CONTAINER_REGISTRY) \
-s drogueCloudTwin.defaults.images.tag=latest $(DEPLOY_ARGS)
.PHONY: run-deps
run-deps:
podman-compose -f $(TOP_DIR)/develop/compose.yaml -f $(TOP_DIR)/develop/compose-health.yaml up
.PHONY: start-deps
start-deps:
podman-compose -f $(TOP_DIR)/develop/compose.yaml -f $(TOP_DIR)/develop/compose-health.yaml up -d
.PHONY: stop-deps
stop-deps:
podman-compose -f $(TOP_DIR)/develop/compose.yaml -f $(TOP_DIR)/develop/compose-health.yaml down
.PHONY: restart-deps
restart-deps: stop-deps start-deps