mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 02:51:55 +00:00
Remove output formats from the Yaml file, put in CLI
This removes outputs from yaml, instead you can do ``` moby build -output tar -output qcow2 file.yaml ``` or alternative syntax ``` moby build -output tar,qcow2 file.yaml ``` In future we may change this to be available in a `moby package` step, but lets try this for now. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
b47f3dec4a
commit
cbbedbfc57
2
Makefile
2
Makefile
@ -22,7 +22,7 @@ lint:
|
|||||||
@go test github.com/moby/tool/cmd/moby
|
@go test github.com/moby/tool/cmd/moby
|
||||||
|
|
||||||
test: moby
|
test: moby
|
||||||
./moby build test/test.yml
|
./moby build -output tar test/test.yml
|
||||||
rm moby test.tar
|
rm moby test.tar
|
||||||
|
|
||||||
PHONY: install
|
PHONY: install
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
@ -17,8 +18,30 @@ import (
|
|||||||
|
|
||||||
const defaultNameForStdin = "moby"
|
const defaultNameForStdin = "moby"
|
||||||
|
|
||||||
|
type outputList []string
|
||||||
|
|
||||||
|
func (o *outputList) String() string {
|
||||||
|
return fmt.Sprint(*o)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *outputList) Set(value string) error {
|
||||||
|
// allow comma seperated options or multiple options
|
||||||
|
for _, cs := range strings.Split(value, ",") {
|
||||||
|
*o = append(*o, cs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Process the build arguments and execute build
|
// Process the build arguments and execute build
|
||||||
func build(args []string) {
|
func build(args []string) {
|
||||||
|
var buildOut outputList
|
||||||
|
|
||||||
|
outputTypes := []string{}
|
||||||
|
for k := range outFuns {
|
||||||
|
outputTypes = append(outputTypes, k)
|
||||||
|
}
|
||||||
|
sort.Strings(outputTypes)
|
||||||
|
|
||||||
buildCmd := flag.NewFlagSet("build", flag.ExitOnError)
|
buildCmd := flag.NewFlagSet("build", flag.ExitOnError)
|
||||||
buildCmd.Usage = func() {
|
buildCmd.Usage = func() {
|
||||||
fmt.Printf("USAGE: %s build [options] <file>[.yml] | -\n\n", os.Args[0])
|
fmt.Printf("USAGE: %s build [options] <file>[.yml] | -\n\n", os.Args[0])
|
||||||
@ -27,12 +50,19 @@ func build(args []string) {
|
|||||||
}
|
}
|
||||||
buildName := buildCmd.String("name", "", "Name to use for output files")
|
buildName := buildCmd.String("name", "", "Name to use for output files")
|
||||||
buildPull := buildCmd.Bool("pull", false, "Always pull images")
|
buildPull := buildCmd.Bool("pull", false, "Always pull images")
|
||||||
|
buildCmd.Var(&buildOut, "output", "Output types to create [ "+strings.Join(outputTypes, " ")+" ]")
|
||||||
|
|
||||||
if err := buildCmd.Parse(args); err != nil {
|
if err := buildCmd.Parse(args); err != nil {
|
||||||
log.Fatal("Unable to parse args")
|
log.Fatal("Unable to parse args")
|
||||||
}
|
}
|
||||||
remArgs := buildCmd.Args()
|
remArgs := buildCmd.Args()
|
||||||
|
|
||||||
|
if len(buildOut) == 0 {
|
||||||
|
buildOut = outputList{"kernel+initrd"}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Outputs selected: %s", buildOut.String())
|
||||||
|
|
||||||
if len(remArgs) == 0 {
|
if len(remArgs) == 0 {
|
||||||
fmt.Println("Please specify a configuration file")
|
fmt.Println("Please specify a configuration file")
|
||||||
buildCmd.Usage()
|
buildCmd.Usage()
|
||||||
@ -71,7 +101,7 @@ func build(args []string) {
|
|||||||
image := buildInternal(m, name, *buildPull)
|
image := buildInternal(m, name, *buildPull)
|
||||||
|
|
||||||
log.Infof("Create outputs:")
|
log.Infof("Create outputs:")
|
||||||
err = outputs(m, name, image)
|
err = outputs(name, image, buildOut)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error writing outputs: %v", err)
|
log.Fatalf("Error writing outputs: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,6 @@ type Moby struct {
|
|||||||
Contents string
|
Contents string
|
||||||
Source string
|
Source string
|
||||||
}
|
}
|
||||||
Outputs []struct {
|
|
||||||
Format string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrustConfig is the type of a content trust config
|
// TrustConfig is the type of a content trust config
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
func TestOverrides(t *testing.T) {
|
func TestOverrides(t *testing.T) {
|
||||||
var yamlCaps = []string{"CAP_SYS_ADMIN"}
|
var yamlCaps = []string{"CAP_SYS_ADMIN"}
|
||||||
|
|
||||||
var yaml MobyImage = MobyImage{
|
var yaml = MobyImage{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Image: "testimage",
|
Image: "testimage",
|
||||||
Capabilities: &yamlCaps,
|
Capabilities: &yamlCaps,
|
||||||
@ -20,7 +20,7 @@ func TestOverrides(t *testing.T) {
|
|||||||
|
|
||||||
var labelCaps = []string{"CAP_SYS_CHROOT"}
|
var labelCaps = []string{"CAP_SYS_CHROOT"}
|
||||||
|
|
||||||
var label MobyImage = MobyImage{
|
var label = MobyImage{
|
||||||
Capabilities: &labelCaps,
|
Capabilities: &labelCaps,
|
||||||
Cwd: "/label/directory",
|
Cwd: "/label/directory",
|
||||||
}
|
}
|
||||||
|
@ -21,94 +21,118 @@ const (
|
|||||||
vmdk = "linuxkit/mkimage-vmdk:182b541474ca7965c8e8f987389b651859f760da@sha256:99638c5ddb17614f54c6b8e11bd9d49d1dea9d837f38e0f6c1a5f451085d449b"
|
vmdk = "linuxkit/mkimage-vmdk:182b541474ca7965c8e8f987389b651859f760da@sha256:99638c5ddb17614f54c6b8e11bd9d49d1dea9d837f38e0f6c1a5f451085d449b"
|
||||||
)
|
)
|
||||||
|
|
||||||
func outputs(m Moby, base string, image []byte) error {
|
var outFuns = map[string]func(string, []byte) error{
|
||||||
log.Debugf("output: %s %s", m.Outputs, base)
|
"tar": func(base string, image []byte) error {
|
||||||
|
|
||||||
for _, o := range m.Outputs {
|
|
||||||
switch o.Format {
|
|
||||||
case "tar":
|
|
||||||
err := outputTar(base, image)
|
err := outputTar(base, image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing tar output: %v", err)
|
||||||
}
|
}
|
||||||
case "kernel+initrd":
|
return nil
|
||||||
|
},
|
||||||
|
"kernel+initrd": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputKernelInitrd(base, kernel, initrd, cmdline)
|
err = outputKernelInitrd(base, kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing kernel+initrd output: %v", err)
|
||||||
}
|
}
|
||||||
case "iso-bios":
|
return nil
|
||||||
|
},
|
||||||
|
"iso-bios": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImg(bios, base+".iso", kernel, initrd, cmdline)
|
err = outputImg(bios, base+".iso", kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing iso-bios output: %v", err)
|
||||||
}
|
}
|
||||||
case "iso-efi":
|
return nil
|
||||||
|
},
|
||||||
|
"iso-efi": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImg(efi, base+"-efi.iso", kernel, initrd, cmdline)
|
err = outputImg(efi, base+"-efi.iso", kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing iso-efi output: %v", err)
|
||||||
}
|
}
|
||||||
case "img-gz":
|
return nil
|
||||||
|
},
|
||||||
|
"img-gz": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImgSize(img, base+".img.gz", kernel, initrd, cmdline, "1G")
|
err = outputImgSize(img, base+".img.gz", kernel, initrd, cmdline, "1G")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing img-gz output: %v", err)
|
||||||
}
|
}
|
||||||
case "gcp-img":
|
return nil
|
||||||
|
},
|
||||||
|
"gcp-img": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImg(gcp, base+".img.tar.gz", kernel, initrd, cmdline)
|
err = outputImg(gcp, base+".img.tar.gz", kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing gcp-img output: %v", err)
|
||||||
}
|
}
|
||||||
case "qcow", "qcow2":
|
return nil
|
||||||
|
},
|
||||||
|
"qcow2": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImg(qcow, base+".qcow2", kernel, initrd, cmdline)
|
err = outputImg(qcow, base+".qcow2", kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing qcow2 output: %v", err)
|
||||||
}
|
}
|
||||||
case "vhd":
|
return nil
|
||||||
|
},
|
||||||
|
"vhd": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImg(vhd, base+".vhd", kernel, initrd, cmdline)
|
err = outputImg(vhd, base+".vhd", kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writingvhd output: %v", err)
|
||||||
}
|
}
|
||||||
case "vmdk":
|
return nil
|
||||||
|
},
|
||||||
|
"vmdk": func(base string, image []byte) error {
|
||||||
kernel, initrd, cmdline, err := tarToInitrd(image)
|
kernel, initrd, cmdline, err := tarToInitrd(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error converting to initrd: %v", err)
|
return fmt.Errorf("Error converting to initrd: %v", err)
|
||||||
}
|
}
|
||||||
err = outputImg(vmdk, base+".vmdk", kernel, initrd, cmdline)
|
err = outputImg(vmdk, base+".vmdk", kernel, initrd, cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing vmdk output: %v", err)
|
||||||
}
|
}
|
||||||
case "":
|
return nil
|
||||||
return fmt.Errorf("No format specified for output")
|
},
|
||||||
default:
|
}
|
||||||
return fmt.Errorf("Unknown output type %s", o.Format)
|
|
||||||
|
func outputs(base string, image []byte, out outputList) error {
|
||||||
|
log.Debugf("output: %v %s", out, base)
|
||||||
|
|
||||||
|
for _, o := range out {
|
||||||
|
f := outFuns[o]
|
||||||
|
if f == nil {
|
||||||
|
return fmt.Errorf("Unknown output type %s", o)
|
||||||
|
}
|
||||||
|
err := f(base, image)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,17 +29,6 @@ var schema = string(`
|
|||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "$ref": "#/definitions/file" }
|
"items": { "$ref": "#/definitions/file" }
|
||||||
},
|
},
|
||||||
"output": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": false,
|
|
||||||
"properties": {
|
|
||||||
"format": {"type": "string"}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": {
|
|
||||||
"type": "array",
|
|
||||||
"items": { "$ref": "#/definitions/output" }
|
|
||||||
},
|
|
||||||
"trust": {
|
"trust": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
@ -116,8 +105,7 @@ var schema = string(`
|
|||||||
"onboot": { "$ref": "#/definitions/images" },
|
"onboot": { "$ref": "#/definitions/images" },
|
||||||
"services": { "$ref": "#/definitions/images" },
|
"services": { "$ref": "#/definitions/images" },
|
||||||
"trust": { "$ref": "#/definitions/trust" },
|
"trust": { "$ref": "#/definitions/trust" },
|
||||||
"files": { "$ref": "#/definitions/files" },
|
"files": { "$ref": "#/definitions/files" }
|
||||||
"outputs": { "$ref": "#/definitions/outputs" }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
@ -56,5 +56,3 @@ trust:
|
|||||||
- linuxkit/kernel
|
- linuxkit/kernel
|
||||||
- linuxkit/binfmt
|
- linuxkit/binfmt
|
||||||
- linuxkit/rngd
|
- linuxkit/rngd
|
||||||
outputs:
|
|
||||||
- format: tar
|
|
||||||
|
Loading…
Reference in New Issue
Block a user