-
Notifications
You must be signed in to change notification settings - Fork 126
/
Makefile
151 lines (118 loc) · 5.72 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
# 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_DIR=build/firecracker
arch=$(shell uname -m)
FIRECRACKER_TARGET?=$(arch)-unknown-linux-musl
FC_TEST_DATA_PATH?=testdata
FC_TEST_BIN_PATH:=$(FC_TEST_DATA_PATH)/bin
FIRECRACKER_BIN=$(FC_TEST_DATA_PATH)/firecracker-main
JAILER_BIN=$(FC_TEST_DATA_PATH)/jailer-main
UID = $(shell id -u)
GID = $(shell id -g)
# Version has to be in format of vx.x.x
firecracker_version=v1.4.1
# The below files are needed and can be downloaded from the internet
release_url=https://github.com/firecracker-microvm/firecracker/releases/download/$(firecracker_version)/firecracker-$(firecracker_version)-$(arch).tgz
testdata_objects = \
$(FC_TEST_DATA_PATH)/firecracker \
$(FC_TEST_BIN_PATH)/host-local \
$(FC_TEST_DATA_PATH)/jailer \
$(FC_TEST_DATA_PATH)/ltag \
$(FC_TEST_BIN_PATH)/ptp \
$(FC_TEST_DATA_PATH)/root-drive.img \
$(FC_TEST_DATA_PATH)/root-drive-with-ssh.img \
$(FC_TEST_DATA_PATH)/root-drive-ssh-key \
$(FC_TEST_BIN_PATH)/static \
$(FC_TEST_BIN_PATH)/tc-redirect-tap \
$(FC_TEST_DATA_PATH)/vmlinux
testdata_dir = testdata/firecracker.tgz testdata/firecracker_spec-$(firecracker_version).yaml testdata/LICENSE testdata/NOTICE testdata/THIRD-PARTY
# --location is needed to follow redirects
curl = curl --location
GO_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1,2)
ifeq ($(GO_VERSION), $(filter $(GO_VERSION),1.14 1.15))
define install_go
cd .hack; GO111MODULE=on GOBIN=$(abspath $(FC_TEST_BIN_PATH)) go get $(1)@$(2)
cd .hack; GO111MODULE=on GOBIN=$(abspath $(FC_TEST_BIN_PATH)) go install $(1)
endef
else
define install_go
GOBIN=$(abspath $(FC_TEST_BIN_PATH)) go install $(1)@$(2)
endef
endif
all: build
test: all-tests
unit-tests: $(testdata_objects)
DISABLE_ROOT_TESTS=$(DISABLE_ROOT_TESTS) go test -short ./... $(EXTRAGOARGS)
all-tests: $(testdata_objects)
DISABLE_ROOT_TESTS=$(DISABLE_ROOT_TESTS) go test ./... $(EXTRAGOARGS)
generate build clean::
go $@ $(EXTRAGOARGS)
clean::
rm -fr build/
distclean: clean
rm -rf $(testdata_objects)
rm -f $(FC_TEST_DATA_PATH)/fc.stamp
rm -rfv $(testdata_dir)
docker volume rm -f $(CARGO_CACHE_VOLUME_NAME)
deps: $(testdata_objects)
$(FC_TEST_DATA_PATH)/vmlinux:
$(curl) -o $@ https://s3.amazonaws.com/spec.ccfc.min/img/quickstart_guide/$(arch)/kernels/vmlinux.bin
$(FC_TEST_DATA_PATH)/firecracker $(FC_TEST_DATA_PATH)/jailer: $(FC_TEST_DATA_PATH)/fc.stamp
# Download the pinned release version of firecracker and jailer version from github
$(FC_TEST_DATA_PATH)/fc.stamp:
$(curl) ${release_url} | tar -xvzf - -C $(FC_TEST_DATA_PATH)
mv $(FC_TEST_DATA_PATH)/release-$(firecracker_version)-$(arch)/firecracker-$(firecracker_version)-$(arch) $(FC_TEST_DATA_PATH)/firecracker
mv $(FC_TEST_DATA_PATH)/release-$(firecracker_version)-$(arch)/jailer-$(firecracker_version)-$(arch) $(FC_TEST_DATA_PATH)/jailer
rm -rf $(FC_TEST_DATA_PATH)/release-$(firecracker_version)-$(arch)
touch $@
$(FC_TEST_DATA_PATH)/root-drive.img:
$(curl) -o $@ https://s3.amazonaws.com/spec.ccfc.min/img/hello/fsfiles/hello-rootfs.ext4
# Download pre-built rootfs image and its ssh key from S3
# TODO: Change the pre-built rootfs to ubuntu 22.04 once firecracker team has it in the public S3 bucket
# Currently the S3 bucket only has ubuntu 18.04 image
$(FC_TEST_DATA_PATH)/root-drive-ssh-key $(FC_TEST_DATA_PATH)/root-drive-with-ssh.img:
$(curl) -o $(FC_TEST_DATA_PATH)/root-drive-with-ssh.img https://s3.amazonaws.com/spec.ccfc.min/ci-artifacts/disks/$(arch)/ubuntu-18.04.ext4
$(curl) -o $(FC_TEST_DATA_PATH)/root-drive-ssh-key https://s3.amazonaws.com/spec.ccfc.min/ci-artifacts/disks/$(arch)/ubuntu-18.04.id_rsa
$(FC_TEST_BIN_PATH)/ptp:
$(call install_go,github.com/containernetworking/plugins/plugins/main/ptp,v1.1.1)
$(FC_TEST_BIN_PATH)/host-local:
$(call install_go,github.com/containernetworking/plugins/plugins/ipam/host-local,v1.1.1)
$(FC_TEST_BIN_PATH)/static:
$(call install_go,github.com/containernetworking/plugins/plugins/ipam/static,v1.1.1)
$(FC_TEST_BIN_PATH)/tc-redirect-tap:
$(call install_go,github.com/awslabs/tc-redirect-tap/cmd/tc-redirect-tap,v0.0.0-20240408144842-496fddc89db6)
$(FC_TEST_DATA_PATH)/ltag:
$(call install_go,github.com/kunalkushwaha/ltag,v0.2.3)
# test-images builds firecracker and jailer from main branch of firecracker
# to test against HEAD of firecracker
.PHONY: test-images
test-images: $(FIRECRACKER_BIN) $(JAILER_BIN)
$(FIRECRACKER_DIR):
- git clone https://github.com/firecracker-microvm/firecracker.git $(FIRECRACKER_DIR)
$(FIRECRACKER_BIN) $(JAILER_BIN): $(FIRECRACKER_DIR)
$(FIRECRACKER_DIR)/tools/devtool -y build --release
cp $(FIRECRACKER_DIR)/build/cargo_target/$(FIRECRACKER_TARGET)/release/firecracker $(FIRECRACKER_BIN)
cp $(FIRECRACKER_DIR)/build/cargo_target/$(FIRECRACKER_TARGET)/release/jailer $(JAILER_BIN)
.PHONY: firecracker-clean
firecracker-clean:
- $(FIRECRACKER_DIR)/tools/devtool distclean
- rm $(FIRECRACKER_BIN) $(JAILER_BIN)
lint: deps
gofmt -s -l .
$(FC_TEST_DATA_PATH)/bin/ltag -check -v -t .headers
.PHONY: all generate clean distclean build test unit-tests all-tests check-kvm