cmd: Add scaffolding to decompress the kernel

Add the '-vmlinux' flag to build and pass it all
the way to the kernel filter.

Note, this commit only adds the flag but does not
yet perform the decompression. This will be added
with the next commit.

Signed-off-by: Rolf Neugebauer <rn@rneugeba.io>
This commit is contained in:
Rolf Neugebauer 2018-11-10 14:43:50 +00:00
parent 4f0cec5c14
commit 09fbcb59d7
3 changed files with 19 additions and 17 deletions

View File

@ -49,6 +49,7 @@ func build(args []string) {
buildSize := buildCmd.String("size", "1024M", "Size for output image, if supported and fixed size") buildSize := buildCmd.String("size", "1024M", "Size for output image, if supported and fixed size")
buildPull := buildCmd.Bool("pull", false, "Always pull images") buildPull := buildCmd.Bool("pull", false, "Always pull images")
buildDisableTrust := buildCmd.Bool("disable-content-trust", false, "Skip image trust verification specified in trust section of config (default false)") buildDisableTrust := buildCmd.Bool("disable-content-trust", false, "Skip image trust verification specified in trust section of config (default false)")
buildDecompressKernel := buildCmd.Bool("decompress-kernel", false, "Decompress the Linux kernel (default false)")
buildCmd.Var(&buildFormats, "format", "Formats to create [ "+strings.Join(outputTypes, " ")+" ]") buildCmd.Var(&buildFormats, "format", "Formats to create [ "+strings.Join(outputTypes, " ")+" ]")
if err := buildCmd.Parse(args); err != nil { if err := buildCmd.Parse(args); err != nil {
@ -203,7 +204,7 @@ func build(args []string) {
if moby.Streamable(buildFormats[0]) { if moby.Streamable(buildFormats[0]) {
tp = buildFormats[0] tp = buildFormats[0]
} }
err = moby.Build(m, w, *buildPull, tp) err = moby.Build(m, w, *buildPull, tp, *buildDecompressKernel)
if err != nil { if err != nil {
log.Fatalf("%v", err) log.Fatalf("%v", err)
} }

View File

@ -142,7 +142,7 @@ func outputImage(image *Image, section string, prefix string, m Moby, idMap map[
} }
// Build performs the actual build process // Build performs the actual build process
func Build(m Moby, w io.Writer, pull bool, tp string) error { func Build(m Moby, w io.Writer, pull bool, tp string, decompressKernel bool) error {
if MobyDir == "" { if MobyDir == "" {
MobyDir = defaultMobyConfigDir() MobyDir = defaultMobyConfigDir()
} }
@ -179,7 +179,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string) error {
if m.Kernel.ref != nil { if m.Kernel.ref != nil {
// get kernel and initrd tarball and ucode cpio archive from container // get kernel and initrd tarball and ucode cpio archive from container
log.Infof("Extract kernel image: %s", m.Kernel.ref) log.Infof("Extract kernel image: %s", m.Kernel.ref)
kf := newKernelFilter(iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar, m.Kernel.UCode) kf := newKernelFilter(iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar, m.Kernel.UCode, decompressKernel)
err := ImageTar(m.Kernel.ref, "", kf, enforceContentTrust(m.Kernel.ref.String(), &m.Trust), pull, "") err := ImageTar(m.Kernel.ref, "", kf, enforceContentTrust(m.Kernel.ref.String(), &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)
@ -255,20 +255,21 @@ func Build(m Moby, w io.Writer, pull bool, tp string) error {
// kernelFilter is a tar.Writer that transforms a kernel image into the output we want on underlying tar writer // kernelFilter is a tar.Writer that transforms a kernel image into the output we want on underlying tar writer
type kernelFilter struct { type kernelFilter struct {
tw *tar.Writer tw *tar.Writer
buffer *bytes.Buffer buffer *bytes.Buffer
hdr *tar.Header hdr *tar.Header
cmdline string cmdline string
kernel string kernel string
tar string tar string
ucode string ucode string
discard bool decompressKernel bool
foundKernel bool discard bool
foundKTar bool foundKernel bool
foundUCode bool foundKTar bool
foundUCode bool
} }
func newKernelFilter(tw *tar.Writer, cmdline string, kernel string, tar, ucode *string) *kernelFilter { func newKernelFilter(tw *tar.Writer, cmdline string, kernel string, tar, ucode *string, decompressKernel bool) *kernelFilter {
tarName, kernelName, ucodeName := "kernel.tar", "kernel", "" tarName, kernelName, ucodeName := "kernel.tar", "kernel", ""
if tar != nil { if tar != nil {
tarName = *tar tarName = *tar
@ -282,7 +283,7 @@ func newKernelFilter(tw *tar.Writer, cmdline string, kernel string, tar, ucode *
if ucode != nil { if ucode != nil {
ucodeName = *ucode ucodeName = *ucode
} }
return &kernelFilter{tw: tw, cmdline: cmdline, kernel: kernelName, tar: tarName, ucode: ucodeName} return &kernelFilter{tw: tw, cmdline: cmdline, kernel: kernelName, tar: tarName, ucode: ucodeName, decompressKernel: decompressKernel}
} }
func (k *kernelFilter) finishTar() error { func (k *kernelFilter) finishTar() error {

View File

@ -62,7 +62,7 @@ func ensureLinuxkitImage(name string) error {
return err return err
} }
defer os.Remove(tf.Name()) defer os.Remove(tf.Name())
Build(m, tf, false, "") Build(m, tf, false, "", false)
if err := tf.Close(); err != nil { if err := tf.Close(); err != nil {
return err return err
} }