From 830be373dab6b344d9b1a6a5798e0cd661da0cb0 Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Fri, 14 Jul 2017 13:34:07 +0100 Subject: [PATCH] Allow specifying the kernel and tarball names, or omitting tarball fix #113 Use `tar: none` or `tar: ""` to omit the tarball. Signed-off-by: Justin Cormack --- docs/yaml.md | 3 +++ src/moby/build.go | 26 +++++++++++++++++++------- src/moby/config.go | 19 +++++++++++++++---- src/moby/schema.go | 6 ++++-- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/docs/yaml.md b/docs/yaml.md index 9b9db8ea2..b802c6f7e 100644 --- a/docs/yaml.md +++ b/docs/yaml.md @@ -44,6 +44,9 @@ which should contain a `kernel` file that will be booted (eg a `bzImage` for `am called `kernel.tar` which is a tarball that is unpacked into the root, which should usually contain a kernel modules directory. `cmdline` specifies the kernel command line options if required. +To override the names, you can specify the kernel image name with `binary: bzImage` and the tar image +with `tar: kernel.tar` or the empty string or `none` if you do not want to use a tarball at all. + ## `init` The `init` section is a list of images that are used for the `init` system and are unpacked directly diff --git a/src/moby/build.go b/src/moby/build.go index da6fbdd83..d2fcf266b 100644 --- a/src/moby/build.go +++ b/src/moby/build.go @@ -140,7 +140,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string) error { if m.Kernel.Image != "" { // get kernel and initrd tarball from container log.Infof("Extract kernel image: %s", m.Kernel.Image) - kf := newKernelFilter(iw, m.Kernel.Cmdline) + kf := newKernelFilter(iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar) err := ImageTar(m.Kernel.Image, "", kf, enforceContentTrust(m.Kernel.Image, &m.Trust), pull) if err != nil { return fmt.Errorf("Failed to extract kernel image and tarball: %v", err) @@ -225,13 +225,25 @@ type kernelFilter struct { tw *tar.Writer buffer *bytes.Buffer cmdline string + kernel string + tar string discard bool foundKernel bool foundKTar bool } -func newKernelFilter(tw *tar.Writer, cmdline string) *kernelFilter { - return &kernelFilter{tw: tw, cmdline: cmdline} +func newKernelFilter(tw *tar.Writer, cmdline string, kernel string, tar *string) *kernelFilter { + tarName, kernelName := "kernel.tar", "kernel" + if tar != nil { + tarName = *tar + if tarName == "none" { + tarName = "" + } + } + if kernel != "" { + kernelName = kernel + } + return &kernelFilter{tw: tw, cmdline: cmdline, kernel: kernelName, tar: tarName} } func (k *kernelFilter) finishTar() error { @@ -248,8 +260,8 @@ func (k *kernelFilter) Close() error { if !k.foundKernel { return errors.New("did not find kernel in kernel image") } - if !k.foundKTar { - return errors.New("did not find kernel.tar in kernel image") + if !k.foundKTar && k.tar != "" { + return errors.New("did not find kernel tar in kernel image") } return k.finishTar() } @@ -279,7 +291,7 @@ func (k *kernelFilter) WriteHeader(hdr *tar.Header) error { } tw := k.tw switch hdr.Name { - case "kernel": + case k.kernel: if k.foundKernel { return errors.New("found more than one possible kernel image") } @@ -315,7 +327,7 @@ func (k *kernelFilter) WriteHeader(hdr *tar.Header) error { if err := tw.WriteHeader(whdr); err != nil { return err } - case "kernel.tar": + case k.tar: k.foundKTar = true k.discard = false k.buffer = new(bytes.Buffer) diff --git a/src/moby/config.go b/src/moby/config.go index 6703ff8b3..2f113e5df 100644 --- a/src/moby/config.go +++ b/src/moby/config.go @@ -19,10 +19,7 @@ import ( // Moby is the type of a Moby config file type Moby struct { - Kernel struct { - Image string - Cmdline string - } + Kernel KernelConfig Init []string Onboot []Image Services []Image @@ -30,6 +27,14 @@ type Moby struct { Files []File } +// KernelConfig is the type of the config for a kernel +type KernelConfig struct { + Image string + Cmdline string + Binary string + Tar *string +} + // TrustConfig is the type of a content trust config type TrustConfig struct { Image []string @@ -168,6 +173,12 @@ func AppendConfig(m0, m1 Moby) (Moby, error) { if m1.Kernel.Cmdline != "" { moby.Kernel.Cmdline = m1.Kernel.Cmdline } + if m1.Kernel.Binary != "" { + moby.Kernel.Binary = m1.Kernel.Binary + } + if m1.Kernel.Tar != nil { + moby.Kernel.Tar = m1.Kernel.Tar + } moby.Init = append(moby.Init, m1.Init...) moby.Onboot = append(moby.Onboot, m1.Onboot...) moby.Services = append(moby.Services, m1.Services...) diff --git a/src/moby/schema.go b/src/moby/schema.go index 3539c205c..effe4836d 100644 --- a/src/moby/schema.go +++ b/src/moby/schema.go @@ -10,8 +10,10 @@ var schema = string(` "type": "object", "additionalProperties": false, "properties": { - "image": { "type": "string"}, - "cmdline": { "type": "string"} + "image": {"type": "string"}, + "cmdline": {"type": "string"}, + "binary": {"type": "string"}, + "tar": {"type": "string"} } }, "file": {