Skip to content

Commit

Permalink
Merge pull request linuxkit#70 from justincormack/multiple-yaml
Browse files Browse the repository at this point in the history
Allow specification of multiple yaml files for a single build
  • Loading branch information
justincormack committed Jun 5, 2017
2 parents 3a16c02 + 54e58f2 commit 181c66d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
57 changes: 31 additions & 26 deletions cmd/moby/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,46 @@ func build(args []string) {
}

name := *buildName
var config []byte
if conf := remArgs[0]; conf == "-" {
var err error
config, err = ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Cannot read stdin: %v", err)
}
if name == "" {
name = defaultNameForStdin
}
} else {
if !(filepath.Ext(conf) == ".yml" || filepath.Ext(conf) == ".yaml") {
conf = conf + ".yml"

var moby Moby
for _, arg := range remArgs {
var config []byte
if conf := arg; conf == "-" {
var err error
config, err = ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Cannot read stdin: %v", err)
}
if name == "" {
name = defaultNameForStdin
}
} else {
if !(filepath.Ext(conf) == ".yml" || filepath.Ext(conf) == ".yaml") {
conf = conf + ".yml"
}
var err error
config, err = ioutil.ReadFile(conf)
if err != nil {
log.Fatalf("Cannot open config file: %v", err)
}
if name == "" {
name = strings.TrimSuffix(filepath.Base(conf), filepath.Ext(conf))
}
}
var err error
config, err = ioutil.ReadFile(conf)

m, err := NewConfig(config)
if err != nil {
log.Fatalf("Cannot open config file: %v", err)
log.Fatalf("Invalid config: %v", err)
}
if name == "" {
name = strings.TrimSuffix(filepath.Base(conf), filepath.Ext(conf))
}
}

m, err := NewConfig(config)
if err != nil {
log.Fatalf("Invalid config: %v", err)
moby = AppendConfig(moby, m)
}

if *buildDisableTrust {
log.Debugf("Disabling content trust checks for this build")
m.Trust = TrustConfig{}
moby.Trust = TrustConfig{}
}

image := buildInternal(m, *buildPull)
image := buildInternal(moby, *buildPull)

log.Infof("Create outputs:")
err = outputs(filepath.Join(*buildDir, name), image, buildOut, size, *buildHyperkit)
Expand Down
19 changes: 19 additions & 0 deletions cmd/moby/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ func NewConfig(config []byte) (Moby, error) {
return m, nil
}

// AppendConfig appends two configs.
func AppendConfig(m0, m1 Moby) Moby {
moby := m0
if m1.Kernel.Image != "" {
moby.Kernel.Image = m1.Kernel.Image
}
if m1.Kernel.Cmdline != "" {
moby.Kernel.Cmdline = m1.Kernel.Cmdline
}
moby.Init = append(moby.Init, m1.Init...)
moby.Onboot = append(moby.Onboot, m1.Onboot...)
moby.Services = append(moby.Services, m1.Services...)
moby.Files = append(moby.Files, m1.Files...)
moby.Trust.Image = append(moby.Trust.Image, m1.Trust.Image...)
moby.Trust.Org = append(moby.Trust.Org, m1.Trust.Org...)

return moby
}

// NewImage validates an parses yaml or json for a MobyImage
func NewImage(config []byte) (MobyImage, error) {
log.Debugf("Reading label config: %s", string(config))
Expand Down

0 comments on commit 181c66d

Please sign in to comment.