Skip to content

Commit ad9ec90

Browse files
committed
ci: generate ext4 image after downloading artifacts
This avoids the need to store and download the image from S3. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 83aec7b commit ad9ec90

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

resources/rebuild.sh

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@ function install_dependencies {
2020
apt install -y bc flex bison gcc make libelf-dev libssl-dev squashfs-tools busybox-static tree cpio curl patch docker.io
2121
}
2222

23-
function dir2ext4img {
24-
# ext4
25-
# https://unix.stackexchange.com/questions/503211/how-can-an-image-file-be-created-for-a-directory
26-
local DIR=$1
27-
local IMG=$2
28-
# Default size for the resulting rootfs image is 300M
29-
local SIZE=${3:-300M}
30-
local TMP_MNT=$(mktemp -d)
31-
truncate -s "$SIZE" "$IMG"
32-
mkfs.ext4 -F "$IMG"
33-
mount "$IMG" "$TMP_MNT"
34-
tar c -C $DIR . |tar x -C "$TMP_MNT"
35-
# cleanup
36-
# Use the -l flag for lazy unmounting since sometimes umount fails
37-
# with "device busy" and simply calling `sync` doesn't help
38-
umount -l "$TMP_MNT"
39-
rmdir $TMP_MNT
40-
}
41-
4223
function prepare_docker {
4324
nohup /usr/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 &
4425

@@ -102,8 +83,6 @@ EOF
10283
rootfs_img="$OUTPUT_DIR/$ROOTFS_NAME.squashfs"
10384
mv $rootfs/root/manifest $OUTPUT_DIR/$ROOTFS_NAME.manifest
10485
mksquashfs $rootfs $rootfs_img -all-root -noappend
105-
rootfs_ext4=$OUTPUT_DIR/$ROOTFS_NAME.ext4
106-
dir2ext4img $rootfs $rootfs_ext4
10786
rm -rf $rootfs
10887
for bin in fast_page_fault_helper fillmem init readmem; do
10988
rm $PWD/overlay/usr/local/bin/$bin
@@ -235,7 +214,7 @@ function build_al_kernels {
235214
local KERNEL_VERSION="all"
236215
elif [[ $# -ne 1 ]]; then
237216
die "Too many arguments in '$(basename $0) kernels' command. Please use \`$0 help\` for help."
238-
else
217+
else
239218
KERNEL_VERSION=$1
240219
if [[ "$KERNEL_VERSION" != @(5.10|5.10-no-acpi|6.1) ]]; then
241220
die "Unsupported kernel version: '$KERNEL_VERSION'. Please use \`$0 help\` for help."
@@ -259,33 +238,33 @@ function build_al_kernels {
259238

260239
# Undo kernel patches on top of AL configuration
261240
git restore $PWD/guest_configs
262-
rm -rf $PWD/guest_configs/*.orig
241+
rm -rf $PWD/guest_configs/*.orig
263242
}
264243

265244
function print_help {
266245
cat <<EOF
267246
Firecracker CI artifacts build script
268247
269248
Usage: $(basename $0) [<command>] [<command args>]
270-
249+
271250
Available commands:
272-
251+
273252
all (default)
274253
Build CI rootfs and default guest kernels using configurations from
275254
resources/guest_configs.
276255
This will patch the guest configurations with all the patches under
277256
resources/guest_configs/patches.
278257
This is the default command, if no command is chosen.
279-
258+
280259
rootfs
281260
Builds only the CI rootfs.
282-
261+
283262
kernels [version]
284263
Builds our the currently supported CI kernels.
285-
264+
286265
version: Optionally choose a kernel version to build. Supported
287266
versions are: 5.10, 5.10-no-acpi or 6.1.
288-
267+
289268
help
290269
Displays the help message and exits.
291270
EOF
@@ -310,7 +289,7 @@ function main {
310289
fi
311290

312291
set -x
313-
292+
314293
install_dependencies
315294

316295
# Create the directory in which we will store the kernels and rootfs

tools/devtool

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ cmd_help() {
417417
echo " build_ci_artifacts [all|rootfs|kernels]"
418418
echo " Builds the rootfs and guest kernel artifacts we use for our CI."
419419
echo " Run './tools/devtool build_ci_artifacts help' for more details about the available commands."
420-
echo ""
420+
echo ""
421421

422422
cat <<EOF
423423
test_debug [-- [<pytest args>]]
@@ -567,9 +567,7 @@ ensure_ci_artifacts() {
567567
if [ ! -d "$ARTIFACTS" ]; then
568568
mkdir -pv $ARTIFACTS
569569
aws s3 sync --no-sign-request "$S3_URL" "$ARTIFACTS"
570-
# fix permissions
571-
find "$ARTIFACTS" -type f -name "*.id_rsa" |xargs chmod -c 400
572-
find "$ARTIFACTS/firecracker" -type f |xargs chmod -c 755
570+
cmd_sh "./tools/setup-ci-artifacts.sh"
573571
fi
574572
}
575573

tools/setup-ci-artifacts.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# fail if we encounter an error, uninitialized variable or a pipe breaks
6+
set -eu -o pipefail
7+
8+
TOOLS_DIR=$(dirname $0)
9+
source "$TOOLS_DIR/functions"
10+
11+
say "Setup CI artifacts"
12+
cd build/img/$(uname -m)
13+
14+
say "Fix executable permissions"
15+
find "firecracker" -type f |xargs chmod -c 755
16+
17+
say "Fix RSA key permissions"
18+
find . -type f -name "*.id_rsa" |xargs chmod -c 400
19+
20+
for SQUASHFS in *.squashfs; do
21+
EXT4=$(basename $SQUASHFS .squashfs).ext4
22+
23+
# Create rw ext4 image from ro squashfs
24+
[ -f $EXT4 ] && continue
25+
say "Converting $SQUASHFS to $EXT4"
26+
truncate -s 400M $EXT4
27+
unsquashfs $SQUASHFS
28+
mkfs.ext4 -F $EXT4 -d squashfs-root
29+
rm -rf squashfs-root
30+
done

0 commit comments

Comments
 (0)