Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions images/chromium-headful/Kraftfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ spec: v0.6
runtime: index.unikraft.io/official/base-compat:latest

labels:
cloud.unikraft.v1.instances/scale_to_zero.policy: "on"
cloud.unikraft.v1.instances/scale_to_zero.policy: "idle"
cloud.unikraft.v1.instances/scale_to_zero.stateful: "true"
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms: 4000
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms: 5000

rootfs: ./Dockerfile
rootfs: ./initrd

cmd: ["/wrapper.sh"]
22 changes: 20 additions & 2 deletions images/chromium-headful/build-unikernel.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
#!/usr/bin/env bash

source common.sh
source ../../shared/erofs-utils.sh

# Ensure the mkfs.erofs tool is available
if ! check_mkfs_erofs; then
echo "mkfs.erofs is not installed. Installing erofs-utils..."
install_erofs_utils
fi

set -euo pipefail

# Build the root file system
source ../../shared/start-buildkit.sh

rm -rf ./.rootfs || true
# Build the API binary
source ../../shared/build-server.sh "$(pwd)/bin"
app_name=chromium-headful-build
docker build --platform linux/amd64 -t "$IMAGE" .
docker rm cnt-"$app_name" || true
docker create --platform linux/amd64 --name cnt-"$app_name" "$IMAGE" /bin/sh
docker cp cnt-"$app_name":/ ./.rootfs
rm -f initrd || true
mkfs.erofs --all-root -d2 -E noinline_data -b 4096 initrd ./.rootfs

# Package the unikernel (and the new initrd) to KraftCloud
kraft pkg \
--name $UKC_INDEX/$IMAGE \
--plat kraftcloud --arch x86_64 \
--plat kraftcloud \
--arch x86_64 \
--strategy overwrite \
--push \
.
48 changes: 5 additions & 43 deletions images/chromium-headless/build-unikernel.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,10 @@
#!/usr/bin/env bash

source common.sh
source ../../shared/erofs-utils.sh

# Function to check if mkfs.erofs is available
check_mkfs_erofs() {
if command -v mkfs.erofs &>/dev/null; then
echo "mkfs.erofs is already installed."
return 0
else
echo "mkfs.erofs is not installed."
return 1
fi
}

# Function to install erofs-utils package
install_erofs_utils() {
if command -v apt-get &>/dev/null; then
echo "Detected Ubuntu/Debian-based system. Installing erofs-utils..."
sudo apt update
sudo apt install -y erofs-utils
elif command -v dnf &>/dev/null; then
echo "Detected Fedora-based system. Installing erofs-utils..."
sudo dnf install -y erofs-utils
elif command -v yum &>/dev/null; then
echo "Detected CentOS/RHEL-based system. Installing erofs-utils..."
sudo yum install -y erofs-utils
elif [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &>/dev/null; then
echo "Detected macOS. Installing erofs-utils..."
brew install erofs-utils
else
echo "Homebrew (brew) not found. Please install Homebrew first."
exit 1
fi
else
echo "Unsupported operating system or package manager. Please install erofs-utils manually."
exit 1
fi
}

check_mkfs_erofs
if [ $? -ne 0 ]; then
# Ensure the mkfs.erofs tool is present
if ! check_mkfs_erofs; then
echo "mkfs.erofs is not installed. Installing erofs-utils..."
install_erofs_utils
fi
Expand All @@ -50,11 +14,9 @@ set -euo pipefail
cd image/

# Build the root file system
source ../../shared/start-buildkit.sh
rm -rf ./.rootfs || true

# Load configuration
app_name=chromium-headless-test

app_name=chromium-headless-build
docker build --platform linux/amd64 -t "$IMAGE" .
docker rm cnt-"$app_name" || true
docker create --platform linux/amd64 --name cnt-"$app_name" "$IMAGE" /bin/sh
Expand Down
43 changes: 43 additions & 0 deletions shared/erofs-utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# erofs-utils.sh
# ----------------
# Shared utility functions for verifying that mkfs.erofs (provided by the
# erofs-utils package) is available on the host and installing it when it is
# missing. This script is meant to be sourced by other build scripts.

set -e -o pipefail

# Returns 0 if mkfs.erofs is on the PATH, 1 otherwise.
check_mkfs_erofs() {
if command -v mkfs.erofs &>/dev/null; then
return 0
else
return 1
fi
}

# Installs the erofs-utils package using the host's package manager.
install_erofs_utils() {
if command -v apt-get &>/dev/null; then
echo "Detected Debian/Ubuntu system. Installing erofs-utils …"
sudo apt update
sudo apt install -y erofs-utils
elif command -v dnf &>/dev/null; then
echo "Detected Fedora system. Installing erofs-utils …"
sudo dnf install -y erofs-utils
elif command -v yum &>/dev/null; then
echo "Detected CentOS/RHEL system. Installing erofs-utils …"
sudo yum install -y erofs-utils
elif [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &>/dev/null; then
echo "Detected macOS system. Installing erofs-utils via Homebrew …"
brew install erofs-utils
else
echo "Homebrew is required but not found. Please install Homebrew first."
exit 1
fi
else
echo "Unsupported operating system or package manager; please install erofs-utils manually."
exit 1
fi
}
Loading