Stage a complete Alpine x86_64 image stack so \ --image alpineworks like the existing manual Void path instead of relying on Debian-oriented image builds.\n\nAdd make targets plus kernel/rootfs/register helpers that download pinned Alpine artifacts, extract a Firecracker-compatible vmlinux, build a matching mkinitfs initramfs, seed OpenRC services, and register/promote a managed image named alpine.\n\nFold in the bring-up fixes discovered during boot validation: use rootfstype=ext4 in shared boot args, install libgcc/libstdc++ for the opencode binary, and give opencode more time to become ready on cold boots.\n\nValidate with go test ./..., the Alpine helper builds, image promotion, and banger vm create --image alpine --name alp --nat plus guest service and port checks.
92 lines
2.4 KiB
Bash
Executable file
92 lines
2.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
log() {
|
|
printf '[register-alpine-image] %s\n' "$*" >&2
|
|
}
|
|
|
|
find_latest_matching() {
|
|
local dir="$1"
|
|
local pattern="$2"
|
|
if [[ ! -d "$dir" ]]; then
|
|
return 1
|
|
fi
|
|
find "$dir" -maxdepth 1 -type f -name "$pattern" | sort | tail -n 1
|
|
}
|
|
|
|
find_latest_module_dir() {
|
|
local root="$1"
|
|
if [[ ! -d "$root" ]]; then
|
|
return 1
|
|
fi
|
|
find "$root" -mindepth 1 -maxdepth 1 -type d | sort | tail -n 1
|
|
}
|
|
|
|
resolve_banger_bin() {
|
|
if [[ -n "${BANGER_BIN:-}" ]]; then
|
|
printf '%s\n' "$BANGER_BIN"
|
|
return
|
|
fi
|
|
if [[ -x "$REPO_ROOT/build/bin/banger" ]]; then
|
|
printf '%s\n' "$REPO_ROOT/build/bin/banger"
|
|
return
|
|
fi
|
|
if [[ -x "$REPO_ROOT/banger" ]]; then
|
|
printf '%s\n' "$REPO_ROOT/banger"
|
|
return
|
|
fi
|
|
if command -v banger >/dev/null 2>&1; then
|
|
command -v banger
|
|
return
|
|
fi
|
|
log "banger binary not found; build it first with 'make build' or set BANGER_BIN"
|
|
exit 1
|
|
}
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
RUNTIME_DIR="${BANGER_MANUAL_DIR:-$REPO_ROOT/build/manual}"
|
|
IMAGE_NAME="${ALPINE_IMAGE_NAME:-alpine}"
|
|
BANGER_BIN="$(resolve_banger_bin)"
|
|
ROOTFS="$RUNTIME_DIR/rootfs-alpine.ext4"
|
|
WORK_SEED="$RUNTIME_DIR/rootfs-alpine.work-seed.ext4"
|
|
|
|
if [[ ! -f "$ROOTFS" ]]; then
|
|
log "missing Alpine rootfs: $ROOTFS"
|
|
exit 1
|
|
fi
|
|
if [[ ! -f "$WORK_SEED" ]]; then
|
|
log "missing Alpine work-seed: $WORK_SEED"
|
|
exit 1
|
|
fi
|
|
|
|
args=(
|
|
image register
|
|
--name "$IMAGE_NAME"
|
|
--rootfs "$ROOTFS"
|
|
--work-seed "$WORK_SEED"
|
|
--docker
|
|
)
|
|
|
|
if [[ ! -d "$RUNTIME_DIR/alpine-kernel" ]]; then
|
|
log "missing staged Alpine kernel artifacts: $RUNTIME_DIR/alpine-kernel"
|
|
log "run 'make alpine-kernel' before registering $IMAGE_NAME"
|
|
exit 1
|
|
fi
|
|
|
|
kernel="$(find_latest_matching "$RUNTIME_DIR/alpine-kernel/boot" 'vmlinux-*' || true)"
|
|
if [[ -z "$kernel" ]]; then
|
|
kernel="$(find_latest_matching "$RUNTIME_DIR/alpine-kernel/boot" 'vmlinuz-*' || true)"
|
|
fi
|
|
initrd="$(find_latest_matching "$RUNTIME_DIR/alpine-kernel/boot" 'initramfs-*' || true)"
|
|
modules="$(find_latest_module_dir "$RUNTIME_DIR/alpine-kernel/lib/modules" || true)"
|
|
|
|
if [[ -z "$kernel" || -z "$initrd" || -z "$modules" ]]; then
|
|
log "staged Alpine kernel is incomplete; expected kernel, initramfs, and modules under $RUNTIME_DIR/alpine-kernel"
|
|
exit 1
|
|
fi
|
|
|
|
log "using staged Alpine kernel artifacts from $RUNTIME_DIR/alpine-kernel"
|
|
args+=(--kernel "$kernel" --initrd "$initrd" --modules "$modules")
|
|
|
|
"$BANGER_BIN" "${args[@]}"
|