mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 01:06:27 +00:00
Rename "output" to "format"
This was confusing as there is an option to output to a file as well. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
69596e17dd
commit
11b573c6fb
2
Makefile
2
Makefile
@ -35,7 +35,7 @@ test: lint moby
|
||||
# go test
|
||||
@go test github.com/moby/tool/src/moby
|
||||
# test build
|
||||
./moby build -output tar test/test.yml
|
||||
./moby build -format tar test/test.yml
|
||||
rm moby test.tar
|
||||
|
||||
.PHONY: install
|
||||
|
@ -19,16 +19,16 @@ import (
|
||||
|
||||
const defaultNameForStdin = "moby"
|
||||
|
||||
type outputList []string
|
||||
type formatList []string
|
||||
|
||||
func (o *outputList) String() string {
|
||||
return fmt.Sprint(*o)
|
||||
func (f *formatList) String() string {
|
||||
return fmt.Sprint(*f)
|
||||
}
|
||||
|
||||
func (o *outputList) Set(value string) error {
|
||||
func (f *formatList) Set(value string) error {
|
||||
// allow comma seperated options or multiple options
|
||||
for _, cs := range strings.Split(value, ",") {
|
||||
*o = append(*o, cs)
|
||||
*f = append(*f, cs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -56,7 +56,7 @@ func getDiskSizeMB(s string) (int, error) {
|
||||
|
||||
// Process the build arguments and execute build
|
||||
func build(args []string) {
|
||||
var buildOut outputList
|
||||
var buildFormats formatList
|
||||
|
||||
outputTypes := moby.OutputTypes()
|
||||
|
||||
@ -73,7 +73,7 @@ func build(args []string) {
|
||||
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)")
|
||||
buildHyperkit := buildCmd.Bool("hyperkit", runtime.GOOS == "darwin", "Use hyperkit for LinuxKit based builds where possible")
|
||||
buildCmd.Var(&buildOut, "output", "Output types to create [ "+strings.Join(outputTypes, " ")+" ]")
|
||||
buildCmd.Var(&buildFormats, "format", "Formats to create [ "+strings.Join(outputTypes, " ")+" ]")
|
||||
|
||||
if err := buildCmd.Parse(args); err != nil {
|
||||
log.Fatal("Unable to parse args")
|
||||
@ -100,36 +100,35 @@ func build(args []string) {
|
||||
// the basic outputs are tarballs, while the packaged ones are the LinuxKit out formats that
|
||||
// cannot be streamed but we do allow multiple ones to be built.
|
||||
|
||||
if len(buildOut) == 0 {
|
||||
if len(buildFormats) == 0 {
|
||||
if *buildOutputFile == "" {
|
||||
buildOut = outputList{"kernel+initrd"}
|
||||
buildFormats = formatList{"kernel+initrd"}
|
||||
} else {
|
||||
buildOut = outputList{"tar"}
|
||||
buildFormats = formatList{"tar"}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Outputs selected: %s", buildOut.String())
|
||||
log.Debugf("Formats selected: %s", buildFormats.String())
|
||||
|
||||
if len(buildOut) > 1 {
|
||||
for _, o := range buildOut {
|
||||
if len(buildFormats) > 1 {
|
||||
for _, o := range buildFormats {
|
||||
if moby.Streamable(o) {
|
||||
log.Fatalf("Output type %s must be the only output specified", o)
|
||||
log.Fatalf("Format type %s must be the only format specified", o)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(buildOut) == 1 && moby.Streamable(buildOut[0]) {
|
||||
if len(buildFormats) == 1 && moby.Streamable(buildFormats[0]) {
|
||||
if *buildOutputFile == "" {
|
||||
*buildOutputFile = filepath.Join(*buildDir, name+"."+buildOut[0])
|
||||
*buildOutputFile = filepath.Join(*buildDir, name+"."+buildFormats[0])
|
||||
// stop the errors in the validation below
|
||||
*buildName = ""
|
||||
*buildDir = ""
|
||||
}
|
||||
|
||||
} else {
|
||||
err := moby.ValidateOutputs(buildOut)
|
||||
err := moby.ValidateFormats(buildFormats)
|
||||
if err != nil {
|
||||
log.Errorf("Error parsing outputs: %v", err)
|
||||
log.Errorf("Error parsing formats: %v", err)
|
||||
buildCmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -137,7 +136,7 @@ func build(args []string) {
|
||||
|
||||
var outputFile *os.File
|
||||
if *buildOutputFile != "" {
|
||||
if len(buildOut) > 1 {
|
||||
if len(buildFormats) > 1 {
|
||||
log.Fatal("The -output option can only be specified when generating a single output format")
|
||||
}
|
||||
if *buildName != "" {
|
||||
@ -146,8 +145,8 @@ func build(args []string) {
|
||||
if *buildDir != "" {
|
||||
log.Fatal("The -output option cannot be specified with -dir")
|
||||
}
|
||||
if !moby.Streamable(buildOut[0]) {
|
||||
log.Fatalf("The -output option cannot be specified for build type %s as it cannot be streamed", buildOut[0])
|
||||
if !moby.Streamable(buildFormats[0]) {
|
||||
log.Fatalf("The -output option cannot be specified for build type %s as it cannot be streamed", buildFormats[0])
|
||||
}
|
||||
if *buildOutputFile == "-" {
|
||||
outputFile = os.Stdout
|
||||
@ -221,8 +220,8 @@ func build(args []string) {
|
||||
// this is a weird interface, but currently only streamable types can have additional files
|
||||
// need to split up the base tarball outputs from the secondary stages
|
||||
var tp string
|
||||
if moby.Streamable(buildOut[0]) {
|
||||
tp = buildOut[0]
|
||||
if moby.Streamable(buildFormats[0]) {
|
||||
tp = buildFormats[0]
|
||||
}
|
||||
err = moby.Build(m, w, *buildPull, tp)
|
||||
if err != nil {
|
||||
@ -232,7 +231,7 @@ func build(args []string) {
|
||||
if outputFile == nil {
|
||||
image := buf.Bytes()
|
||||
log.Infof("Create outputs:")
|
||||
err = moby.Outputs(filepath.Join(*buildDir, name), image, buildOut, size, *buildHyperkit)
|
||||
err = moby.Formats(filepath.Join(*buildDir, name), image, buildFormats, size, *buildHyperkit)
|
||||
if err != nil {
|
||||
log.Fatalf("Error writing outputs: %v", err)
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ then start the `onboot` and `service` containers. The example below shows how yo
|
||||
can run `nginx` on either of these base configs.
|
||||
|
||||
```
|
||||
moby build -output docker -o - docker.yml nginx.yml | docker build -t dockertest -
|
||||
moby build -format docker -o - docker.yml nginx.yml | docker build -t dockertest -
|
||||
docker run -d -p 80:80 --privileged dockertest
|
||||
|
||||
moby build -output kernel+initrd linuxkit.yml nginx.yml
|
||||
moby build -format kernel+initrd linuxkit.yml nginx.yml
|
||||
linuxkit run nginx
|
||||
```
|
||||
|
||||
|
@ -132,33 +132,33 @@ func ensurePrereq(out string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ValidateOutputs checks if the output type is known
|
||||
func ValidateOutputs(out []string) error {
|
||||
log.Debugf("validating output: %v", out)
|
||||
// ValidateFormats checks if the format type is known
|
||||
func ValidateFormats(formats []string) error {
|
||||
log.Debugf("validating output: %v", formats)
|
||||
|
||||
for _, o := range out {
|
||||
for _, o := range formats {
|
||||
f := outFuns[o]
|
||||
if f == nil {
|
||||
return fmt.Errorf("Unknown output type %s", o)
|
||||
return fmt.Errorf("Unknown format type %s", o)
|
||||
}
|
||||
err := ensurePrereq(o)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to set up output type %s: %v", o, err)
|
||||
return fmt.Errorf("Failed to set up format type %s: %v", o, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Outputs generates all the specified output formats
|
||||
func Outputs(base string, image []byte, out []string, size int, hyperkit bool) error {
|
||||
log.Debugf("output: %v %s", out, base)
|
||||
// Formats generates all the specified output formats
|
||||
func Formats(base string, image []byte, formats []string, size int, hyperkit bool) error {
|
||||
log.Debugf("format: %v %s", formats, base)
|
||||
|
||||
err := ValidateOutputs(out)
|
||||
err := ValidateFormats(formats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, o := range out {
|
||||
for _, o := range formats {
|
||||
f := outFuns[o]
|
||||
err := f(base, image, size, hyperkit)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user