-
Notifications
You must be signed in to change notification settings - Fork 1
/
opa.mk
129 lines (98 loc) · 3.6 KB
/
opa.mk
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
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 := opa-tp opactl
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)
clean: clean_containers clean_target
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/opa-tp `pwd`/target/amd64/; \
docker rm $$container_id;
container_id=$$(docker create chronicle-amd64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/opctl `pwd`/target/amd64/; \
docker rm $$container_id;
container_id=$$(docker create chronicle-tp-arm64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/opa-tp `pwd`/target/arm64; \
docker rm $$container_id;
container_id=$$(docker create chronicle-arm64:${ISOLATION_ID}); \
docker cp $$container_id:/usr/local/bin/opactl `pwd`/target/arm64; \
docker rm $$container_id;
if [ "$(RELEASABLE)" = "yes" ]; then \
$(GH_RELEASE) upload $(VERSION) target/* ; \
fi
.PHONY: build-end-to-end-test
build-end-to-end-test:
docker build -t opa-test:$(ISOLATION_ID) --build-arg TARGETARCH=$(HOST_ARCHITECTURE) --build-arg ISOLATION_ID=$(ISOLATION_ID) -f docker/opa-test/opa-test.dockerfile .
.PHONY: test-e2e
test-e2e: build-end-to-end-test
$(COMPOSE) -f docker/opa-test.yaml up --force-recreate --exit-code-from opa-test
run:
$(COMPOSE) -f docker/opa.yaml up -d
.PHONY: stop
stop:
$(COMPOSE) -f docker/opa.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: tested-$(ISOLATION_ID)
tested-$(ISOLATION_ID): ensure-context-opa-tp
docker buildx build $(DOCKER_PROGRESS) \
-f./docker/opa-builder \
-t tested-artifacts:$(ISOLATION_ID) . \
--builder ctx-$(ISOLATION_ID) \
--platform linux/$(HOST_ARCHITECTURE) \
--target tested-artifacts \
--cache-to type=local,dest=.buildx-cache \
--cache-from type=local,src=.buildx-cache \
--load
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 multi-arch-docker =
.PHONY: ensure-context-$(1)
$(1)-$(2)-ensure-context: $(MARKERS)/binfmt
docker buildx create --name ctx-$(ISOLATION_ID) \
--driver docker-container \
--bootstrap || true
docker buildx use ctx-$(ISOLATION_ID)
.PHONY: $(1)-$(2)-build
$(1)-$(2)-build: $(1)-$(2)-ensure-context tested-$(ISOLATION_ID)
docker buildx build $(DOCKER_PROGRESS) \
-f./docker/opa-builder \
-t $(1)-$(2):$(ISOLATION_ID) . \
--builder ctx-$(ISOLATION_ID) \
--build-arg TARGETARCH=$(2) \
--platform linux/$(2) \
--target $(1) \
--load
$(1)-manifest: $(1)-$(2)-build
docker manifest create $(1):$(ISOLATION_ID) \
-a $(1)-$(2):$(ISOLATION_ID)
$(1): $(1)-$(2)-build
build: $(1)
build-native: $(1)-$(HOST_ARCHITECTURE)-build
endef
$(foreach image,$(IMAGES),$(foreach arch,$(ARCHS),$(eval $(call multi-arch-docker,$(image),$(arch)))))
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