Merge pull request #116 from justincormack/kernel-options

Allow specifying the kernel and tarball names, or omitting tarball
This commit is contained in:
Justin Cormack 2017-07-14 14:32:53 +01:00 committed by GitHub
commit a824287800
4 changed files with 41 additions and 13 deletions

View File

@ -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 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. 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` ## `init`
The `init` section is a list of images that are used for the `init` system and are unpacked directly The `init` section is a list of images that are used for the `init` system and are unpacked directly

View File

@ -140,7 +140,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string) error {
if m.Kernel.Image != "" { if m.Kernel.Image != "" {
// get kernel and initrd tarball from container // get kernel and initrd tarball from container
log.Infof("Extract kernel image: %s", m.Kernel.Image) 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) err := ImageTar(m.Kernel.Image, "", kf, enforceContentTrust(m.Kernel.Image, &m.Trust), pull)
if err != nil { if err != nil {
return fmt.Errorf("Failed to extract kernel image and tarball: %v", err) return fmt.Errorf("Failed to extract kernel image and tarball: %v", err)
@ -225,13 +225,25 @@ type kernelFilter struct {
tw *tar.Writer tw *tar.Writer
buffer *bytes.Buffer buffer *bytes.Buffer
cmdline string cmdline string
kernel string
tar string
discard bool discard bool
foundKernel bool foundKernel bool
foundKTar bool foundKTar bool
} }
func newKernelFilter(tw *tar.Writer, cmdline string) *kernelFilter { func newKernelFilter(tw *tar.Writer, cmdline string, kernel string, tar *string) *kernelFilter {
return &kernelFilter{tw: tw, cmdline: cmdline} 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 { func (k *kernelFilter) finishTar() error {
@ -248,8 +260,8 @@ func (k *kernelFilter) Close() error {
if !k.foundKernel { if !k.foundKernel {
return errors.New("did not find kernel in kernel image") return errors.New("did not find kernel in kernel image")
} }
if !k.foundKTar { if !k.foundKTar && k.tar != "" {
return errors.New("did not find kernel.tar in kernel image") return errors.New("did not find kernel tar in kernel image")
} }
return k.finishTar() return k.finishTar()
} }
@ -279,7 +291,7 @@ func (k *kernelFilter) WriteHeader(hdr *tar.Header) error {
} }
tw := k.tw tw := k.tw
switch hdr.Name { switch hdr.Name {
case "kernel": case k.kernel:
if k.foundKernel { if k.foundKernel {
return errors.New("found more than one possible kernel image") 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 { if err := tw.WriteHeader(whdr); err != nil {
return err return err
} }
case "kernel.tar": case k.tar:
k.foundKTar = true k.foundKTar = true
k.discard = false k.discard = false
k.buffer = new(bytes.Buffer) k.buffer = new(bytes.Buffer)

View File

@ -19,10 +19,7 @@ import (
// Moby is the type of a Moby config file // Moby is the type of a Moby config file
type Moby struct { type Moby struct {
Kernel struct { Kernel KernelConfig
Image string
Cmdline string
}
Init []string Init []string
Onboot []Image Onboot []Image
Services []Image Services []Image
@ -30,6 +27,14 @@ type Moby struct {
Files []File 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 // TrustConfig is the type of a content trust config
type TrustConfig struct { type TrustConfig struct {
Image []string Image []string
@ -168,6 +173,12 @@ func AppendConfig(m0, m1 Moby) (Moby, error) {
if m1.Kernel.Cmdline != "" { if m1.Kernel.Cmdline != "" {
moby.Kernel.Cmdline = 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.Init = append(moby.Init, m1.Init...)
moby.Onboot = append(moby.Onboot, m1.Onboot...) moby.Onboot = append(moby.Onboot, m1.Onboot...)
moby.Services = append(moby.Services, m1.Services...) moby.Services = append(moby.Services, m1.Services...)

View File

@ -11,7 +11,9 @@ var schema = string(`
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"image": {"type": "string"}, "image": {"type": "string"},
"cmdline": { "type": "string"} "cmdline": {"type": "string"},
"binary": {"type": "string"},
"tar": {"type": "string"}
} }
}, },
"file": { "file": {