-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
92 lines (75 loc) · 2.85 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
### Makefile --- build images and things...
# Copyright 2019 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.
IMAGE_SIZE?=1G
KERNEL?=/usr/local/bin/vmlinux
IMAGE=$(CURDIR)/image
FIRECTL_DIR=_submodules/firectl
FIRECRACKER_DIR=_submodules/firecracker
CARGO_SYSTEM=$(shell uname -m)-unknown-linux-musl
CARGO_CACHE=.cargo_cache
FIRECRACKER_CARGO=docker run --rm -v $(CURDIR)/$(FIRECRACKER_DIR):/src \
-v $(CURDIR)/$(CARGO_CACHE):/usr/local/cargo/registry \
--workdir /src --user=$(shell id -u) \
localhost/firecracker-build:latest cargo
$(FIRECTL_DIR)/Makefile:
git submodule update --init $(FIRECTL_DIR)
firectl: $(FIRECTL_DIR)/Makefile
$(MAKE) -C $(FIRECTL_DIR) build-in-docker
cp $(FIRECTL_DIR)/firectl .
$(FIRECRACKER_DIR)/Cargo.toml:
git submodule update --init $(FIRECRACKER_DIR)
firecracker: $(FIRECRACKER_DIR)/Cargo.toml
mkdir -p $(CARGO_CACHE)
cd tools && docker build -t localhost/firecracker-build:latest -f Dockerfile.firecracker .
$(FIRECRACKER_CARGO) build --release
cp $(FIRECRACKER_DIR)/target/$(CARGO_SYSTEM)/release/firecracker .
$(IMAGE):
truncate -s $(IMAGE_SIZE) $(IMAGE)
.image: $(IMAGE)
docker run --cap-add=sys_admin \
--cap-add=sys_chroot \
--security-opt=apparmor=unconfined \
--rm \
-v $(IMAGE):/img \
debian:buster sh -c " id && apt-get update && apt-get --no-install-recommends -y install debootstrap && debootstrap --include=tcpdump buster /mnt && sed -i 's|root:\*:|root::|' /mnt/etc/shadow && mkfs.ext4 -d /mnt /img"
touch .image
install: .image
vmlinux:
cp $(KERNEL) vmlinux
container: vmlinux firectl firecracker
docker build -t fc .
run:
docker run -v $(IMAGE):/root.img \
--device /dev/kvm:/dev/kvm:rw \
--device /dev/net/tun:/dev/net/tun:rw \
--cap-add=net_admin \
-e CPU_COUNT \
-e MEM_MB \
-e CPU_TEMPLATE \
$(EXTRA) \
-it --rm fc
clean:
-rm -f image .image vmlinux firectl firecracker
-test ! -d $(FIRECTL_DIR) || $(MAKE) -C $(FIRECTL_DIR) clean
-test ! -d $(FIRECRACKER_DIR) || $(FIRECRACKER_CARGO) clean
distclean: clean
rm -rf $(CARGO_CACHE)
-docker rmi localhost/firecracker-build:latest
help:
@echo Useful makefile targets:
@echo
@echo 'install - Construct a root filesystem for use with a microvm'
@echo 'container - Construct a container image for use with Docker'
@echo 'run - Run a VM container with the images created by "install" and "container"'
.PHONY: install run clean container distclean help