forked from veracruz-project/veracruz-docker-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
210 lines (172 loc) · 7.28 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
VERACRUZ_DOCKER_IMAGE ?= veracruz_image
VERACRUZ_CONTAINER ?= veracruz
VERACRUZ_ROOT ?= ..
USER ?= $(shell id -un)
UID ?= $(shell id -u)
OS_NAME := $(shell uname -s | tr A-Z a-z)
AWS_NITRO_CLI_REVISION = v1.1.0
NIX_VOLUME = veracruz-icecap-nix-root
NE_GID := $(shell getent group ne | awk -F: '{printf $$3}')
ifeq ($(OS_NAME),darwin)
LOCALIP = $(shell "(ifconfig en0 ; ifconfig en1) | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'")
DOCKER_GROUP_ID=$(shell stat -f "%g" $(shell realpath /var/run/docker.sock))
else
LOCALIP = $(shell ip -4 address show eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*')
DOCKER_GROUP_ID=$(shell stat --format "%g" $(shell realpath /var/run/docker.sock))
endif
BUILD_ARCH = --build-arg ARCH=$(shell uname -m)
DOCKER_RUN_PARAMS = \
-v $(abspath $(VERACRUZ_ROOT)):/work/veracruz \
-v $(HOME)/.cargo/registry/:/usr/local/cargo/registry/
.PHONY:
default:
#####################################################################
# Shared targets
.PHONY:
base: base/Dockerfile
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) -t veracruz/base -f $< .
.PHONY:
%-build: Dockerfile %-base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) \
--build-arg USER=$(USER) --build-arg UID=$(UID) --build-arg TEE=$* \
--build-arg DOCKER_GROUP_ID=$(DOCKER_GROUP_ID) \
-t $(VERACRUZ_DOCKER_IMAGE)_$*:$(USER) --progress=plain -f $< .
.PHONY:
all-base: base linux-base nitro-base
echo 'All base docker images re-built from scratch'
.PHONY:
pull-base:
docker pull veracruz/base
docker pull veracruz/linux
docker pull veracruz/nitro
#####################################################################
# CI-related targets
#
.PHONY: ci-unity-run ci-unity-exec ci-unity-base \
ci-images ci-icecap ci-linux ci-nitro
ci-unity-run: ci-unity-build
docker run --init --privileged --rm -d \
-v /work/cache:/cache \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(abspath $(VERACRUZ_ROOT)):/work/veracruz \
--name $(VERACRUZ_CONTAINER)_ci_$(USER) \
$(VERACRUZ_DOCKER_IMAGE)_ci:$(USER) sleep inf
ci-unity-exec:
docker exec -u root -i -t $(VERACRUZ_CONTAINER)_ci_$(USER) /bin/bash || true
ci-unity-base: ci/Dockerfile nitro-base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) \
--build-arg USER=root --build-arg UID=0 \
--build-arg ICECAP_REV=$(shell GIT_DIR=../icecap/icecap/.git git rev-parse HEAD) \
--build-arg TEE=ci -t veracruz/ci -f $< .
ci-images: ci-icecap ci-linux ci-nitro
docker tag veracruz/ci-icecap:latest ghcr.io/veracruz-project/veracruz/veracruz-ci-icecap:ci-v2
docker tag veracruz/ci-linux:latest ghcr.io/veracruz-project/veracruz/veracruz-ci-linux:ci-v2
docker tag veracruz/ci-nitro:latest ghcr.io/veracruz-project/veracruz/veracruz-ci-nitro:ci-v2
ci-icecap: ci/icecap/Dockerfile base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) \
--build-arg USER=root --build-arg UID=0 \
--build-arg ICECAP_REV=$(shell GIT_DIR=../icecap/icecap/.git git rev-parse HEAD) \
--build-arg TEE=ci -t veracruz/ci-icecap -f $< .
ci-linux: ci/linux/Dockerfile base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) \
--build-arg USER=root --build-arg UID=0 \
--build-arg TEE=ci -t veracruz/ci-linux -f $< .
ci-nitro: ci/nitro/Dockerfile nitro-base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) \
--build-arg USER=root --build-arg UID=0 \
--build-arg TEE=ci -t veracruz/ci-nitro -f $< .
# "localci" is similar to "ci-unity" but uses "icecap/hacking" with local volume
# to cache nix store.
.PHONY:
localci-run: localci-build icecap-initialize-volume
docker run --init --privileged --rm -d $(DOCKER_RUN_PARAMS) \
-v /work/cache:/cache \
-v /var/run/docker.sock:/var/run/docker.sock \
--mount type=volume,src=$(NIX_VOLUME),dst=/nix \
--name $(VERACRUZ_CONTAINER)_localci_$(USER) \
$(VERACRUZ_DOCKER_IMAGE)_localci:$(USER) sleep inf
.PHONY:
localci-exec:
docker exec -i -t $(VERACRUZ_CONTAINER)_localci_$(USER) /bin/bash || true
.PHONY:
localci-base: localci/Dockerfile nitro-base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) \
--build-arg TEE=ci -t veracruz/localci -f $< .
#####################################################################
# IceCap-related targets
.PHONY:
icecap-initialize-volume: icecap-build
if [ -z "$$(docker volume ls -q -f "name=$(NIX_VOLUME)")" ]; then \
docker volume create --label $(VERACRUZ_CONTAINER)_icecap_$(USER) \
$(NIX_VOLUME) && \
docker run --privileged --rm -u root --label $(VERACRUZ_CONTAINER)_icecap_$(USER) \
-w /work --mount type=volume,src=$(NIX_VOLUME),dst=/nix \
$(VERACRUZ_DOCKER_IMAGE)_icecap:$(USER) flock /nix/.installed.lock bash /work/setup.sh $(USER); \
fi
.PHONY:
icecap-run: icecap-build icecap-initialize-volume
docker run --init --privileged -d $(DOCKER_RUN_PARAMS) \
--mount type=volume,src=$(NIX_VOLUME),dst=/nix \
--name $(VERACRUZ_CONTAINER)_icecap_$(USER) \
$(VERACRUZ_DOCKER_IMAGE)_icecap:$(USER) sleep inf
.PHONY:
icecap-exec:
docker exec -i -t $(VERACRUZ_CONTAINER)_icecap_$(USER) /bin/bash || true
.PHONY:
icecap-base: icecap/hacking/Dockerfile base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) -t veracruz/icecap -f $< .
.PHONY: icecap-clean
icecap-clean:
for volume in $$(docker volume ls -q -f "name=$(NIX_VOLUME)"); do \
docker volume rm $$volume; \
done
#####################################################################
# Linux-related targets
.PHONY:
linux-run: linux-build
docker run --init --privileged -d $(DOCKER_RUN_PARAMS) \
--name $(VERACRUZ_CONTAINER)_linux_$(USER) \
$(VERACRUZ_DOCKER_IMAGE)_linux:$(USER) sleep inf
.PHONY:
linux-exec:
docker exec -i -t $(VERACRUZ_CONTAINER)_linux_$(USER) /bin/bash || true
.PHONY:
linux-base: linux/Dockerfile base
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) -t veracruz/linux -f $< .
#####################################################################
# Nitro-related targets
.PHONY:
nitro-run: nitro-build
# This container must be started on a "Nitro Enclave"-capable AWS instance
docker run --init --privileged -d $(DOCKER_RUN_PARAMS) \
-v /usr/bin:/host/bin \
-v /usr/share/nitro_enclaves:/usr/share/nitro_enclaves \
-v /run/nitro_enclaves:/run/nitro_enclaves \
-v /etc/nitro_enclaves:/etc/nitro_enclaves \
--device=/dev/vsock:/dev/vsock \
--device=/dev/nitro_enclaves:/dev/nitro_enclaves \
-v /var/run/docker.sock:/var/run/docker.sock \
-p $(LOCALIP):3010:3010/tcp \
--name $(VERACRUZ_CONTAINER)_nitro_$(USER) \
$(VERACRUZ_DOCKER_IMAGE)_nitro:$(USER) sleep inf
.PHONY:
nitro-run-build: nitro-build
# This container does not need to be run in AWS, it can build but not start enclaves
docker run --init --privileged -d $(DOCKER_RUN_PARAMS) \
-v /var/run/docker.sock:/var/run/docker.sock \
-p $(LOCALIP):3010:3010/tcp \
--name $(VERACRUZ_CONTAINER)_nitro_$(USER) \
$(VERACRUZ_DOCKER_IMAGE)_nitro:$(USER) sleep inf
.PHONY:
nitro-exec:
docker exec -i -t $(VERACRUZ_CONTAINER)_nitro_$(USER) /bin/bash || true
.PHONY:
nitro-base: nitro/Dockerfile base
ifeq (,$(wildcard aws-nitro-enclaves-cli))
git clone https://github.com/aws/aws-nitro-enclaves-cli.git
endif
cd "aws-nitro-enclaves-cli" && git checkout $(AWS_NITRO_CLI_REVISION) || \
(git fetch ; git checkout $(AWS_NITRO_CLI_REVISION))
perl -i -pe 's/readlink -f/realpath/' aws-nitro-enclaves-cli/Makefile # Work-around to build on Mac
make -C aws-nitro-enclaves-cli nitro-cli
DOCKER_BUILDKIT=1 docker build $(BUILD_ARCH) --build-arg NE_GID=$(NE_GID) -t veracruz/nitro -f $< .