mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
Allow specification of multiple yaml files for a single build
Each section will be appended in order of the CLI, other then kernel where last specified one wins. This is useful if you eg want to have a base version for (say) AWS and GCP and then add your own image on top. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
058ce768f4
commit
54e58f2808
@ -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 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))
|
||||
}
|
||||
}
|
||||
|
||||
m, err := NewConfig(config)
|
||||
if err != nil {
|
||||
log.Fatalf("Invalid config: %v", err)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user