mirror of
https://github.com/docker/compose.git
synced 2026-08-04 14:47:40 +00:00
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 <github@gone.nl>
This commit is contained in:
parent
3697b128a1
commit
bdb630fb89
1 changed files with 26 additions and 2 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue