mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-20 10:27:46 +08:00
Merge pull request #15 from tonistiigi/output-parsing
fix and improve outputs parsing
This commit is contained in:
commit
f0142b9e8b
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containerd/console"
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -20,9 +21,9 @@ 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 {
|
if len(fields) == 1 && fields[0] == s && !strings.HasPrefix(s, "type=") {
|
||||||
outs = append(outs, client.ExportEntry{
|
outs = append(outs, client.ExportEntry{
|
||||||
Type: "local",
|
Type: client.ExporterLocal,
|
||||||
OutputDir: s,
|
OutputDir: s,
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
@ -51,32 +52,44 @@ func ParseOutputs(inp []string) ([]client.ExportEntry, error) {
|
|||||||
|
|
||||||
// handle client side
|
// handle client side
|
||||||
switch out.Type {
|
switch out.Type {
|
||||||
case "local":
|
case client.ExporterLocal:
|
||||||
dest, ok := out.Attrs["dest"]
|
dest, ok := out.Attrs["dest"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("dest is required for local output")
|
return nil, errors.Errorf("dest is required for local output")
|
||||||
}
|
}
|
||||||
out.OutputDir = dest
|
out.OutputDir = dest
|
||||||
delete(out.Attrs, "dest")
|
delete(out.Attrs, "dest")
|
||||||
case "oci", "dest":
|
case client.ExporterOCI, client.ExporterDocker:
|
||||||
dest, ok := out.Attrs["dest"]
|
dest, ok := out.Attrs["dest"]
|
||||||
if !ok {
|
if !ok {
|
||||||
if out.Type != "docker" {
|
if out.Type != client.ExporterDocker {
|
||||||
return nil, errors.Errorf("dest is required for %s output", out.Type)
|
dest = "-"
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if dest == "-" {
|
|
||||||
out.Output = os.Stdout
|
|
||||||
} else {
|
} else {
|
||||||
f, err := os.Open(dest)
|
return nil, errors.Errorf("loading to docker currently not implemented, specify dest file or -")
|
||||||
if err != nil {
|
|
||||||
out.Output = f
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete(out.Attrs, "dest")
|
|
||||||
}
|
}
|
||||||
|
if dest == "-" {
|
||||||
|
if _, err := console.ConsoleFromFile(os.Stdout); err == nil {
|
||||||
|
return nil, errors.Errorf("output file is required for %s exporter. refusing to write to console", out.Type)
|
||||||
|
}
|
||||||
|
out.Output = os.Stdout
|
||||||
|
} else if dest != "" {
|
||||||
|
fi, err := os.Stat(dest)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return nil, errors.Wrapf(err, "invalid destination file: %s", dest)
|
||||||
|
}
|
||||||
|
if err == nil && fi.IsDir() {
|
||||||
|
return nil, errors.Errorf("destination file %s is a directory", dest)
|
||||||
|
}
|
||||||
|
f, err := os.Create(dest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Errorf("failed to open %s", err)
|
||||||
|
}
|
||||||
|
out.Output = f
|
||||||
|
}
|
||||||
|
delete(out.Attrs, "dest")
|
||||||
case "registry":
|
case "registry":
|
||||||
out.Type = "iamge"
|
out.Type = client.ExporterImage
|
||||||
out.Attrs["push"] = "true"
|
out.Attrs["push"] = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user