Skip to content

Commit aed5e9d

Browse files
authored
use erofs for headful image (#39)
* use erofs for headful image syncing up with the approach used in the headless image * debian 12 notes * tweak stat script
1 parent 5d05b0c commit aed5e9d

File tree

7 files changed

+86
-52
lines changed

7 files changed

+86
-52
lines changed

images/chromium-headful/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
bin/
22
recording/
33
.tmp/
4+
.rootfs/
5+
initrd

images/chromium-headful/Kraftfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ spec: v0.6
33
runtime: index.unikraft.io/official/base-compat:latest
44

55
labels:
6-
cloud.unikraft.v1.instances/scale_to_zero.policy: "on"
6+
cloud.unikraft.v1.instances/scale_to_zero.policy: "idle"
77
cloud.unikraft.v1.instances/scale_to_zero.stateful: "true"
8-
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms: 4000
8+
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms: 5000
99

10-
rootfs: ./Dockerfile
10+
rootfs: ./initrd
1111

1212
cmd: ["/wrapper.sh"]
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
#!/usr/bin/env bash
22

33
source common.sh
4+
source ../../shared/erofs-utils.sh
5+
6+
# Ensure the mkfs.erofs tool is available
7+
if ! check_mkfs_erofs; then
8+
echo "mkfs.erofs is not installed. Installing erofs-utils..."
9+
install_erofs_utils
10+
fi
11+
412
set -euo pipefail
513

14+
# Build the root file system
615
source ../../shared/start-buildkit.sh
7-
16+
rm -rf ./.rootfs || true
817
# Build the API binary
918
source ../../shared/build-server.sh "$(pwd)/bin"
19+
app_name=chromium-headful-build
20+
docker build --platform linux/amd64 -t "$IMAGE" .
21+
docker rm cnt-"$app_name" || true
22+
docker create --platform linux/amd64 --name cnt-"$app_name" "$IMAGE" /bin/sh
23+
docker cp cnt-"$app_name":/ ./.rootfs
24+
rm -f initrd || true
25+
sudo mkfs.erofs --all-root -d2 -E noinline_data -b 4096 initrd ./.rootfs
1026

27+
# Package the unikernel (and the new initrd) to KraftCloud
1128
kraft pkg \
1229
--name $UKC_INDEX/$IMAGE \
13-
--plat kraftcloud --arch x86_64 \
30+
--plat kraftcloud \
31+
--arch x86_64 \
1432
--strategy overwrite \
1533
--push \
1634
.

images/chromium-headful/run-unikernel.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ trap 'rm -rf "$FLAGS_DIR"' EXIT
3939
deploy_args=(
4040
-M 8192
4141
-p 9222:9222/tls
42-
-p 8080:8080/tls
4342
-e DISPLAY_NUM=1
4443
-e HEIGHT=768
4544
-e WIDTH=1024

images/chromium-headless/build-unikernel.sh

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,10 @@
11
#!/usr/bin/env bash
22

33
source common.sh
4+
source ../../shared/erofs-utils.sh
45

5-
# Function to check if mkfs.erofs is available
6-
check_mkfs_erofs() {
7-
if command -v mkfs.erofs &>/dev/null; then
8-
echo "mkfs.erofs is already installed."
9-
return 0
10-
else
11-
echo "mkfs.erofs is not installed."
12-
return 1
13-
fi
14-
}
15-
16-
# Function to install erofs-utils package
17-
install_erofs_utils() {
18-
if command -v apt-get &>/dev/null; then
19-
echo "Detected Ubuntu/Debian-based system. Installing erofs-utils..."
20-
sudo apt update
21-
sudo apt install -y erofs-utils
22-
elif command -v dnf &>/dev/null; then
23-
echo "Detected Fedora-based system. Installing erofs-utils..."
24-
sudo dnf install -y erofs-utils
25-
elif command -v yum &>/dev/null; then
26-
echo "Detected CentOS/RHEL-based system. Installing erofs-utils..."
27-
sudo yum install -y erofs-utils
28-
elif [[ "$OSTYPE" == "darwin"* ]]; then
29-
if command -v brew &>/dev/null; then
30-
echo "Detected macOS. Installing erofs-utils..."
31-
brew install erofs-utils
32-
else
33-
echo "Homebrew (brew) not found. Please install Homebrew first."
34-
exit 1
35-
fi
36-
else
37-
echo "Unsupported operating system or package manager. Please install erofs-utils manually."
38-
exit 1
39-
fi
40-
}
41-
42-
check_mkfs_erofs
43-
if [ $? -ne 0 ]; then
6+
# Ensure the mkfs.erofs tool is present
7+
if ! check_mkfs_erofs; then
448
echo "mkfs.erofs is not installed. Installing erofs-utils..."
459
install_erofs_utils
4610
fi
@@ -50,11 +14,9 @@ set -euo pipefail
5014
cd image/
5115

5216
# Build the root file system
17+
source ../../shared/start-buildkit.sh
5318
rm -rf ./.rootfs || true
54-
55-
# Load configuration
56-
app_name=chromium-headless-test
57-
19+
app_name=chromium-headless-build
5820
docker build --platform linux/amd64 -t "$IMAGE" .
5921
docker rm cnt-"$app_name" || true
6022
docker create --platform linux/amd64 --name cnt-"$app_name" "$IMAGE" /bin/sh

shared/erofs-utils.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
# erofs-utils.sh
3+
# ----------------
4+
# Shared utility functions for verifying that mkfs.erofs (provided by the
5+
# erofs-utils package) is available on the host and installing it when it is
6+
# missing. This script is meant to be sourced by other build scripts.
7+
8+
set -e -o pipefail
9+
10+
# Returns 0 if mkfs.erofs is on the PATH, 1 otherwise.
11+
check_mkfs_erofs() {
12+
if command -v mkfs.erofs &>/dev/null; then
13+
return 0
14+
else
15+
return 1
16+
fi
17+
}
18+
19+
# Installs the erofs-utils package using the host's package manager.
20+
install_erofs_utils() {
21+
if command -v apt-get &>/dev/null; then
22+
echo "Detected Debian/Ubuntu system. Installing erofs-utils …"
23+
sudo apt update
24+
sudo apt install -y erofs-utils
25+
elif command -v dnf &>/dev/null; then
26+
echo "Detected Fedora system. Installing erofs-utils …"
27+
sudo dnf install -y erofs-utils
28+
elif command -v yum &>/dev/null; then
29+
echo "Detected CentOS/RHEL system. Installing erofs-utils …"
30+
sudo yum install -y erofs-utils
31+
elif [[ "$OSTYPE" == "darwin"* ]]; then
32+
if command -v brew &>/dev/null; then
33+
echo "Detected macOS system. Installing erofs-utils via Homebrew …"
34+
brew install erofs-utils
35+
else
36+
echo "Homebrew is required but not found. Please install Homebrew first."
37+
exit 1
38+
fi
39+
else
40+
echo "Unsupported operating system or package manager; please install erofs-utils manually."
41+
exit 1
42+
fi
43+
}
44+
45+
# on debian 12 you have to grab mkfs.erofs from sid:
46+
# echo "deb http://deb.debian.org/debian unstable main" \
47+
# | sudo tee /etc/apt/sources.list.d/unstable.list
48+
# cat <<'EOF' | sudo tee /etc/apt/preferences.d/90-unstable
49+
# Package: *
50+
# Pin: release a=unstable
51+
# Pin-Priority: 90
52+
# EOF
53+
# sudo apt update
54+
# sudo apt -t unstable install erofs-utils

shared/uk-check-stats.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ fi
2323
# get instance stats in a loop until ctrl-c
2424
trap 'echo "Stopping stats collection..."; exit 0' INT
2525

26+
echo -e "RSS\tCPU Time\tTX Bytes"
2627
while true; do
2728
metrics=$(curl -s -H "Authorization: Bearer $UKC_TOKEN" "$UKC_METRO/instances/$instance_id/metrics")
2829
rss=$(echo "$metrics" | grep 'instance_rss_bytes{instance_uuid=' | cut -d' ' -f2)
2930
cpu_time=$(echo "$metrics" | grep 'instance_cpu_time_s{instance_uuid=' | cut -d' ' -f2)
3031
tx_bytes=$(echo "$metrics" | grep 'instance_tx_bytes{instance_uuid=' | cut -d' ' -f2)
31-
echo "RSS: $rss"
32-
echo "CPU Time: $cpu_time"
33-
echo "TX Bytes: $tx_bytes"
32+
echo -e "$rss\t$cpu_time\t$tx_bytes"
3433
sleep 1
3534
done

0 commit comments

Comments
 (0)