From bdb630fb894529589bcccb1dffa34256be0d8fba Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 10 Feb 2026 13:48:51 +0100 Subject: [PATCH] pkg/compose: format layer push progress Format layer progress details with minimal efforts as new UI does not render individual layers. Signed-off-by: Sebastiaan van Stijn --- pkg/compose/push.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/compose/push.go b/pkg/compose/push.go index b26d93f0b..58762dd51 100644 --- a/pkg/compose/push.go +++ b/pkg/compose/push.go @@ -27,6 +27,7 @@ import ( "github.com/compose-spec/compose-go/v2/types" "github.com/distribution/reference" + "github.com/docker/go-units" "github.com/moby/moby/api/types/jsonstream" "github.com/moby/moby/client" "golang.org/x/sync/errgroup" @@ -149,8 +150,7 @@ func toPushProgressEvent(prefix string, jm jsonstream.Message, events api.EventP text = jm.Error.Message } if jm.Progress != nil { - // FIXME(thaJeztah): what's the replacement for Progress.String()? - // text = jm.Progress.String() + text = progressText(jm.Progress) if jm.Progress.Total != 0 { current = jm.Progress.Current total = jm.Progress.Total @@ -183,3 +183,27 @@ func isDone(msg jsonstream.Message) bool { return false } } + +// progressText is a minimal variant of [jsonmessage.JSONProgress.String()] +// +// [jsonmessage.JSONProgress.String()]: https://github.com/moby/moby/blob/v28.5.2/pkg/jsonmessage/jsonmessage.go#L54-L117 +func progressText(p *jsonstream.Progress) string { + switch { + case p.Current <= 0 && p.Total <= 0: + return "" + case p.Units == "": // no units, use bytes + current := units.HumanSize(float64(p.Current)) + if p.Total <= 0 || p.Total > p.Current { + // remove total display if the reported current is wonky. + return fmt.Sprintf("%8v", current) + } + total := units.HumanSize(float64(p.Total)) + return fmt.Sprintf("%8v/%v", current, total) + default: + if p.Total <= 0 || p.Total > p.Current { + // remove total display if the reported current is wonky. + return fmt.Sprintf("%d %s", p.Current, p.Units) + } + return fmt.Sprintf("%d/%d %s", p.Current, p.Total, p.Units) + } +}