`banger kernel import <name> --from <dir>` copies a staged kernel
bundle into the local catalog. <dir> is the output of
`make void-kernel` or `make alpine-kernel` (build/manual/void-kernel/
or build/manual/alpine-kernel/).
kernelcat.DiscoverPaths locates artifacts under <dir>:
1. Prefers metadata.json (written by make-void-kernel.sh).
2. Falls back to globbing: boot/vmlinux-* or vmlinuz-* (Alpine
fallback), boot/initramfs-*, lib/modules/<latest>.
The daemon's KernelImport copies kernel + optional initrd via
system.CopyFilePreferClone and modules via system.CopyDirContents
(no-sudo mode — catalog lives under ~/.local/state), computes SHA256
over the kernel, and writes the manifest via kernelcat.WriteLocal.
While wiring this up, fixed a latent bug in system.CopyDirContents:
filepath.Join(sourceDir, ".") silently drops the trailing dot, so
`cp -a source source/contents target/` was copying the whole source
directory (including its basename) instead of just its contents.
Replaced the join with a manual "/." suffix. imagemgr.StageBootArtifacts
(the only existing caller) silently benefits.
scripts/register-void-image.sh and scripts/register-alpine-image.sh
are rewritten to use `banger kernel import … && banger image register
--kernel-ref …` instead of the find-and-pass-paths dance. Preserves
the same user-facing commands and env vars.
Tests cover: metadata.json preference, glob fallback, Alpine vmlinuz
fallback, kernel-missing error, round-trip copy into the catalog, and
the --from required flag.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.7 KiB
Bash
Executable file
64 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
log() {
|
|
printf '[register-alpine-image] %s\n' "$*" >&2
|
|
}
|
|
|
|
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}"
|
|
KERNEL_REF="${ALPINE_KERNEL_REF:-$IMAGE_NAME}"
|
|
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
|
|
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
|
|
|
|
log "importing Alpine kernel from $RUNTIME_DIR/alpine-kernel as $KERNEL_REF"
|
|
"$BANGER_BIN" kernel import "$KERNEL_REF" \
|
|
--from "$RUNTIME_DIR/alpine-kernel" \
|
|
--distro alpine \
|
|
--arch x86_64
|
|
|
|
log "registering image $IMAGE_NAME with kernel-ref $KERNEL_REF"
|
|
"$BANGER_BIN" image register \
|
|
--name "$IMAGE_NAME" \
|
|
--rootfs "$ROOTFS" \
|
|
--work-seed "$WORK_SEED" \
|
|
--docker \
|
|
--kernel-ref "$KERNEL_REF"
|