forked from firecracker-microvm/firecracker-containerd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
340 lines (271 loc) · 12.2 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
SUBDIRS:=agent runtime examples firecracker-control/cmd/containerd
TEST_SUBDIRS:=$(addprefix test-,$(SUBDIRS))
INTEG_TEST_SUBDIRS:=$(addprefix integ-test-,$(SUBDIRS))
export INSTALLROOT?=/usr/local
export STATIC_AGENT
export DOCKER_IMAGE_TAG?=latest
GOMOD := $(shell go env GOMOD)
GOSUM := $(GOMOD:.mod=.sum)
GOPATH:=$(shell go env GOPATH)
BINPATH:=$(abspath ./bin)
SUBMODULES=_submodules
UID:=$(shell id -u)
GID:=$(shell id -g)
FIRECRACKER_CONTAINERD_BUILDER_IMAGE?=golang:1.13-buster
export FIRECRACKER_CONTAINERD_TEST_IMAGE?=localhost/firecracker-containerd-test
export GO_CACHE_VOLUME_NAME?=gocache
# This Makefile uses Firecracker's pre-build Linux kernels for x86_64 and aarch64.
host_arch=$(shell arch)
ifeq ($(host_arch),x86_64)
kernel_sha256sum="ea5e7d5cf494a8c4ba043259812fc018b44880d70bcbbfc4d57d2760631b1cd6"
else ifeq ($(host_arch),aarch64)
kernel_sha256sum="e2d7c3d6cc123de9e6052d1f434ca7b47635a1f630d63f7fcc1b7164958375e4"
else
$(error "$(host_arch) is not supported by Firecracker")
endif
FIRECRACKER_TARGET?=$(host_arch)-unknown-linux-musl
FIRECRACKER_DIR=$(SUBMODULES)/firecracker
FIRECRACKER_BIN=$(FIRECRACKER_DIR)/build/cargo_target/$(FIRECRACKER_TARGET)/release/firecracker
FIRECRACKER_BUILDER_NAME?=firecracker-builder
CARGO_CACHE_VOLUME_NAME?=cargocache
RUNC_DIR=$(SUBMODULES)/runc
RUNC_BIN=$(RUNC_DIR)/runc
RUNC_BUILDER_NAME?=runc-builder
PROTO_BUILDER_NAME?=proto-builder
# Set this to pass additional commandline flags to the go compiler, e.g. "make test EXTRAGOARGS=-v"
export EXTRAGOARGS?=
all: $(SUBDIRS) $(GOMOD) $(GOSUM) cni-bins test-cni-bins
$(SUBDIRS):
$(MAKE) -C $@ EXTRAGOARGS=$(EXTRAGOARGS)
%-in-docker:
docker run --rm \
--user $(UID):$(GID) \
--volume $(CURDIR):/src \
--volume $(GO_CACHE_VOLUME_NAME):/go \
--env HOME=/tmp \
--env GOPATH=/go \
--env GO111MODULES=on \
--env STATIC_AGENT=on \
--env GOPROXY=$(shell go env GOPROXY) \
--workdir /src \
$(FIRECRACKER_CONTAINERD_BUILDER_IMAGE) \
$(MAKE) $(subst -in-docker,,$@)
proto:
DOCKER_BUILDKIT=1 docker build \
--file tools/docker/Dockerfile.proto-builder \
--tag localhost/$(PROTO_BUILDER_NAME):${DOCKER_IMAGE_TAG} \
$(CURDIR)/tools/docker
PATH=$(BINPATH):$(PATH) $(MAKE) -C proto/ proto-docker
clean:
for d in $(SUBDIRS); do $(MAKE) -C $$d clean; done
- rm -rf $(BINPATH)/
$(MAKE) -C $(RUNC_DIR) clean
$(MAKE) firecracker-clean
rm -f tools/*stamp *stamp
$(MAKE) -C tools/image-builder clean-in-docker
rm -f $(DEFAULT_VMLINUX_NAME)
rmi-if-exists = $(if $(shell docker images -q $(1)),docker rmi $(1),true)
distclean: clean
for d in $(SUBDIRS); do $(MAKE) -C $$d distclean; done
$(MAKE) -C tools/image-builder distclean
$(call rmi-if-exists,localhost/$(RUNC_BUILDER_NAME):$(DOCKER_IMAGE_TAG))
$(call rmi-if-exists,localhost/$(FIRECRACKER_BUILDER_NAME):$(DOCKER_IMAGE_TAG))
docker volume rm -f $(CARGO_CACHE_VOLUME_NAME)
docker volume rm -f $(GO_CACHE_VOLUME_NAME)
$(call rmi-if-exists,$(FIRECRACKER_CONTAINERD_TEST_IMAGE):$(DOCKER_IMAGE_TAG))
$(call rmi-if-exists,localhost/$(PROTO_BUILDER_NAME):$(DOCKER_IMAGE_TAG))
lint:
$(BINPATH)/ltag -t ./.headers -excludes "tools $(SUBMODULES)" -check -v
$(BINPATH)/git-validation -run DCO,short-subject -range HEAD~20..HEAD
$(BINPATH)/golangci-lint run
tidy:
go mod tidy
deps:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(BINPATH) v1.21.0
$(BINPATH)/golangci-lint --version
GOBIN=$(BINPATH) GO111MODULE=off go get -u github.com/vbatts/git-validation
GOBIN=$(BINPATH) GO111MODULE=off go get -u github.com/kunalkushwaha/ltag
install:
for d in $(SUBDIRS); do $(MAKE) -C $$d install; done
image: $(RUNC_BIN) agent-in-docker
mkdir -p tools/image-builder/files_ephemeral/usr/local/bin
mkdir -p tools/image-builder/files_ephemeral/var/firecracker-containerd-test/scripts
for f in tools/docker/scripts/*; do test -f $$f && install -m 755 $$f tools/image-builder/files_ephemeral/var/firecracker-containerd-test/scripts; done
cp $(RUNC_BIN) tools/image-builder/files_ephemeral/usr/local/bin
cp agent/agent tools/image-builder/files_ephemeral/usr/local/bin
touch tools/image-builder/files_ephemeral
$(MAKE) -C tools/image-builder all-in-docker
test: $(TEST_SUBDIRS)
go test ./... $(EXTRAGOARGS)
# test-in-docker runs all unit tests inside a docker container. Use "integ-test" to
# run the integ-tests inside containers.
test-in-docker:
docker run --rm -it \
--user $(UID):$(GID) \
--volume $(CURDIR):/src \
--volume $(GO_CACHE_VOLUME_NAME):/go \
--env HOME=/tmp \
--env GOPATH=/go \
--env EXTRAGOARGS="$(EXTRAGOARGS)" \
--entrypoint=/bin/bash \
--workdir /src \
$(FIRECRACKER_CONTAINERD_BUILDER_IMAGE) \
-c "make test"
$(TEST_SUBDIRS):
$(MAKE) -C $(patsubst test-%,%,$@) test
integ-test: $(INTEG_TEST_SUBDIRS)
$(INTEG_TEST_SUBDIRS): test-images
$(MAKE) -C $(patsubst integ-test-%,%,$@) integ-test
test-images: test-images-stamp
test-images-stamp: | image firecracker-containerd-test-image
touch $@
firecracker-containerd-test-image: all-in-docker firecracker runc test-cni-bins cni-bins default-vmlinux
DOCKER_BUILDKIT=1 docker build \
--progress=plain \
--file tools/docker/Dockerfile.integ-test \
--build-arg FIRECRACKER_TARGET=$(FIRECRACKER_TARGET) \
--tag $(FIRECRACKER_CONTAINERD_TEST_IMAGE):${DOCKER_IMAGE_TAG} .
.PHONY: all $(SUBDIRS) clean proto deps lint install image test-images firecracker-container-test-image firecracker-containerd-integ-test-image test test-in-docker $(TEST_SUBDIRS) integ-test $(INTEG_TEST_SUBDIRS) tidy
##########################
# Runtime config
##########################
FIRECRACKER_CONTAINERD_RUNTIME_DIR?=/var/lib/firecracker-containerd/runtime
ETC_CONTAINERD?=/etc/containerd
$(FIRECRACKER_CONTAINERD_RUNTIME_DIR) $(ETC_CONTAINERD):
mkdir --mode 0700 --parents $@
DEFAULT_VMLINUX_NAME?=default-vmlinux.bin
$(DEFAULT_VMLINUX_NAME):
curl --silent --show-error --retry 3 --max-time 30 --output $@ \
"https://s3.amazonaws.com/spec.ccfc.min/img/quickstart_guide/$(host_arch)/kernels/vmlinux.bin"
echo "$(kernel_sha256sum) $@" | sha256sum -c -
chmod 0400 $@
DEFAULT_VMLINUX_INSTALLPATH=$(FIRECRACKER_CONTAINERD_RUNTIME_DIR)/$(DEFAULT_VMLINUX_NAME)
$(DEFAULT_VMLINUX_INSTALLPATH): $(DEFAULT_VMLINUX_NAME) $(FIRECRACKER_CONTAINERD_RUNTIME_DIR)
install -D -o root -g root -m400 $(DEFAULT_VMLINUX_NAME) $@
DEFAULT_ROOTFS_INSTALLPATH=$(FIRECRACKER_CONTAINERD_RUNTIME_DIR)/default-rootfs.img
$(DEFAULT_ROOTFS_INSTALLPATH): tools/image-builder/rootfs.img $(FIRECRACKER_CONTAINERD_RUNTIME_DIR)
install -D -o root -g root -m400 tools/image-builder/rootfs.img $@
DEFAULT_RUNC_JAILER_CONFIG_INSTALLPATH?=/etc/containerd/firecracker-runc-config.json
$(DEFAULT_RUNC_JAILER_CONFIG_INSTALLPATH): $(ETC_CONTAINERD) runtime/firecracker-runc-config.json.example
install -D -o root -g root -m400 runtime/firecracker-runc-config.json.example $@
ROOTFS_SLOW_BOOT_INSTALLPATH=$(FIRECRACKER_CONTAINERD_RUNTIME_DIR)/rootfs-slow-boot.img
$(ROOTFS_SLOW_BOOT_INSTALLPATH): tools/image-builder/rootfs-slow-boot.img $(FIRECRACKER_CONTAINERD_RUNTIME_DIR)
install -D -o root -g root -m400 $< $@
ROOTFS_SLOW_REBOOT_INSTALLPATH=$(FIRECRACKER_CONTAINERD_RUNTIME_DIR)/rootfs-slow-reboot.img
$(ROOTFS_SLOW_REBOOT_INSTALLPATH): tools/image-builder/rootfs-slow-reboot.img $(FIRECRACKER_CONTAINERD_RUNTIME_DIR)
install -D -o root -g root -m400 $< $@
ROOTFS_NO_AGENT_INSTALLPATH=$(FIRECRACKER_CONTAINERD_RUNTIME_DIR)/rootfs-no-agent.img
$(ROOTFS_NO_AGENT_INSTALLPATH): tools/image-builder/rootfs-no-agent.img $(FIRECRACKER_CONTAINERD_RUNTIME_DIR)
install -D -o root -g root -m400 $< $@
.PHONY: default-vmlinux
default-vmlinux: $(DEFAULT_VMLINUX_NAME)
.PHONY: install-default-vmlinux
install-default-vmlinux: $(DEFAULT_VMLINUX_INSTALLPATH)
.PHONY: install-default-rootfs
install-default-rootfs: $(DEFAULT_ROOTFS_INSTALLPATH)
.PHONY: install-default-runc-jailer-config
install-default-runc-jailer-config: $(DEFAULT_RUNC_JAILER_CONFIG_INSTALLPATH)
.PHONY: install-test-rootfs
install-test-rootfs: $(ROOTFS_SLOW_BOOT_INSTALLPATH) $(ROOTFS_SLOW_REBOOT_INSTALLPATH) $(ROOTFS_NO_AGENT_INSTALLPATH)
##########################
# CNI Network
##########################
CNI_BIN_ROOT?=/opt/cni/bin
$(CNI_BIN_ROOT):
mkdir --mode 0755 --parents $@
BRIDGE_BIN?=$(BINPATH)/bridge
$(BRIDGE_BIN):
GOBIN=$(dir $@) GO111MODULE=off go get -u github.com/containernetworking/plugins/plugins/main/bridge
PTP_BIN?=$(BINPATH)/ptp
$(PTP_BIN):
GOBIN=$(dir $@) GO111MODULE=off go get -u github.com/containernetworking/plugins/plugins/main/ptp
HOSTLOCAL_BIN?=$(BINPATH)/host-local
$(HOSTLOCAL_BIN):
GOBIN=$(dir $@) GO111MODULE=off go get -u github.com/containernetworking/plugins/plugins/ipam/host-local
FIREWALL_BIN?=$(BINPATH)/firewall
$(FIREWALL_BIN):
GOBIN=$(dir $@) GO111MODULE=off go get -u github.com/containernetworking/plugins/plugins/meta/firewall
TC_REDIRECT_TAP_BIN?=$(BINPATH)/tc-redirect-tap
$(TC_REDIRECT_TAP_BIN):
GOBIN=$(dir $@) go install github.com/awslabs/tc-redirect-tap/cmd/tc-redirect-tap
TEST_BRIDGED_TAP_BIN?=$(BINPATH)/test-bridged-tap
$(TEST_BRIDGED_TAP_BIN): $(shell find internal/cmd/test-bridged-tap -name *.go) $(GOMOD) $(GOSUM)
go build -o $@ $(CURDIR)/internal/cmd/test-bridged-tap
.PHONY: cni-bins
cni-bins: $(BRIDGE_BIN) $(PTP_BIN) $(HOSTLOCAL_BIN) $(FIREWALL_BIN) $(TC_REDIRECT_TAP_BIN)
.PHONY: test-cni-bins
test-cni-bins: $(TEST_BRIDGED_TAP_BIN)
.PHONY: install-cni-bins
install-cni-bins: cni-bins $(CNI_BIN_ROOT)
install -D -o root -g root -m755 -t $(CNI_BIN_ROOT) $(BRIDGE_BIN)
install -D -o root -g root -m755 -t $(CNI_BIN_ROOT) $(PTP_BIN)
install -D -o root -g root -m755 -t $(CNI_BIN_ROOT) $(HOSTLOCAL_BIN)
install -D -o root -g root -m755 -t $(CNI_BIN_ROOT) $(FIREWALL_BIN)
install -D -o root -g root -m755 -t $(CNI_BIN_ROOT) $(TC_REDIRECT_TAP_BIN)
.PHONY: install-test-cni-bins
install-test-cni-bins: test-cni-bins $(CNI_BIN_ROOT)
install -D -o root -g root -m755 -t $(CNI_BIN_ROOT) $(TEST_BRIDGED_TAP_BIN)
FCNET_CONFIG?=/etc/cni/conf.d/fcnet.conflist
$(FCNET_CONFIG):
mkdir -p $(dir $(FCNET_CONFIG))
install -o root -g root -m644 tools/demo/fcnet.conflist $(FCNET_CONFIG)
FCNET_BRIDGE_CONFIG?=/etc/network/interfaces.d/fc-br0
$(FCNET_BRIDGE_CONFIG):
mkdir -p $(dir $(FCNET_BRIDGE_CONFIG))
install -o root -g root -m644 tools/demo/fc-br0.interface $(FCNET_BRIDGE_CONFIG)
.PHONY: demo-network
demo-network: install-cni-bins $(FCNET_CONFIG)
##########################
# Firecracker submodule
##########################
.PHONY: firecracker
firecracker: $(FIRECRACKER_BIN)
.PHONY: install-firecracker
install-firecracker: firecracker
install -D -o root -g root -m755 -t $(INSTALLROOT)/bin $(FIRECRACKER_BIN)
$(FIRECRACKER_DIR)/Cargo.toml:
git submodule update --init --recursive $(FIRECRACKER_DIR)
$(FIRECRACKER_BIN): $(FIRECRACKER_DIR)/Cargo.toml
$(FIRECRACKER_DIR)/tools/devtool -y build --release && \
$(FIRECRACKER_DIR)/tools/devtool strip
.PHONY: firecracker-clean
firecracker-clean:
- $(FIRECRACKER_DIR)/tools/devtool distclean
- rm $(FIRECRACKER_BIN)
##########################
# RunC submodule
##########################
.PHONY: runc
runc: $(RUNC_BIN)
$(RUNC_DIR)/VERSION:
git submodule update --init --recursive $(RUNC_DIR)
tools/runc-builder-stamp: tools/docker/Dockerfile.runc-builder
docker build \
-t localhost/$(RUNC_BUILDER_NAME):$(DOCKER_IMAGE_TAG) \
-f tools/docker/Dockerfile.runc-builder \
tools/
touch $@
$(RUNC_BIN): $(RUNC_DIR)/VERSION tools/runc-builder-stamp
docker run --rm --user $(UID) \
--volume $(CURDIR)/$(RUNC_DIR):/gopath/src/github.com/opencontainers/runc \
--volume $(CURDIR)/deps:/target \
-e HOME=/tmp \
-e GOPATH=/gopath \
--workdir /gopath/src/github.com/opencontainers/runc \
localhost/$(RUNC_BUILDER_NAME):$(DOCKER_IMAGE_TAG) \
make static
.PHONY: install-runc
install-runc: $(RUNC_BIN)
install -D -o root -g root -m755 -t $(INSTALLROOT)/bin $(RUNC_BIN)