Skip to content

Commit

Permalink
wip push
Browse files Browse the repository at this point in the history
Signed-off-by: Laura Brehm <[email protected]>
  • Loading branch information
laurazard committed Oct 25, 2024
1 parent 6447bbe commit 8584c2d
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 200 deletions.
75 changes: 68 additions & 7 deletions cli/command/image/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package image

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand All @@ -18,8 +19,10 @@ import (
"github.com/docker/cli/cli/streams"
"github.com/docker/docker/api/types/auxprogress"
"github.com/docker/docker/api/types/image"
imagetypes "github.com/docker/docker/api/types/image"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/registry"
"github.com/morikuni/aec"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -144,28 +147,86 @@ To push the complete multi-platform image, remove the --platform flag.
}

if opts.quiet {
err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(io.Discard), handleAux(dockerCli))
err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(io.Discard), handleAux(dockerCli.Out()))
if err == nil {
fmt.Fprintln(dockerCli.Out(), ref.String())
}
return err
}
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), handleAux(dockerCli))
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), handleAux(dockerCli.Out()))
}

var notes []string

func handleAux(dockerCli command.Cli) func(jm jsonmessage.JSONMessage) {
func handleAux(out *streams.Out) func(jm jsonmessage.JSONMessage) {
return func(jm jsonmessage.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()),
)
highlightColor := aec.NewBuilder(aec.GreenF, aec.Bold)

note := fmt.Sprintf("Not all multiplatform-content is present, pushing single-platform image.")
note += "\nNo platform selected, using host platform " + highlightColor.ANSI.Apply(stripped.SelectedManifest.Platform.OS+"/"+stripped.SelectedManifest.Platform.Architecture+"/"+stripped.SelectedManifest.Platform.Variant+"\n\n")
topNameColor := aec.NewBuilder(aec.BlueF, aec.Bold).ANSI
normalColor := aec.NewBuilder(aec.DefaultF).ANSI
untaggedColor := aec.NewBuilder(aec.Faint).ANSI
// Print images
columns := []imgColumn{
{
Title: "Image",
Align: alignLeft,
Width: 10,
},
{
Title: "ID",
Align: alignLeft,
Width: 12,
DetailsValue: func(d *rowDetails) string {
return stringid.TruncateID(d.ID)
},
},
{
Title: "Disk usage",
Align: alignRight,
Width: 10,
DetailsValue: func(d *rowDetails) string {
return d.DiskUsage
},
},
{
Title: "Content size",
Align: alignRight,
Width: 12,
DetailsValue: func(d *rowDetails) string {
return d.ContentSize
},
},
}

imageRows, spacing := buildTableRows([]imagetypes.Summary{*stripped.ImageSummary})
for i, child := range imageRows[0].Children {
if child.Platform == stripped.SelectedManifest.Platform.OS+"/"+stripped.SelectedManifest.Platform.Architecture+"/"+stripped.SelectedManifest.Platform.Variant {
imageRows[0].Children[i].Highlight = true
}
}

_, width := out.GetTtySize()
columns = formatColumnsForOutput(int(width), columns, imageRows)

table := imageTreeTable{
columns: columns,
headerColor: topNameColor,
indexNameColor: topNameColor,
untaggedColor: untaggedColor,
normalColor: normalColor,
spacing: spacing,
}

treeB := bytes.Buffer{}
table.printTable(&treeB, imageRows)
note += treeB.String()
notes = append(notes, note)
}

Expand Down
8 changes: 7 additions & 1 deletion vendor/github.com/docker/docker/api/swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/docker/docker/api/types/auxprogress/push.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions vendor/github.com/docker/docker/api/types/system/info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/docker/docker/api/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vendor/github.com/docker/docker/client/build_prune.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/docker/docker/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions vendor/github.com/docker/docker/client/container_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions vendor/github.com/docker/docker/client/container_prune.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/github.com/docker/docker/client/container_resize.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8584c2d

Please sign in to comment.