mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:37:46 +08:00
Move printing to stdout up to the command itself
Signed-off-by: Andy Caldwell <andrew.caldwell@metaswitch.com>
This commit is contained in:
parent
3ab0b6953a
commit
ef3e46fd62
@ -54,7 +54,6 @@ type Options struct {
|
|||||||
BuildArgs map[string]string
|
BuildArgs map[string]string
|
||||||
Pull bool
|
Pull bool
|
||||||
ImageIDFile string
|
ImageIDFile string
|
||||||
Quiet bool
|
|
||||||
ExtraHosts []string
|
ExtraHosts []string
|
||||||
NetworkMode string
|
NetworkMode string
|
||||||
|
|
||||||
@ -685,9 +684,6 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
respMu.Unlock()
|
respMu.Unlock()
|
||||||
if len(res) == 1 {
|
if len(res) == 1 {
|
||||||
digest := res[0].ExporterResponse["containerimage.digest"]
|
digest := res[0].ExporterResponse["containerimage.digest"]
|
||||||
if opt.Quiet {
|
|
||||||
fmt.Println(digest)
|
|
||||||
}
|
|
||||||
if opt.ImageIDFile != "" {
|
if opt.ImageIDFile != "" {
|
||||||
return ioutil.WriteFile(opt.ImageIDFile, []byte(digest), 0644)
|
return ioutil.WriteFile(opt.ImageIDFile, []byte(digest), 0644)
|
||||||
}
|
}
|
||||||
@ -718,9 +714,6 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if opt.Quiet {
|
|
||||||
fmt.Println(desc.Digest)
|
|
||||||
}
|
|
||||||
if opt.ImageIDFile != "" {
|
if opt.ImageIDFile != "" {
|
||||||
return ioutil.WriteFile(opt.ImageIDFile, []byte(desc.Digest), 0644)
|
return ioutil.WriteFile(opt.ImageIDFile, []byte(desc.Digest), 0644)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -122,7 +123,6 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) {
|
|||||||
NoCache: noCache,
|
NoCache: noCache,
|
||||||
Target: in.target,
|
Target: in.target,
|
||||||
ImageIDFile: in.imageIDFile,
|
ImageIDFile: in.imageIDFile,
|
||||||
Quiet: in.quiet,
|
|
||||||
ExtraHosts: in.extraHosts,
|
ExtraHosts: in.extraHosts,
|
||||||
NetworkMode: in.networkMode,
|
NetworkMode: in.networkMode,
|
||||||
}
|
}
|
||||||
@ -216,15 +216,23 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) {
|
|||||||
contextPathHash = in.contextPath
|
contextPathHash = in.contextPath
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildTargets(ctx, dockerCli, map[string]build.Options{defaultTargetName: opts}, in.progress, contextPathHash, in.builder, in.metadataFile)
|
imageID, err := buildTargets(ctx, dockerCli, map[string]build.Options{defaultTargetName: opts}, in.progress, contextPathHash, in.builder, in.metadataFile)
|
||||||
}
|
|
||||||
|
|
||||||
func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]build.Options, progressMode, contextPathHash, instance string, metadataFile string) error {
|
|
||||||
dis, err := getInstanceOrDefault(ctx, dockerCli, instance, contextPathHash)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if in.quiet {
|
||||||
|
fmt.Println(imageID)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]build.Options, progressMode, contextPathHash, instance string, metadataFile string) (imageID string, err error) {
|
||||||
|
dis, err := getInstanceOrDefault(ctx, dockerCli, instance, contextPathHash)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
ctx2, cancel := context.WithCancel(context.TODO())
|
ctx2, cancel := context.WithCancel(context.TODO())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -236,20 +244,20 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]bu
|
|||||||
err = err1
|
err = err1
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(metadataFile) > 0 && resp != nil {
|
if len(metadataFile) > 0 && resp != nil {
|
||||||
mdatab, err := json.MarshalIndent(resp[defaultTargetName].ExporterResponse, "", " ")
|
mdatab, err := json.MarshalIndent(resp[defaultTargetName].ExporterResponse, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
if err := ioutils.AtomicWriteFile(metadataFile, mdatab, 0644); err != nil {
|
if err := ioutils.AtomicWriteFile(metadataFile, mdatab, 0644); err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return resp[defaultTargetName].ExporterResponse["containerimage.digest"], err
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user