Merge pull request #41 from tonistiigi/outputs

bake: add output key
pull/44/head
Tõnis Tiigi 6 years ago committed by GitHub
commit 2f668d555c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -132,6 +132,8 @@ func (c Config) setOverrides(v []string) error {
t.Tags = append(t.Tags, parts[1]) t.Tags = append(t.Tags, parts[1])
case "cache-from": case "cache-from":
t.CacheFrom = append(t.CacheFrom, parts[1]) t.CacheFrom = append(t.CacheFrom, parts[1])
case "cache-to":
t.CacheTo = append(t.CacheTo, parts[1])
case "target": case "target":
s := parts[1] s := parts[1]
t.Target = &s t.Target = &s
@ -141,6 +143,8 @@ func (c Config) setOverrides(v []string) error {
t.SSH = append(t.SSH, parts[1]) t.SSH = append(t.SSH, parts[1])
case "platform": case "platform":
t.Platforms = append(t.Platforms, parts[1]) t.Platforms = append(t.Platforms, parts[1])
case "output":
t.Outputs = append(t.Outputs, parts[1])
default: default:
return errors.Errorf("unknown key: %s", keys[1]) return errors.Errorf("unknown key: %s", keys[1])
} }
@ -216,18 +220,19 @@ type Group struct {
} }
type Target struct { type Target struct {
Inherits []string `json:"inherits,omitempty"` Inherits []string `json:"inherits,omitempty" hcl:"inherits,omitempty"`
Context *string `json:"context,omitempty"` Context *string `json:"context,omitempty" hcl:"context,omitempty"`
Dockerfile *string `json:"dockerfile,omitempty"` Dockerfile *string `json:"dockerfile,omitempty" hcl:"dockerfile,omitempty"`
Args map[string]string `json:"args,omitempty"` Args map[string]string `json:"args,omitempty" hcl:"args,omitempty"`
Labels map[string]string `json:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty" hcl:"labels,omitempty"`
Tags []string `json:"tags,omitempty"` Tags []string `json:"tags,omitempty" hcl:"tags,omitempty"`
CacheFrom []string `json:"cache-from,omitempty"` CacheFrom []string `json:"cache-from,omitempty" hcl:"cache-from,omitempty"`
CacheTo []string `json:"cache-to,omitempty"` CacheTo []string `json:"cache-to,omitempty" hcl:"cache-to,omitempty"`
Target *string `json:"target,omitempty"` Target *string `json:"target,omitempty" hcl:"target,omitempty"`
Secrets []string `json:"secret,omitempty"` Secrets []string `json:"secret,omitempty" hcl:"secret,omitempty"`
SSH []string `json:"ssh,omitempty"` SSH []string `json:"ssh,omitempty" hcl:"ssh,omitempty"`
Platforms []string `json:"platform,omitempty"` Platforms []string `json:"platforms,omitempty" hcl:"platforms,omitempty"`
Outputs []string `json:"output,omitempty" hcl:"output,omitempty"`
} }
func (t *Target) normalize() { func (t *Target) normalize() {
@ -235,6 +240,9 @@ func (t *Target) normalize() {
t.Secrets = removeDupes(t.Secrets) t.Secrets = removeDupes(t.Secrets)
t.SSH = removeDupes(t.SSH) t.SSH = removeDupes(t.SSH)
t.Platforms = removeDupes(t.Platforms) t.Platforms = removeDupes(t.Platforms)
t.CacheFrom = removeDupes(t.CacheFrom)
t.CacheTo = removeDupes(t.CacheTo)
t.Outputs = removeDupes(t.Outputs)
} }
func TargetsToBuildOpt(m map[string]Target) (map[string]build.Options, error) { func TargetsToBuildOpt(m map[string]Target) (map[string]build.Options, error) {
@ -312,6 +320,12 @@ func toBuildOpt(t Target) (*build.Options, error) {
} }
bo.CacheTo = cacheExports bo.CacheTo = cacheExports
outputs, err := build.ParseOutputs(t.Outputs)
if err != nil {
return nil, err
}
bo.Exports = outputs
return bo, nil return bo, nil
} }
@ -341,9 +355,6 @@ func merge(t1, t2 Target) Target {
if t2.Tags != nil { // no merge if t2.Tags != nil { // no merge
t1.Tags = t2.Tags t1.Tags = t2.Tags
} }
if t2.CacheFrom != nil {
t1.CacheFrom = t2.CacheFrom
}
if t2.Target != nil { if t2.Target != nil {
t1.Target = t2.Target t1.Target = t2.Target
} }
@ -356,12 +367,15 @@ func merge(t1, t2 Target) Target {
if t2.Platforms != nil { // no merge if t2.Platforms != nil { // no merge
t1.Platforms = t2.Platforms t1.Platforms = t2.Platforms
} }
if len(t2.CacheFrom) > 0 { // no merge if t2.CacheFrom != nil { // no merge
t1.CacheFrom = t2.CacheFrom t1.CacheFrom = append(t1.CacheFrom, t2.CacheFrom...)
} }
if len(t2.CacheTo) > 0 { // no merge if t2.CacheTo != nil { // no merge
t1.CacheTo = t2.CacheTo t1.CacheTo = t2.CacheTo
} }
if t2.Outputs != nil { // no merge
t1.Outputs = t2.Outputs
}
t1.Inherits = append(t1.Inherits, t2.Inherits...) t1.Inherits = append(t1.Inherits, t2.Inherits...)
return t1 return t1
} }

@ -21,29 +21,40 @@ func ParseOutputs(inp []string) ([]client.ExportEntry, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(fields) == 1 && fields[0] == s && !strings.HasPrefix(s, "type=") {
outs = append(outs, client.ExportEntry{
Type: client.ExporterLocal,
OutputDir: s,
})
continue
}
out := client.ExportEntry{ out := client.ExportEntry{
Attrs: map[string]string{}, Attrs: map[string]string{},
} }
for _, field := range fields { if len(fields) == 1 && fields[0] == s && !strings.HasPrefix(s, "type=") {
parts := strings.SplitN(field, "=", 2) if s != "-" {
if len(parts) != 2 { outs = append(outs, client.ExportEntry{
return nil, errors.Errorf("invalid value %s", field) Type: client.ExporterLocal,
OutputDir: s,
})
continue
} }
key := strings.TrimSpace(strings.ToLower(parts[0])) out = client.ExportEntry{
value := parts[1] Type: client.ExporterTar,
switch key { Attrs: map[string]string{
case "type": "dest": s,
out.Type = value },
default: }
out.Attrs[key] = value }
if out.Type == "" {
for _, field := range fields {
parts := strings.SplitN(field, "=", 2)
if len(parts) != 2 {
return nil, errors.Errorf("invalid value %s", field)
}
key := strings.TrimSpace(strings.ToLower(parts[0]))
value := parts[1]
switch key {
case "type":
out.Type = value
default:
out.Attrs[key] = value
}
} }
} }
if out.Type == "" { if out.Type == "" {
@ -59,7 +70,7 @@ func ParseOutputs(inp []string) ([]client.ExportEntry, error) {
} }
out.OutputDir = dest out.OutputDir = dest
delete(out.Attrs, "dest") delete(out.Attrs, "dest")
case client.ExporterOCI, client.ExporterDocker: case client.ExporterOCI, client.ExporterDocker, client.ExporterTar:
dest, ok := out.Attrs["dest"] dest, ok := out.Attrs["dest"]
if !ok { if !ok {
if out.Type != client.ExporterDocker { if out.Type != client.ExporterDocker {

Loading…
Cancel
Save