Out with the old, in with the new Moby

- remove remainder of editions code
- add a new check container to run tests without Docker
- switch over `make test` to use new command to build tests

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack 2017-03-06 21:25:11 +00:00
parent 4cf1e1290d
commit 3637f0a5bd
3 changed files with 53 additions and 18 deletions

View File

@ -4,6 +4,7 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"errors" "errors"
"fmt"
"path" "path"
"strconv" "strconv"
"strings" "strings"
@ -11,10 +12,12 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
// Moby is the type of a Moby config file
type Moby struct { type Moby struct {
Kernel string Kernel string
Init string Init string
System []MobyImage System []MobyImage
Daemon []MobyImage
Files []struct { Files []struct {
Path string Path string
Contents string Contents string
@ -24,6 +27,7 @@ type Moby struct {
} }
} }
// MobyImage is the type of an image config, based on Compose
type MobyImage struct { type MobyImage struct {
Name string Name string
Image string Image string
@ -32,10 +36,12 @@ type MobyImage struct {
OomScoreAdj int64 `yaml:"oom_score_adj"` OomScoreAdj int64 `yaml:"oom_score_adj"`
Command []string Command []string
NetworkMode string `yaml:"network_mode"` NetworkMode string `yaml:"network_mode"`
Pid string
} }
const riddler = "mobylinux/riddler:7d4545d8b8ac2700971a83f12a3446a76db28c14@sha256:11b7310df6482fc38aa52b419c2ef1065d7b9207c633d47554e13aa99f6c0b72" const riddler = "mobylinux/riddler:7d4545d8b8ac2700971a83f12a3446a76db28c14@sha256:11b7310df6482fc38aa52b419c2ef1065d7b9207c633d47554e13aa99f6c0b72"
// NewConfig parses a config file
func NewConfig(config []byte) (*Moby, error) { func NewConfig(config []byte) (*Moby, error) {
m := Moby{} m := Moby{}
@ -47,9 +53,11 @@ func NewConfig(config []byte) (*Moby, error) {
return &m, nil return &m, nil
} }
func ConfigToRun(image *MobyImage) []string { // ConfigToRun converts a config to a series of arguments for docker run
func ConfigToRun(order int, path string, image *MobyImage) []string {
// riddler arguments // riddler arguments
args := []string{"-v", "/var/run/docker.sock:/var/run/docker.sock", riddler, image.Image, "/containers/" + image.Name} so := fmt.Sprintf("%03d", order)
args := []string{"-v", "/var/run/docker.sock:/var/run/docker.sock", riddler, image.Image, "/containers/" + path + "/" + so + "-" + image.Name}
// docker arguments // docker arguments
args = append(args, "--cap-drop", "all") args = append(args, "--cap-drop", "all")
for _, cap := range image.Capabilities { for _, cap := range image.Capabilities {
@ -62,7 +70,12 @@ func ConfigToRun(image *MobyImage) []string {
args = append(args, "--oom-score-adj", strconv.FormatInt(image.OomScoreAdj, 10)) args = append(args, "--oom-score-adj", strconv.FormatInt(image.OomScoreAdj, 10))
} }
if image.NetworkMode != "" { if image.NetworkMode != "" {
args = append(args, "--net", image.NetworkMode) // TODO only "host" supported
args = append(args, "--net="+image.NetworkMode)
}
if image.Pid != "" {
// TODO only "host" supported
args = append(args, "--pid="+image.Pid)
} }
for _, bind := range image.Binds { for _, bind := range image.Binds {
args = append(args, "-v", bind) args = append(args, "-v", bind)
@ -75,7 +88,7 @@ func ConfigToRun(image *MobyImage) []string {
return args return args
} }
func Filesystem(m *Moby) (*bytes.Buffer, error) { func filesystem(m *Moby) (*bytes.Buffer, error) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
tw := tar.NewWriter(buf) tw := tar.NewWriter(buf)
defer tw.Close() defer tw.Close()

View File

@ -7,7 +7,9 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"os/exec" "os/exec"
"path/filepath"
"github.com/docker/moby/pkg/initrd" "github.com/docker/moby/pkg/initrd"
) )
@ -137,9 +139,18 @@ func build(configfile string) {
buffer := bytes.NewBuffer(init) buffer := bytes.NewBuffer(init)
containers = append(containers, buffer) containers = append(containers, buffer)
for _, image := range m.System { for i, image := range m.System {
args := ConfigToRun(&image) args := ConfigToRun(i, "system", &image)
// get output tarball out, err := dockerRun(args...)
if err != nil {
log.Fatalf("Failed to build container tarball: %v", err)
}
buffer := bytes.NewBuffer(out)
containers = append(containers, buffer)
}
for i, image := range m.Daemon {
args := ConfigToRun(i, "daemon", &image)
out, err := dockerRun(args...) out, err := dockerRun(args...)
if err != nil { if err != nil {
log.Fatalf("Failed to build container tarball: %v", err) log.Fatalf("Failed to build container tarball: %v", err)
@ -149,7 +160,7 @@ func build(configfile string) {
} }
// add files // add files
buffer, err = Filesystem(m) buffer, err = filesystem(m)
if err != nil { if err != nil {
log.Fatalf("failed to add filesystem parts: %v", err) log.Fatalf("failed to add filesystem parts: %v", err)
} }
@ -160,12 +171,23 @@ func build(configfile string) {
log.Fatalf("Failed to make initrd %v", err) log.Fatalf("Failed to make initrd %v", err)
} }
err = outputs(m, bzimage.Bytes(), initrd.Bytes()) base := filepath.Base(conf)
ext := filepath.Ext(conf)
if ext != "" {
base = base[:len(base)-len(ext)]
}
err = outputs(m, base, bzimage.Bytes(), initrd.Bytes())
if err != nil { if err != nil {
log.Fatalf("Error writing outputs: %v", err) log.Fatalf("Error writing outputs: %v", err)
} }
} }
var conf = "moby.yaml"
func main() { func main() {
build("moby.yaml") if len(os.Args) >= 2 {
conf = os.Args[1]
}
build(conf)
} }

View File

@ -13,21 +13,21 @@ const (
efi = "mobylinux/mkimage-iso-efi:40f35270037dae95584324427e56f829756ff145@sha256:ae5b37ae560a5e030342f3d493d4ad611f2694bcd54eba86bf42ca069da986a7" efi = "mobylinux/mkimage-iso-efi:40f35270037dae95584324427e56f829756ff145@sha256:ae5b37ae560a5e030342f3d493d4ad611f2694bcd54eba86bf42ca069da986a7"
) )
func outputs(m *Moby, bzimage []byte, initrd []byte) error { func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
for _, o := range m.Outputs { for _, o := range m.Outputs {
switch o.Format { switch o.Format {
case "kernel+initrd": case "kernel+initrd":
err := outputKernelInitrd(bzimage, initrd) err := outputKernelInitrd(base, bzimage, initrd)
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-bios": case "iso-bios":
err := outputISO(bios, "mobylinux.iso", bzimage, initrd) err := outputISO(bios, base+".iso", bzimage, initrd)
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, "mobylinux-efi.iso", bzimage, initrd) err := outputISO(efi, base+"-efi.iso", bzimage, initrd)
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)
} }
@ -87,15 +87,15 @@ func outputISO(image, filename string, bzimage []byte, initrd []byte) error {
return nil return nil
} }
func outputKernelInitrd(bzimage []byte, initrd []byte) error { func outputKernelInitrd(base string, bzimage []byte, initrd []byte) error {
err := ioutil.WriteFile("initrd.img", initrd, os.FileMode(0644)) err := ioutil.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644))
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile("bzImage", bzimage, os.FileMode(0644)) err = ioutil.WriteFile(base+"-bzImage", bzimage, os.FileMode(0644))
if err != nil { if err != nil {
return err return err
} }
fmt.Println("bzImage initrd.img") fmt.Println(base + "-bzImage " + base + "-initrd.img")
return nil return nil
} }