mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 01:06:27 +00:00
Merge pull request #146 from justincormack/formats
Rename "output" to "format"
This commit is contained in:
commit
1ff0e3beee
2
Makefile
2
Makefile
@ -35,7 +35,7 @@ test: lint moby
|
|||||||
# go test
|
# go test
|
||||||
@go test github.com/moby/tool/src/moby
|
@go test github.com/moby/tool/src/moby
|
||||||
# test build
|
# test build
|
||||||
./moby build -output tar test/test.yml
|
./moby build -format tar test/test.yml
|
||||||
rm moby test.tar
|
rm moby test.tar
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
|
@ -19,16 +19,16 @@ import (
|
|||||||
|
|
||||||
const defaultNameForStdin = "moby"
|
const defaultNameForStdin = "moby"
|
||||||
|
|
||||||
type outputList []string
|
type formatList []string
|
||||||
|
|
||||||
func (o *outputList) String() string {
|
func (f *formatList) String() string {
|
||||||
return fmt.Sprint(*o)
|
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
|
// allow comma seperated options or multiple options
|
||||||
for _, cs := range strings.Split(value, ",") {
|
for _, cs := range strings.Split(value, ",") {
|
||||||
*o = append(*o, cs)
|
*f = append(*f, cs)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func getDiskSizeMB(s string) (int, error) {
|
|||||||
|
|
||||||
// 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
|
var buildFormats formatList
|
||||||
|
|
||||||
outputTypes := moby.OutputTypes()
|
outputTypes := moby.OutputTypes()
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ func build(args []string) {
|
|||||||
buildPull := buildCmd.Bool("pull", false, "Always pull images")
|
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)")
|
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")
|
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 {
|
if err := buildCmd.Parse(args); err != nil {
|
||||||
log.Fatal("Unable to parse args")
|
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
|
// 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.
|
// cannot be streamed but we do allow multiple ones to be built.
|
||||||
|
|
||||||
if len(buildOut) == 0 {
|
if len(buildFormats) == 0 {
|
||||||
if *buildOutputFile == "" {
|
if *buildOutputFile == "" {
|
||||||
buildOut = outputList{"kernel+initrd"}
|
buildFormats = formatList{"kernel+initrd"}
|
||||||
} else {
|
} 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 {
|
if len(buildFormats) > 1 {
|
||||||
for _, o := range buildOut {
|
for _, o := range buildFormats {
|
||||||
if moby.Streamable(o) {
|
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 == "" {
|
if *buildOutputFile == "" {
|
||||||
*buildOutputFile = filepath.Join(*buildDir, name+"."+buildOut[0])
|
*buildOutputFile = filepath.Join(*buildDir, name+"."+buildFormats[0])
|
||||||
// stop the errors in the validation below
|
// stop the errors in the validation below
|
||||||
*buildName = ""
|
*buildName = ""
|
||||||
*buildDir = ""
|
*buildDir = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err := moby.ValidateOutputs(buildOut)
|
err := moby.ValidateFormats(buildFormats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error parsing outputs: %v", err)
|
log.Errorf("Error parsing formats: %v", err)
|
||||||
buildCmd.Usage()
|
buildCmd.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -137,7 +136,7 @@ func build(args []string) {
|
|||||||
|
|
||||||
var outputFile *os.File
|
var outputFile *os.File
|
||||||
if *buildOutputFile != "" {
|
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")
|
log.Fatal("The -output option can only be specified when generating a single output format")
|
||||||
}
|
}
|
||||||
if *buildName != "" {
|
if *buildName != "" {
|
||||||
@ -146,8 +145,8 @@ func build(args []string) {
|
|||||||
if *buildDir != "" {
|
if *buildDir != "" {
|
||||||
log.Fatal("The -output option cannot be specified with -dir")
|
log.Fatal("The -output option cannot be specified with -dir")
|
||||||
}
|
}
|
||||||
if !moby.Streamable(buildOut[0]) {
|
if !moby.Streamable(buildFormats[0]) {
|
||||||
log.Fatalf("The -output option cannot be specified for build type %s as it cannot be streamed", buildOut[0])
|
log.Fatalf("The -output option cannot be specified for build type %s as it cannot be streamed", buildFormats[0])
|
||||||
}
|
}
|
||||||
if *buildOutputFile == "-" {
|
if *buildOutputFile == "-" {
|
||||||
outputFile = os.Stdout
|
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
|
// 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
|
// need to split up the base tarball outputs from the secondary stages
|
||||||
var tp string
|
var tp string
|
||||||
if moby.Streamable(buildOut[0]) {
|
if moby.Streamable(buildFormats[0]) {
|
||||||
tp = buildOut[0]
|
tp = buildFormats[0]
|
||||||
}
|
}
|
||||||
err = moby.Build(m, w, *buildPull, tp)
|
err = moby.Build(m, w, *buildPull, tp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -232,7 +231,7 @@ func build(args []string) {
|
|||||||
if outputFile == nil {
|
if outputFile == nil {
|
||||||
image := buf.Bytes()
|
image := buf.Bytes()
|
||||||
log.Infof("Create outputs:")
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Error writing outputs: %v", err)
|
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.
|
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
|
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
|
linuxkit run nginx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -132,33 +132,33 @@ func ensurePrereq(out string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateOutputs checks if the output type is known
|
// ValidateFormats checks if the format type is known
|
||||||
func ValidateOutputs(out []string) error {
|
func ValidateFormats(formats []string) error {
|
||||||
log.Debugf("validating output: %v", out)
|
log.Debugf("validating output: %v", formats)
|
||||||
|
|
||||||
for _, o := range out {
|
for _, o := range formats {
|
||||||
f := outFuns[o]
|
f := outFuns[o]
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return fmt.Errorf("Unknown output type %s", o)
|
return fmt.Errorf("Unknown format type %s", o)
|
||||||
}
|
}
|
||||||
err := ensurePrereq(o)
|
err := ensurePrereq(o)
|
||||||
if err != nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outputs generates all the specified output formats
|
// Formats generates all the specified output formats
|
||||||
func Outputs(base string, image []byte, out []string, size int, hyperkit bool) error {
|
func Formats(base string, image []byte, formats []string, size int, hyperkit bool) error {
|
||||||
log.Debugf("output: %v %s", out, base)
|
log.Debugf("format: %v %s", formats, base)
|
||||||
|
|
||||||
err := ValidateOutputs(out)
|
err := ValidateFormats(formats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, o := range out {
|
for _, o := range formats {
|
||||||
f := outFuns[o]
|
f := outFuns[o]
|
||||||
err := f(base, image, size, hyperkit)
|
err := f(base, image, size, hyperkit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user