forked from firecracker-microvm/firecracker-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
106 lines (85 loc) · 3.5 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
# 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.
# Set this to pass additional commandline flags to the go compiler, e.g. "make test EXTRAGOARGS=-v"
CARGO_CACHE_VOLUME_NAME?=firecracker-go-sdk--cargocache
DISABLE_ROOT_TESTS?=1
DOCKER_IMAGE_TAG?=latest
EXTRAGOARGS:=
FIRECRACKER_BUILDER_NAME=firecracker-builder
FIRECRACKER_BIN=testdata/firecracker-master
JAILER_BIN=testdata/jailer-master
FIRECRACKER_TARGET?=x86_64-unknown-linux-musl
UID = $(shell id -u)
GID = $(shell id -g)
# The below files are needed and can be downloaded from the internet
testdata_objects = testdata/vmlinux testdata/root-drive.img testdata/firecracker testdata/jailer
firecracker_version = v0.22.0
# --location is needed to follow redirects on github.com
curl = curl --location
all: build
test: all-tests
unit-tests: $(testdata_objects) check-kvm
DISABLE_ROOT_TESTS=$(DISABLE_ROOT_TESTS) go test -short ./... $(EXTRAGOARGS)
all-tests: $(testdata_objects) check-kvm
DISABLE_ROOT_TESTS=$(DISABLE_ROOT_TESTS) go test ./... $(EXTRAGOARGS)
check-kvm:
@test -w /dev/kvm || \
(echo "In order to run firecracker, $(shell whoami) must have write permission to /dev/kvm"; false)
generate build clean::
go $@ $(EXTRAGOARGS)
clean::
rm -fr build/
distclean: clean
rm -rf $(testdata_objects)
docker volume rm -f $(CARGO_CACHE_VOLUME_NAME)
testdata/vmlinux:
$(curl) -o $@ https://s3.amazonaws.com/spec.ccfc.min/img/hello/kernel/hello-vmlinux.bin
testdata/firecracker:
$(curl) -o $@ https://github.com/firecracker-microvm/firecracker/releases/download/$(firecracker_version)/firecracker-$(firecracker_version)-x86_64
chmod +x $@
testdata/jailer:
$(curl) -o $@ https://github.com/firecracker-microvm/firecracker/releases/download/$(firecracker_version)/jailer-$(firecracker_version)-x86_64
chmod +x $@
testdata/root-drive.img:
$(curl) -o $@ https://s3.amazonaws.com/spec.ccfc.min/img/hello/fsfiles/hello-rootfs.ext4
tools/firecracker-builder-stamp: tools/docker/Dockerfile
docker build \
-t localhost/$(FIRECRACKER_BUILDER_NAME):$(DOCKER_IMAGE_TAG) \
-f tools/docker/Dockerfile \
tools/docker
touch $@
.PHONY: test-images
test-images: $(FIRECRACKER_BIN) $(JAILER_BIN)
$(FIRECRACKER_BIN) $(JAILER_BIN): tools/firecracker-builder-stamp
mkdir -p build
docker run --rm -it \
--user $(UID):$(GID) \
--volume $(CURDIR)/build:/artifacts \
--volume $(CARGO_CACHE_VOLUME_NAME):/usr/local/cargo/registry \
-e HOME=/tmp \
--workdir=/firecracker \
localhost/$(FIRECRACKER_BUILDER_NAME):$(DOCKER_IMAGE_TAG) \
cargo build --release \
--target-dir=/artifacts --target $(FIRECRACKER_TARGET) \
-p firecracker -p jailer
cp build/$(FIRECRACKER_TARGET)/release/firecracker $(FIRECRACKER_BIN)
cp build/$(FIRECRACKER_TARGET)/release/jailer $(JAILER_BIN)
.PHONY: firecracker-clean
firecracker-clean:
- docker run --rm -it \
--user $(UID):$(GID) \
--workdir /firecracker\
localhost/$(FIRECRACKER_BUILDER_NAME):$(DOCKER_IMAGE_TAG) \
cargo clean
- rm $(FIRECRACKER_BIN) $(JAILER_BIN)
.PHONY: all generate clean distclean build test unit-tests all-tests check-kvm