hoist kernel cmdline into moby.yaml

Signed-off-by: Tycho Andersen <tycho@docker.com>
This commit is contained in:
Tycho Andersen 2017-03-08 11:09:31 -08:00
parent befb0bcdec
commit 183fb49d71
3 changed files with 40 additions and 24 deletions

View File

@ -14,7 +14,10 @@ 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 string Kernel struct {
Image string
Cmdline string
}
Init string Init string
System []MobyImage System []MobyImage
Daemon []MobyImage Daemon []MobyImage

47
main.go
View File

@ -4,11 +4,11 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"errors" "errors"
"flag"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -129,17 +129,7 @@ func containersInitrd(containers []*bytes.Buffer) (*bytes.Buffer, error) {
return w, nil return w, nil
} }
func build(configfile string) { func build(m *Moby) {
config, err := ioutil.ReadFile(configfile)
if err != nil {
log.Fatalf("Cannot open config file: %v", err)
}
m, err := NewConfig(config)
if err != nil {
log.Fatalf("Invalid config: %v", err)
}
containers := []*bytes.Buffer{} containers := []*bytes.Buffer{}
// get kernel bzImage and initrd tarball from container // get kernel bzImage and initrd tarball from container
@ -148,7 +138,7 @@ func build(configfile string) {
bzimageName = "bzImage" bzimageName = "bzImage"
ktarName = "kernel.tar" ktarName = "kernel.tar"
) )
out, err := dockerRun(m.Kernel, "tar", "cf", "-", bzimageName, ktarName) out, err := dockerRun(m.Kernel.Image, "tar", "cf", "-", bzimageName, ktarName)
if err != nil { if err != nil {
log.Fatalf("Failed to extract kernel image and tarball: %v", err) log.Fatalf("Failed to extract kernel image and tarball: %v", err)
} }
@ -211,11 +201,34 @@ func build(configfile string) {
} }
} }
var conf = "moby.yaml" var (
conf string
cmdline bool
)
func main() { func main() {
if len(os.Args) >= 2 { flag.BoolVar(&cmdline, "cmdline", false, "Print the kernel command line and exit")
conf = os.Args[1] flag.Parse()
conf = "moby.yaml"
if len(flag.Args()) > 0 {
conf = flag.Args()[0]
} }
build(conf)
config, err := ioutil.ReadFile(conf)
if err != nil {
log.Fatalf("Cannot open config file: %v", err)
}
m, err := NewConfig(config)
if err != nil {
log.Fatalf("Invalid config: %v", err)
}
if cmdline {
fmt.Printf("%s\n", m.Kernel.Cmdline)
return
}
build(m)
} }

View File

@ -9,8 +9,8 @@ import (
) )
const ( const (
bios = "mobylinux/mkimage-iso-bios:6b3ef6d6bdcc5fdf2ee683febac99533c2268c89@sha256:2484146c4dfbd2eee83d9dd3adf84d9232e5dd739d8762275dcd50bf60a529c6" bios = "mobylinux/mkimage-iso-bios:489b1f054a77a8f379d0bfc6cd91639b4db6b67c@sha256:0f058951aac4367d132682aa19eeb5cdcb05600a5d51fe5d0fcbd97b03ae4f87"
efi = "mobylinux/mkimage-iso-efi:40f35270037dae95584324427e56f829756ff145@sha256:ae5b37ae560a5e030342f3d493d4ad611f2694bcd54eba86bf42ca069da986a7" efi = "mobylinux/mkimage-iso-efi:b210c58e096e53082d35b28fa2b52dba6ae200c8@sha256:10c2789bf5fbd27c35c5fe2f3b97f75a7108bbde389d0f5ed750e3e2dae95376"
) )
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error { func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
@ -22,12 +22,12 @@ func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
return fmt.Errorf("Error writing %s output: %v", o.Format, err) return fmt.Errorf("Error writing %s output: %v", o.Format, err)
} }
case "iso-bios": case "iso-bios":
err := outputISO(bios, base+".iso", bzimage, initrd) err := outputISO(bios, base+".iso", bzimage, initrd, m.Kernel.Cmdline)
if err != nil { if err != nil {
return fmt.Errorf("Error writing %s output: %v", o.Format, err) return fmt.Errorf("Error writing %s output: %v", o.Format, err)
} }
case "iso-efi": case "iso-efi":
err := outputISO(efi, base+"-efi.iso", bzimage, initrd) err := outputISO(efi, base+"-efi.iso", bzimage, initrd, m.Kernel.Cmdline)
if err != nil { if err != nil {
return fmt.Errorf("Error writing %s output: %v", o.Format, err) return fmt.Errorf("Error writing %s output: %v", o.Format, err)
} }
@ -41,7 +41,7 @@ func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
} }
// TODO add kernel command line // TODO add kernel command line
func outputISO(image, filename string, bzimage []byte, initrd []byte) error { func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
// first build the input tarball from kernel and initrd // first build the input tarball from kernel and initrd
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
tw := tar.NewWriter(buf) tw := tar.NewWriter(buf)
@ -75,7 +75,7 @@ func outputISO(image, filename string, bzimage []byte, initrd []byte) error {
if err != nil { if err != nil {
return err return err
} }
iso, err := dockerRunInput(buf, image) iso, err := dockerRunInput(buf, append([]string{image}, args...)...)
if err != nil { if err != nil {
return err return err
} }