Phase 3: banger kernel import bridges make-*-kernel.sh output
`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>
This commit is contained in:
parent
48e3a938cf
commit
7192ba24ae
11 changed files with 542 additions and 80 deletions
|
|
@ -1599,10 +1599,45 @@ func newKernelCommand() *cobra.Command {
|
|||
newKernelListCommand(),
|
||||
newKernelShowCommand(),
|
||||
newKernelRmCommand(),
|
||||
newKernelImportCommand(),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func newKernelImportCommand() *cobra.Command {
|
||||
var params api.KernelImportParams
|
||||
cmd := &cobra.Command{
|
||||
Use: "import <name>",
|
||||
Short: "Import a kernel bundle produced by scripts/make-*-kernel.sh",
|
||||
Long: "Copy the kernel, optional initrd, and optional modules directory from <from> into the local kernel catalog keyed by <name>. <from> is usually build/manual/void-kernel or build/manual/alpine-kernel.",
|
||||
Args: exactArgsUsage(1, "usage: banger kernel import <name> --from <dir>"),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
params.Name = args[0]
|
||||
if strings.TrimSpace(params.FromDir) == "" {
|
||||
return errors.New("--from <dir> is required")
|
||||
}
|
||||
abs, err := filepath.Abs(params.FromDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.FromDir = abs
|
||||
layout, _, err := ensureDaemon(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := rpc.Call[api.KernelShowResult](cmd.Context(), layout.SocketPath, "kernel.import", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return printJSON(cmd.OutOrStdout(), result.Entry)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVar(¶ms.FromDir, "from", "", "directory produced by make-*-kernel.sh (e.g. build/manual/void-kernel)")
|
||||
cmd.Flags().StringVar(¶ms.Distro, "distro", "", "distribution label stored in the manifest (e.g. void, alpine)")
|
||||
cmd.Flags().StringVar(¶ms.Arch, "arch", "", "architecture label stored in the manifest (e.g. x86_64)")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func newKernelListCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "list",
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func TestKernelCommandExposesSubcommands(t *testing.T) {
|
|||
for _, sub := range kernel.Commands() {
|
||||
names = append(names, sub.Name())
|
||||
}
|
||||
want := []string{"list", "rm", "show"}
|
||||
want := []string{"import", "list", "rm", "show"}
|
||||
if !reflect.DeepEqual(names, want) {
|
||||
t.Fatalf("kernel subcommands = %v, want %v", names, want)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue