Skip to content

Commit 7be3b30

Browse files
committed
chore: allow building CI rootfs and kernels separately
Script `resources/rebuild.sh` is used mainly to help us re-build CI artifacts. Sometimes, for debugging we would like to be able to build kernels or the rootfs locally. Also, we would like to be able to build each component individually, e.g. only the root filesystem or only guest kernel 6.1. Make the script a bit more clever, adding options for building only rootfs or only kernels (all of them or a single one). Leave the default behaviour intact so we don't break any of its current users. Signed-off-by: Babis Chalios <[email protected]>
1 parent 588e77a commit 7be3b30

File tree

1 file changed

+107
-23
lines changed

1 file changed

+107
-23
lines changed

resources/rebuild.sh

Lines changed: 107 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
# fail if we encounter an error, uninitialized variable or a pipe breaks
66
set -eu -o pipefail
77

8-
set -x
98
PS4='+\t '
109

1110
cd $(dirname $0)
1211
ARCH=$(uname -m)
1312
OUTPUT_DIR=$PWD/$ARCH
1413

14+
GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
15+
source "$GIT_ROOT_DIR/tools/functions"
16+
1517
# Make sure we have all the needed tools
1618
function install_dependencies {
1719
sudo apt update
@@ -50,7 +52,7 @@ function build_rootfs {
5052
local flavour=${2}
5153
local FROM_CTR=public.ecr.aws/ubuntu/ubuntu:$flavour
5254
local rootfs="tmp_rootfs"
53-
mkdir -pv "$rootfs" "$OUTPUT_DIR"
55+
mkdir -pv "$rootfs"
5456

5557
cp -rvf overlay/* $rootfs
5658

@@ -199,31 +201,113 @@ function build_al_kernel {
199201
popd &>/dev/null
200202
}
201203

202-
#### main ####
204+
function prepare_and_build_rootfs {
205+
BIN=overlay/usr/local/bin
206+
compile_and_install $BIN/init.c $BIN/init
207+
compile_and_install $BIN/fillmem.c $BIN/fillmem
208+
compile_and_install $BIN/fast_page_fault_helper.c $BIN/fast_page_fault_helper
209+
compile_and_install $BIN/readmem.c $BIN/readmem
210+
if [ $ARCH == "aarch64" ]; then
211+
compile_and_install $BIN/devmemread.c $BIN/devmemread
212+
fi
213+
214+
build_rootfs ubuntu-22.04 jammy
215+
build_initramfs
216+
}
217+
218+
function build_al_kernels {
219+
if [[ $# = 0 ]]; then
220+
local KERNEL_VERSION="all"
221+
elif [[ $# -ne 1 ]]; then
222+
die "Too many arguments in '$(basename $0) kernels' command. Please use \`$0 help\` for help."
223+
else
224+
KERNEL_VERSION=$1
225+
if [[ "$KERNEL_VERSION" != @(5.10|5.10-no-acpi|6.1) ]]; then
226+
die "Unsupported kernel version: '$KERNEL_VERSION'. Please use \`$0 help\` for help."
227+
fi
228+
fi
229+
230+
clone_amazon_linux_repo
231+
232+
# Apply kernel patches on top of AL configuration
233+
apply_kernel_patches_for_ci
234+
235+
if [[ "$KERNEL_VERSION" == @(all|5.10) ]]; then
236+
build_al_kernel $PWD/guest_configs/microvm-kernel-ci-$ARCH-5.10.config
237+
fi
238+
if [[ $ARCH == "x86_64" && "$KERNEL_VERSION" == @(all|5.10-no-acpi) ]]; then
239+
build_al_kernel $PWD/guest_configs/microvm-kernel-ci-$ARCH-5.10-no-acpi.config
240+
fi
241+
if [[ "$KERNEL_VERSION" == @(all|6.1) ]]; then
242+
build_al_kernel $PWD/guest_configs/microvm-kernel-ci-$ARCH-6.1.config 5.10
243+
fi
244+
}
245+
246+
function print_help {
247+
cat <<EOF
248+
Firecracker CI artifacts build script
249+
250+
Usage: $(basename $0) [<command>] [<command args>]
251+
252+
Available commands:
253+
254+
all (default)
255+
Build CI rootfs and default guest kernels using configurations from
256+
resources/guest_configs.
257+
This will patch the guest configurations with all the patches under
258+
resources/guest_configs/patches.
259+
This is the default command, if no command is chosen.
260+
261+
rootfs
262+
Builds only the CI rootfs.
263+
264+
kernels [version]
265+
Builds our the currently supported CI kernels.
266+
267+
version: Optionally choose a kernel version to build. Supported
268+
versions are: 5.10, 5.10-no-acpi or 6.1.
269+
270+
help
271+
Displays the help message and exits.
272+
EOF
273+
}
203274

204-
install_dependencies
275+
function main {
276+
if [[ $# = 0 ]]; then
277+
local MODE="all"
278+
else
279+
case $1 in
280+
all|rootfs|kernels)
281+
local MODE=$1
282+
shift
283+
;;
284+
help)
285+
print_help
286+
exit 0
287+
;;
288+
*)
289+
die "Unknown command: '$1'. Please use \`$0 help\` for help."
290+
esac
291+
fi
205292

206-
BIN=overlay/usr/local/bin
207-
compile_and_install $BIN/init.c $BIN/init
208-
compile_and_install $BIN/fillmem.c $BIN/fillmem
209-
compile_and_install $BIN/fast_page_fault_helper.c $BIN/fast_page_fault_helper
210-
compile_and_install $BIN/readmem.c $BIN/readmem
211-
if [ $ARCH == "aarch64" ]; then
212-
compile_and_install $BIN/devmemread.c $BIN/devmemread
213-
fi
293+
set -x
294+
295+
install_dependencies
214296

215-
build_rootfs ubuntu-22.04 jammy
216-
build_initramfs
297+
# Create the directory in which we will store the kernels and rootfs
298+
mkdir -pv $OUTPUT_DIR
217299

218-
clone_amazon_linux_repo
300+
if [[ "$MODE" =~ (all|rootfs) ]]; then
301+
say "Building rootfs"
302+
prepare_and_build_rootfs
303+
fi
219304

220-
# Apply kernel patches on top of AL configuration
221-
apply_kernel_patches_for_ci
305+
if [[ "$MODE" =~ (all|kernels) ]]; then
306+
say "Building CI kernels"
307+
build_al_kernels "$@"
308+
fi
222309

223-
build_al_kernel $PWD/guest_configs/microvm-kernel-ci-$ARCH-5.10.config
224-
if [ $ARCH == "x86_64" ]; then
225-
build_al_kernel $PWD/guest_configs/microvm-kernel-ci-$ARCH-5.10-no-acpi.config
226-
fi
227-
build_al_kernel $PWD/guest_configs/microvm-kernel-ci-$ARCH-6.1.config
310+
tree -h $OUTPUT_DIR
311+
}
228312

229-
tree -h $OUTPUT_DIR
313+
main "$@"

0 commit comments

Comments
 (0)