Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cli/command/image/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,27 @@ To push the complete multi-platform image, remove the --platform flag.
}()

if opts.quiet {
err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux()))
err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux(out)))
if err == nil {
_, _ = fmt.Fprintln(dockerCli.Out(), ref.String())
}
return err
}
return jsonstream.Display(ctx, responseBody, dockerCli.Out(), jsonstream.WithAuxCallback(handleAux()))
return jsonstream.Display(ctx, responseBody, dockerCli.Out(), jsonstream.WithAuxCallback(handleAux(out)))
}

var notes []string

func handleAux() func(jm jsonstream.JSONMessage) {
func handleAux(out tui.Output) func(jm jsonstream.JSONMessage) {
return func(jm jsonstream.JSONMessage) {
b := []byte(*jm.Aux)

var stripped auxprogress.ManifestPushedInsteadOfIndex
err := json.Unmarshal(b, &stripped)
if err == nil && stripped.ManifestPushedInsteadOfIndex {
note := fmt.Sprintf("Not all multiplatform-content is present and only the available single-platform image was pushed\n%s -> %s",
aec.RedF.Apply(stripped.OriginalIndex.Digest.String()),
aec.GreenF.Apply(stripped.SelectedManifest.Digest.String()),
out.Color(aec.RedF).Apply(stripped.OriginalIndex.Digest.String()),
out.Color(aec.GreenF).Apply(stripped.SelectedManifest.Digest.String()),
)
notes = append(notes, note)
}
Expand Down
33 changes: 33 additions & 0 deletions cli/command/image/push_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package image

import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"strings"
"testing"

"github.com/docker/cli/internal/test"
"github.com/moby/moby/api/types/auxprogress"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
)

Expand Down Expand Up @@ -86,3 +92,30 @@ func TestNewPushCommandSuccess(t *testing.T) {
})
}
}

func TestRunPushRespectsNoColorForAuxNotes(t *testing.T) {
t.Setenv("NO_COLOR", "1")
cli := test.NewFakeCli(&fakeClient{
imagePushFunc: func(ref string, options client.ImagePushOptions) (client.ImagePushResponse, error) {
aux, err := json.Marshal(auxprogress.ManifestPushedInsteadOfIndex{
ManifestPushedInsteadOfIndex: true,
OriginalIndex: ocispec.Descriptor{Digest: "sha256:1111111111111111111111111111111111111111111111111111111111111111"},
SelectedManifest: ocispec.Descriptor{Digest: "sha256:2222222222222222222222222222222222222222222222222222222222222222"},
})
assert.NilError(t, err)
line := append([]byte(`{"aux":`), aux...)
line = append(line, '}', '\n')
return fakeStreamResult{ReadCloser: io.NopCloser(bytes.NewReader(line))}, nil
},
})
cli.Out().SetIsTerminal(true)
notes = nil
t.Cleanup(func() { notes = nil })

err := runPush(context.Background(), cli, pushOptions{remote: "image:tag"})
assert.NilError(t, err)

out := cli.OutBuffer().String()
assert.Assert(t, strings.Contains(out, "sha256:1111111111111111111111111111111111111111111111111111111111111111 -> sha256:2222222222222222222222222222222222222222222222222222222222222222"))
assert.Assert(t, !strings.Contains(out, "\x1b["), "output should not contain ANSI escape codes, output: %s", out)
}