Skip to content
Merged
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
13 changes: 6 additions & 7 deletions cli/command/image/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ To push the complete multi-platform image, remove the --platform flag.
return err
}

var notes []string
defer func() {
_ = responseBody.Close()
for _, note := range notes {
Expand All @@ -131,18 +132,16 @@ 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(out)))
err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux(&notes, out)))
if err == nil {
_, _ = fmt.Fprintln(dockerCli.Out(), ref.String())
}
return err
}
return jsonstream.Display(ctx, responseBody, dockerCli.Out(), jsonstream.WithAuxCallback(handleAux(out)))
return jsonstream.Display(ctx, responseBody, dockerCli.Out(), jsonstream.WithAuxCallback(handleAux(&notes, out)))
}

var notes []string

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

Expand All @@ -153,7 +152,7 @@ func handleAux(out tui.Output) func(jm jsonstream.JSONMessage) {
out.Color(aec.RedF).Apply(stripped.OriginalIndex.Digest.String()),
out.Color(aec.GreenF).Apply(stripped.SelectedManifest.Digest.String()),
)
notes = append(notes, note)
*notes = append(*notes, note)
}

var missing auxprogress.ContentMissing
Expand All @@ -166,7 +165,7 @@ func handleAux(out tui.Output) func(jm jsonstream.JSONMessage) {
Make sure you have all the referenced content and try again.

You can also push only a single platform specific manifest directly by specifying the platform you want to push with the --platform flag.`
notes = append(notes, note)
*notes = append(*notes, note)
}
}
}
5 changes: 1 addition & 4 deletions cli/command/image/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package image

import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
Expand Down Expand Up @@ -109,10 +108,8 @@ func TestRunPushRespectsNoColorForAuxNotes(t *testing.T) {
},
})
cli.Out().SetIsTerminal(true)
notes = nil
t.Cleanup(func() { notes = nil })

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

out := cli.OutBuffer().String()
Expand Down
Loading