Skip to content

Commit 34c1952

Browse files
authored
Merge pull request #2604 from crazy-max/v0.16.1_cherry-picks
[v0.16] cherry-picks for v0.16.1
2 parents 10c9ff9 + dd3bb69 commit 34c1952

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

commands/bake.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
146146
printer, err = progress.NewPrinter(ctx2, os.Stderr, progressMode,
147147
progress.WithDesc(progressTextDesc, progressConsoleDesc),
148148
progress.WithOnClose(func() {
149-
printWarnings(os.Stderr, printer.Warnings(), progressMode)
149+
if p := printer; p != nil {
150+
printWarnings(os.Stderr, p.Warnings(), progressMode)
151+
}
150152
}),
151153
)
152154
if err != nil {

commands/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ func printWarnings(w io.Writer, warnings []client.VertexWarning, mode progressui
835835
fmt.Fprintf(sb, "%d warnings found", len(warnings))
836836
}
837837
if logrus.GetLevel() < logrus.DebugLevel {
838-
fmt.Fprintf(sb, " (use --debug to expand)")
838+
fmt.Fprintf(sb, " (use docker --debug to expand)")
839839
}
840840
fmt.Fprintf(sb, ":\n")
841841
fmt.Fprint(w, aec.Apply(sb.String(), aec.YellowF))

tests/bake.go

+46
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"os"
@@ -9,6 +10,7 @@ import (
910
"testing"
1011

1112
"github.com/containerd/continuity/fs/fstest"
13+
"github.com/docker/buildx/bake"
1214
"github.com/docker/buildx/util/gitutil"
1315
"github.com/moby/buildkit/client"
1416
"github.com/moby/buildkit/identity"
@@ -28,6 +30,7 @@ func bakeCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
2830
}
2931

3032
var bakeTests = []func(t *testing.T, sb integration.Sandbox){
33+
testBakePrint,
3134
testBakeLocal,
3235
testBakeLocalMulti,
3336
testBakeRemote,
@@ -55,6 +58,49 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){
5558
testBakeCallCheckFlag,
5659
}
5760

61+
func testBakePrint(t *testing.T, sb integration.Sandbox) {
62+
dockerfile := []byte(`
63+
FROM busybox
64+
ARG HELLO
65+
RUN echo "Hello ${HELLO}"
66+
`)
67+
bakefile := []byte(`
68+
target "build" {
69+
args = {
70+
HELLO = "foo"
71+
}
72+
}
73+
`)
74+
dir := tmpdir(
75+
t,
76+
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
77+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
78+
)
79+
80+
cmd := buildxCmd(sb, withDir(dir), withArgs("bake", "--print", "build"))
81+
stdout := bytes.Buffer{}
82+
stderr := bytes.Buffer{}
83+
cmd.Stdout = &stdout
84+
cmd.Stderr = &stderr
85+
require.NoError(t, cmd.Run(), stdout.String(), stderr.String())
86+
87+
var def struct {
88+
Group map[string]*bake.Group `json:"group,omitempty"`
89+
Target map[string]*bake.Target `json:"target"`
90+
}
91+
require.NoError(t, json.Unmarshal(stdout.Bytes(), &def))
92+
93+
require.Len(t, def.Group, 1)
94+
require.Contains(t, def.Group, "default")
95+
96+
require.Equal(t, []string{"build"}, def.Group["default"].Targets)
97+
require.Len(t, def.Target, 1)
98+
require.Contains(t, def.Target, "build")
99+
require.Equal(t, ".", *def.Target["build"].Context)
100+
require.Equal(t, "Dockerfile", *def.Target["build"].Dockerfile)
101+
require.Equal(t, map[string]*string{"HELLO": ptrstr("foo")}, def.Target["build"].Args)
102+
}
103+
58104
func testBakeLocal(t *testing.T, sb integration.Sandbox) {
59105
dockerfile := []byte(`
60106
FROM scratch

tests/integration.go

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"os/exec"
66
"path/filepath"
7+
"reflect"
78
"strconv"
89
"strings"
910
"sync"
@@ -208,3 +209,12 @@ func skipNoCompatBuildKit(t *testing.T, sb integration.Sandbox, constraint strin
208209
t.Skipf("buildkit version %s does not match %s constraint (%s)", buildkitVersion(t, sb), constraint, msg)
209210
}
210211
}
212+
213+
func ptrstr(s interface{}) *string {
214+
var n *string
215+
if reflect.ValueOf(s).Kind() == reflect.String {
216+
ss := s.(string)
217+
n = &ss
218+
}
219+
return n
220+
}

0 commit comments

Comments
 (0)