|
5 | 5 | # fail if we encounter an error, uninitialized variable or a pipe breaks
|
6 | 6 | set -eu -o pipefail
|
7 | 7 |
|
8 |
| -set -x |
9 | 8 | PS4='+\t '
|
10 | 9 |
|
11 | 10 | cd $(dirname $0)
|
12 | 11 | ARCH=$(uname -m)
|
13 | 12 | OUTPUT_DIR=$PWD/$ARCH
|
14 | 13 |
|
| 14 | +GIT_ROOT_DIR=$(git rev-parse --show-toplevel) |
| 15 | +source "$GIT_ROOT_DIR/tools/functions" |
| 16 | + |
15 | 17 | # Make sure we have all the needed tools
|
16 | 18 | function install_dependencies {
|
17 | 19 | sudo apt update
|
@@ -50,7 +52,7 @@ function build_rootfs {
|
50 | 52 | local flavour=${2}
|
51 | 53 | local FROM_CTR=public.ecr.aws/ubuntu/ubuntu:$flavour
|
52 | 54 | local rootfs="tmp_rootfs"
|
53 |
| - mkdir -pv "$rootfs" "$OUTPUT_DIR" |
| 55 | + mkdir -pv "$rootfs" |
54 | 56 |
|
55 | 57 | cp -rvf overlay/* $rootfs
|
56 | 58 |
|
@@ -199,31 +201,113 @@ function build_al_kernel {
|
199 | 201 | popd &>/dev/null
|
200 | 202 | }
|
201 | 203 |
|
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 | +} |
203 | 274 |
|
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 |
205 | 292 |
|
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 |
214 | 296 |
|
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 |
217 | 299 |
|
218 |
| -clone_amazon_linux_repo |
| 300 | + if [[ "$MODE" =~ (all|rootfs) ]]; then |
| 301 | + say "Building rootfs" |
| 302 | + prepare_and_build_rootfs |
| 303 | + fi |
219 | 304 |
|
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 |
222 | 309 |
|
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 | +} |
228 | 312 |
|
229 |
| -tree -h $OUTPUT_DIR |
| 313 | +main "$@" |
0 commit comments