mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 09:39:08 +00:00
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:
parent
4cf1e1290d
commit
3637f0a5bd
@ -4,6 +4,7 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -11,10 +12,12 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Moby is the type of a Moby config file
|
||||
type Moby struct {
|
||||
Kernel string
|
||||
Init string
|
||||
System []MobyImage
|
||||
Daemon []MobyImage
|
||||
Files []struct {
|
||||
Path string
|
||||
Contents string
|
||||
@ -24,6 +27,7 @@ type Moby struct {
|
||||
}
|
||||
}
|
||||
|
||||
// MobyImage is the type of an image config, based on Compose
|
||||
type MobyImage struct {
|
||||
Name string
|
||||
Image string
|
||||
@ -32,10 +36,12 @@ type MobyImage struct {
|
||||
OomScoreAdj int64 `yaml:"oom_score_adj"`
|
||||
Command []string
|
||||
NetworkMode string `yaml:"network_mode"`
|
||||
Pid string
|
||||
}
|
||||
|
||||
const riddler = "mobylinux/riddler:7d4545d8b8ac2700971a83f12a3446a76db28c14@sha256:11b7310df6482fc38aa52b419c2ef1065d7b9207c633d47554e13aa99f6c0b72"
|
||||
|
||||
// NewConfig parses a config file
|
||||
func NewConfig(config []byte) (*Moby, error) {
|
||||
m := Moby{}
|
||||
|
||||
@ -47,9 +53,11 @@ func NewConfig(config []byte) (*Moby, error) {
|
||||
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
|
||||
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
|
||||
args = append(args, "--cap-drop", "all")
|
||||
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))
|
||||
}
|
||||
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 {
|
||||
args = append(args, "-v", bind)
|
||||
@ -75,7 +88,7 @@ func ConfigToRun(image *MobyImage) []string {
|
||||
return args
|
||||
}
|
||||
|
||||
func Filesystem(m *Moby) (*bytes.Buffer, error) {
|
||||
func filesystem(m *Moby) (*bytes.Buffer, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buf)
|
||||
defer tw.Close()
|
@ -7,7 +7,9 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/moby/pkg/initrd"
|
||||
)
|
||||
@ -137,9 +139,18 @@ func build(configfile string) {
|
||||
buffer := bytes.NewBuffer(init)
|
||||
containers = append(containers, buffer)
|
||||
|
||||
for _, image := range m.System {
|
||||
args := ConfigToRun(&image)
|
||||
// get output tarball
|
||||
for i, image := range m.System {
|
||||
args := ConfigToRun(i, "system", &image)
|
||||
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...)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to build container tarball: %v", err)
|
||||
@ -149,7 +160,7 @@ func build(configfile string) {
|
||||
}
|
||||
|
||||
// add files
|
||||
buffer, err = Filesystem(m)
|
||||
buffer, err = filesystem(m)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Fatalf("Error writing outputs: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var conf = "moby.yaml"
|
||||
|
||||
func main() {
|
||||
build("moby.yaml")
|
||||
if len(os.Args) >= 2 {
|
||||
conf = os.Args[1]
|
||||
}
|
||||
build(conf)
|
||||
}
|
@ -13,21 +13,21 @@ const (
|
||||
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 {
|
||||
switch o.Format {
|
||||
case "kernel+initrd":
|
||||
err := outputKernelInitrd(bzimage, initrd)
|
||||
err := outputKernelInitrd(base, bzimage, initrd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||
}
|
||||
case "iso-bios":
|
||||
err := outputISO(bios, "mobylinux.iso", bzimage, initrd)
|
||||
err := outputISO(bios, base+".iso", bzimage, initrd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||
}
|
||||
case "iso-efi":
|
||||
err := outputISO(efi, "mobylinux-efi.iso", bzimage, initrd)
|
||||
err := outputISO(efi, base+"-efi.iso", bzimage, initrd)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
func outputKernelInitrd(bzimage []byte, initrd []byte) error {
|
||||
err := ioutil.WriteFile("initrd.img", initrd, os.FileMode(0644))
|
||||
func outputKernelInitrd(base string, bzimage []byte, initrd []byte) error {
|
||||
err := ioutil.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile("bzImage", bzimage, os.FileMode(0644))
|
||||
err = ioutil.WriteFile(base+"-bzImage", bzimage, os.FileMode(0644))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("bzImage initrd.img")
|
||||
fmt.Println(base + "-bzImage " + base + "-initrd.img")
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user