-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
210 lines (166 loc) · 5.58 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
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(MAKEFILE_DIR)/standard_defs.mk
export OPENSSL_STATIC=1
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
IMAGES := chronicle chronicle-tp chronicle-builder opa-tp opactl id-provider chronicle-helm-api-test
ARCHS := amd64 arm64
COMPOSE ?= docker-compose
HOST_ARCHITECTURE ?= $(shell uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
CLEAN_DIRS := $(CLEAN_DIRS)
DOCKER_GID := $(shell getent group docker | cut -f 3 -d :)
clean: clean_containers clean_target clean-opa
distclean: clean_docker clean_markers
analyze: analyze_fossa
publish: gh-create-draft-release
mkdir -p target/arm64
mkdir -p target/amd64
container_id=$$(docker create chronicle-tp-amd64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/chronicle_sawtooth_tp `pwd`/target/amd64/; \
docker rm $$container_id;
container_id=$$(docker create chronicle-amd64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/chronicle `pwd`/target/amd64/; \
docker rm $$container_id;
ifeq ($(RELEASABLE), yes)
container_id=$$(docker create chronicle-tp-arm64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/chronicle_sawtooth_tp `pwd`/target/arm64; \
docker rm $$container_id;
container_id=$$(docker create chronicle-arm64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/chronicle `pwd`/target/arm64; \
docker rm $$container_id;
#$(GH_RELEASE) upload $(VERSION) target/*
endif
.PHONY: build-end-to-end-test
build-end-to-end-test:
docker build -t chronicle-test:$(ISOLATION_ID) -f docker/chronicle-test/chronicle-test.dockerfile .
.PHONY: test-chronicle-e2e
test-chronicle-e2e: build-end-to-end-test
$(COMPOSE) -f docker/chronicle-test.yaml up --exit-code-from chronicle-test
.PHONY: test-e2e
test-e2e: test-chronicle-e2e
run:
$(COMPOSE) -f docker/chronicle.yaml up -d
.PHONY: stop
stop:
$(COMPOSE) -f docker/chronicle.yaml down || true
$(MARKERS)/binfmt:
mkdir -p $(MARKERS)
if [ `uname -m` = "x86_64" ]; then \
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \
fi
touch $@
# Run the compiler for host and target, then extract the binaries
.PHONY: test-prep-$(ISOLATION_ID)
test-prep-$(ISOLATION_ID): $(HOST_ARCHITECTURE)-ensure-context
docker buildx build $(DOCKER_PROGRESS) \
-f./docker/unified-builder \
-t tested-artifacts:$(ISOLATION_ID) . \
--builder ctx-$(ISOLATION_ID)-$(HOST_ARCHITECTURE) \
--platform linux/$(HOST_ARCHITECTURE) \
--target test \
--load
.PHONY: tested-$(ISOLATION_ID)
test: tested-$(ISOLATION_ID)
tested-$(ISOLATION_ID): test-prep-$(ISOLATION_ID)
container_id=$$(docker run -d \
-v $(DOCKER_SOCK):/var/run/docker.sock \
tested-artifacts:${ISOLATION_ID} sleep 1d); \
docker exec --user root $$container_id groupadd -g $(DOCKER_GID) docker \
&& docker exec --user root $$container_id usermod -aG docker tester \
&& docker exec $$container_id cargo test --locked --release \
&& docker rm -f $$container_id
rm -rf .artifacts
mkdir -p .artifacts
container_id=$$(docker create tested-artifacts:${ISOLATION_ID}); \
docker cp $$container_id:/artifacts `pwd`/.artifacts/ \
&& docker rm $$container_id
.PHONY: test-e2e
test: test-e2e
define arch-contexts =
.PHONY: $(1)-ensure-context
$(1)-ensure-context: $(MARKERS)/binfmt
docker buildx create --name ctx-$(ISOLATION_ID)-$(1) \
--config buildkit.toml \
--driver docker-container \
--bootstrap || true
docker buildx use ctx-$(ISOLATION_ID)-$(1)
.PHONY: clean-$(1)-ensure-context
clean: clean-$(1)-ensure-context
clean-$(1)-ensure-context:
@docker buildx rm ctx-$(ISOLATION_ID)-$(1) || true
endef
$(foreach arch,$(ARCHS),$(eval $(call arch-contexts,$(arch))))
define multi-arch-docker =
.PHONY: $(1)-$(2)-build
$(1)-$(2)-build: $(2)-ensure-context policies/bundle.tar.gz
docker buildx build $(DOCKER_PROGRESS) \
-f./docker/unified-builder \
-t $(1)-$(2):$(ISOLATION_ID) . \
--builder ctx-$(ISOLATION_ID)-$(2) \
--platform linux/$(2) \
--target $(1) \
--load
$(1)-manifest: $(1)-$(2)-manifest
$(1)-$(2)-manifest: $(1)-$(2)-build
docker manifest create $(1):$(ISOLATION_ID) \
-a $(1)-$(2):$(ISOLATION_ID)
ifeq ($(RELEASABLE), yes)
$(1): $(1)-$(2)-build
else
ifeq ($(2), $(HOST_ARCHITECTURE))
$(1): $(1)-$(2)-build
endif
endif
build: .VERSION $(1)
build-native: $(1)-$(HOST_ARCHITECTURE)-build
endef
$(foreach image,$(IMAGES),$(foreach arch,$(ARCHS),$(eval $(call multi-arch-docker,$(image),$(arch)))))
.PHONY: .VERSION
.VERSION:
git describe --tags > .VERSION
clean_containers:
$(COMPOSE) -f docker/chronicle.yaml rm -f || true
clean_docker: stop
$(COMPOSE) -f docker/chronicle.yaml down -v --rmi all || true
clean_target:
$(RM) -r target
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:
curl -sSL -o build/opa $(OPA_DOWNLOAD_URL)
chmod 755 build/opa
build: policies/bundle.tar.gz
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"
test: opa-test
.PHONY: opa-test
opa-test: build/opa
build/opa test -b policies
clean: clean-opa
.PHONY: clean-opa
clean-opa:
$(RM) policies/*.tar.gz