-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
303 lines (247 loc) · 9.93 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(MAKEFILE_DIR)/standard_defs.mk
export OPENSSL_STATIC=1
ARCH_TYPE ?= $(shell uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
HOST_ARCHITECTURE ?= $(shell uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
CHRONICLE_BUILDER_IMAGE ?= blockchaintp/chronicle-builder-$(ARCH_TYPE)
CHRONICLE_TP_IMAGE ?= blockchaintp/chronicle-tp-$(ARCH_TYPE)
CHRONICLE_VERSION ?= BTP2.1.0-0.7.7
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
CLEAN_DIRS := $(CLEAN_DIRS)
DOMAINS := $(shell find . -mindepth 3 -maxdepth 3 -name domain.yaml \
-exec dirname {} \; | awk -F/ '{print $$NF}')
TEST_DOMAIN := $(word $(shell echo | awk '{print 1+int(rand()*$(words $(DOMAINS)))}'), $(DOMAINS))
distclean: clean_docker clean_markers
$(MARKERS):
mkdir -p $(MARKERS)
DOCKER_COMPOSE := docker-compose
DOCKER_COMPOSE_ENV ?= chronicle-environment
DOCKER_BUILD := docker buildx build
DOCKER_TAG := docker tag
.PHONY: clean_docker
clean_docker: clean
docker buildx rm ctx-$(ISOLATION_ID) || true
docker buildx rm ctx-$(ISOLATION_ID)-id || true
docker buildx rm ctx-$(ISOLATION_ID)-ir || true
docker buildx rm ctx-$(ISOLATION_ID)-sd || true
docker buildx rm ctx-$(ISOLATION_ID)-sr || true
define domain_tmpl =
.PHONY: all-domains
all-domains: $(1)
.PHONY: inmem
inmem: $(1)-inmem
.PHONY: stl
stl: $(1)-stl
.PHONY: inmem-release
inmem-release: $(1)-inmem-release
.PHONY: stl-release
stl-release: $(1)-stl-release
$(1): $(1)-inmem $(1)-stl $(1)-sdl $(1)-diagrams
$(1)-inmem: $(1)-inmem-debug $(1)-inmem-release
$(1)-stl: $(1)-stl-debug $(1)-stl-release
$(1)-diagrams:
ifeq (,$(shell command -v plantuml))
@echo "Skipping $(1) diagrams, no plantuml"
else
@echo "Building $(1) diagrams"
$(foreach DIAGRAM,$(wildcard domains/$(1)/diagrams/*.puml),plantuml -tsvg -nometadata "$(DIAGRAM)";)
endif
.PHONY: $(1)-lint
$(1)-lint:
@echo "Checking domain definition for $(1)"
@docker run --volume $(shell pwd)/domains/$(1):/mnt \
--entrypoint /usr/local/bin/chronicle-domain-lint --rm \
$(CHRONICLE_BUILDER_IMAGE):$(CHRONICLE_VERSION) /mnt/domain.yaml
lint: $(1)-lint
.PHONY: $(MARKERS)/ensure-context-$(1)-inmem-debug
$(MARKERS)/ensure-context-$(1)-inmem-debug: $(MARKERS)
docker buildx create --name ctx-$(ISOLATION_ID)-id \
--driver docker-container \
--driver-opt network=host \
--bootstrap || true
docker buildx use ctx-$(ISOLATION_ID)-id
touch $(MARKERS)/ensure-context-$(1)-inmem-debug
.PHONY: $(MARKERS)/ensure-context-$(1)-stl-debug
$(MARKERS)/ensure-context-$(1)-stl-debug: $(MARKERS)
docker buildx create --name ctx-$(ISOLATION_ID)-sd \
--driver docker-container \
--driver-opt network=host \
--bootstrap || true
docker buildx use ctx-$(ISOLATION_ID)-sd
touch $(MARKERS)/ensure-context-$(1)-stl-debug
.PHONY: $(MARKERS)/ensure-context-$(1)-inmem-release
$(MARKERS)/ensure-context-$(1)-inmem-release: $(MARKERS)
docker buildx create --name ctx-$(ISOLATION_ID)-ir \
--driver docker-container \
--driver-opt network=host \
--bootstrap || true
docker buildx use ctx-$(ISOLATION_ID)-ir
touch $(MARKERS)/ensure-context-$(1)-inmem-release
.PHONY: $(MARKERS)/ensure-context-$(1)-stl-release
$(MARKERS)/ensure-context-$(1)-stl-release: $(MARKERS)
docker buildx create --name ctx-$(ISOLATION_ID)-sr \
--driver docker-container \
--driver-opt network=host \
--bootstrap || true
docker buildx use ctx-$(ISOLATION_ID)-sr
touch $(MARKERS)/ensure-context-$(1)-stl-release
.PHONY: ($1)-inmem-debug
$(1)-inmem-debug: $(MARKERS)/ensure-context-$(1)-inmem-debug domains/$(1)/domain.yaml $(1)-lint
@echo "Building $(1) debug inmem as docker image chronicle-$(1)-inmem-debug:$(ISOLATION_ID)"
$(DOCKER_BUILD) -f docker/chronicle.dockerfile \
--builder ctx-$(ISOLATION_ID)-id \
--tag chronicle-domain:$(ISOLATION_ID) \
--build-arg CHRONICLE_VERSION=$(CHRONICLE_VERSION) \
--build-arg CHRONICLE_BUILDER_IMAGE=$(CHRONICLE_BUILDER_IMAGE) \
--build-arg RELEASE=no \
--build-arg FEATURES=inmem \
--build-arg DOMAIN=$(1) . \
--load
@$(DOCKER_TAG) chronicle-domain:$(ISOLATION_ID) \
chronicle-$(1)-inmem-debug:$(ISOLATION_ID)
@$(DOCKER_TAG) chronicle-domain:$(ISOLATION_ID) \
chronicle-$(1)-inmem:$(ISOLATION_ID)
# the tag chronicle-$(1)-inmem is deprecated, always append -debug (or -release)
.PHONY: $(1)-stl-debug
$(1)-stl-debug: $(MARKERS)/ensure-context-$(1)-stl-debug domains/$(1)/domain.yaml $(1)-lint policies/bundle.tar.gz
@echo "Building $(1) debug chronicle stl as docker image as docker image chronicle-$(1)-stl-debug:$(ISOLATION_ID)"
@$(DOCKER_BUILD) -f docker/chronicle.dockerfile \
--builder ctx-$(ISOLATION_ID)-sd \
--tag chronicle-domain:$(ISOLATION_ID) \
--build-arg CHRONICLE_VERSION=$(CHRONICLE_VERSION) \
--build-arg CHRONICLE_BUILDER_IMAGE=$(CHRONICLE_BUILDER_IMAGE) \
--build-arg RELEASE=no \
--build-arg FEATURES="" \
--build-arg DOMAIN=$(1) . \
--load
@$(DOCKER_TAG) chronicle-domain:$(ISOLATION_ID) \
chronicle-$(1)-stl-debug:$(ISOLATION_ID)
@$(DOCKER_TAG) chronicle-domain:$(ISOLATION_ID) \
chronicle-$(1)-stl:$(ISOLATION_ID)
# the tag chronicle-$(1)-stl is deprecated, always append -debug (or -release)
.PHONY: $(1)-inmem-release
$(1)-inmem-release: $(MARKERS)/ensure-context-$(1)-inmem-release domains/$(1)/domain.yaml $(1)-lint
@echo "Building $(1) release inmem as docker image chronicle-$(1)-inmem-release:$(ISOLATION_ID)"
@$(DOCKER_BUILD) -f docker/chronicle.dockerfile \
--builder ctx-$(ISOLATION_ID)-ir \
--tag chronicle-domain:$(ISOLATION_ID) \
--build-arg CHRONICLE_VERSION=$(CHRONICLE_VERSION) \
--build-arg CHRONICLE_BUILDER_IMAGE=$(CHRONICLE_BUILDER_IMAGE) \
--build-arg RELEASE=yes \
--build-arg FEATURES=inmem \
--build-arg DOMAIN=$(1) . \
--load
@$(DOCKER_TAG) chronicle-domain:$(ISOLATION_ID) \
chronicle-$(1)-inmem-release:$(ISOLATION_ID)
.PHONY: $(1)-stl-release
$(1)-stl-release: $(MARKERS)/ensure-context-$(1)-stl-release domains/$(1)/domain.yaml $(1)-lint policies/bundle.tar.gz
@echo "Building $(1) release chronicle stl as docker image chronicle-$(1)-stl-release:$(ISOLATION_ID)"
@$(DOCKER_BUILD) -f docker/chronicle.dockerfile \
--builder ctx-$(ISOLATION_ID)-sr \
--tag chronicle-domain:$(ISOLATION_ID) \
--build-arg CHRONICLE_VERSION=$(CHRONICLE_VERSION) \
--build-arg CHRONICLE_BUILDER_IMAGE=$(CHRONICLE_BUILDER_IMAGE) \
--build-arg RELEASE=yes \
--build-arg FEATURES="" \
--build-arg DOMAIN=$(1) . \
--load
@$(DOCKER_TAG) chronicle-domain:$(ISOLATION_ID) \
chronicle-$(1)-stl-release:$(ISOLATION_ID)
domains/$(1)/chronicle.graphql: $(1)-inmem-release
@echo "Generating $(1) GraphQL schema in file: domains/$(1)/chronicle.graphql"
@docker run --env RUST_LOG=info chronicle-$(1)-inmem-release:$(ISOLATION_ID) \
export-schema > domains/$(1)/chronicle.graphql
.PHONY: clean-graphql-$(1)
clean-graphql-$(1):
rm -f domains/$(1)/chronicle.graphql
.PHONY: $(1)-sdl
$(1)-sdl: domains/$(1)/chronicle.graphql
.PHONY: run-$(1)
run-$(1): $(1)-inmem-debug
export CHRONICLE_IMAGE=chronicle-$(1)-inmem-debug; \
export CHRONICLE_VERSION=$(ISOLATION_ID); \
export CHRONICLE_ENV_FILE=$(DOCKER_COMPOSE_ENV); \
$(DOCKER_COMPOSE) -f ./docker/chronicle-domain.yaml up --force-recreate
.PHONY: run-stl-$(1)
run-stl-$(1): $(1)-stl-debug
export CHRONICLE_IMAGE=chronicle-$(1)-stl-debug; \
export CHRONICLE_TP_IMAGE=$(CHRONICLE_TP_IMAGE); \
export CHRONICLE_VERSION=$(ISOLATION_ID); \
export CHRONICLE_TP_VERSION=$(CHRONICLE_VERSION); \
export CHRONICLE_ENV_FILE=$(DOCKER_COMPOSE_ENV); \
$(DOCKER_COMPOSE) -f docker/chronicle.yaml up --force-recreate -d
.PHONY: stop-stl-$(1)
stop-stl-$(1): $(1)-stl-debug
export CHRONICLE_IMAGE=chronicle-$(1)-stl-debug; \
export CHRONICLE_TP_IMAGE=$(CHRONICLE_TP_IMAGE); \
export CHRONICLE_VERSION=$(ISOLATION_ID); \
export CHRONICLE_TP_VERSION=$(CHRONICLE_VERSION); \
export CHRONICLE_ENV_FILE=$(DOCKER_COMPOSE_ENV); \
$(DOCKER_COMPOSE) -f docker/chronicle.yaml down
.PHONY: clean-images-$(1)
clean-images-$(1): $(MARKERS)
docker buildx rm ctx-$(ISOLATION_ID) || true
docker rmi chronicle-$(1)-inmem:$(ISOLATION_ID) || true
docker rmi chronicle-$(1)-inmem-release:$(ISOLATION_ID) || true
docker rmi chronicle-$(1)-inmem-debug:$(ISOLATION_ID) || true
docker rmi chronicle-$(1)-stl:$(ISOLATION_ID) || true
docker rmi chronicle-$(1)-stl-release:$(ISOLATION_ID) || true
docker rmi chronicle-$(1)-stl-debug:$(ISOLATION_ID) || true
docker rmi chronicle-test$(ISOLATION_ID) || true
rm -f $(MARKERS)/*-$(1)
clean-$(1): clean-images-$(1) clean-graphql-$(1)
clean: clean-$(1)
endef
.PHONY: build-end-to-end-test
build-end-to-end-test: $(TEST_DOMAIN)-stl-release
docker build -t chronicle-test:$(ISOLATION_ID) -f docker/chronicle-test/chronicle-test.dockerfile .
.PHONY: test-e2e
test-e2e: policies/bundle.tar.gz build-end-to-end-test
CHRONICLE_IMAGE=chronicle-$(TEST_DOMAIN)-stl-release \
CHRONICLE_VERSION=$(ISOLATION_ID) \
CHRONICLE_TP_IMAGE=$(CHRONICLE_TP_IMAGE) \
CHRONICLE_TP_VERSION=$(CHRONICLE_VERSION) \
$(DOCKER_COMPOSE) -f docker/chronicle-test.yaml up --exit-code-from chronicle-test
test:
$(foreach domain,$(DOMAINS),$(eval $(call domain_tmpl,$(domain))))
.PHONY: sdl
sdl: $(foreach domain,$(DOMAINS), $(domain)-sdl )
.PHONY: build
build: sdl
uname_S := $(shell uname -s)
uname_M := $(shell uname -m)
ifeq ($(uname_S), Linux)
OS = linux
OPA_SUFFIX = _static
else ifeq ($(uname_S), Darwin)
OS = darwin
else
OS = windows
ARCH = amd64
endif
ifeq ($(uname_M), x86_64)
ARCH = amd64
else ifeq ($(uname_M), arm)
ARCH = arm64
OPA_SUFFIX = _static
else ifeq ($(uname_M), arm64)
ARCH = arm64
OPA_SUFFIX = _static
else ifeq ($(uname_M), aarch64)
ARCH = arm64
OPA_SUFFIX = _static
endif
OPA_VERSION=v0.49.2
OPA_DOWNLOAD_URL=https://openpolicyagent.org/downloads/$(OPA_VERSION)/opa_$(OS)_$(ARCH)$(OPA_SUFFIX)
build/opa:
mkdir -p build
curl -sSL -o build/opa $(OPA_DOWNLOAD_URL)
chmod 755 build/opa
policies/bundle.tar.gz: build/opa
mkdir -p policies
build/opa build -t wasm -o policies/bundle.tar.gz -b policies -e "allow_transactions" -e "common_rules"
clean: clean-opa
.PHONY: clean-opa
clean-opa:
$(RM) policies/*.tar.gz