build: improve resource limits output and docs

Signed-off-by: Jiří Moravčík <jiri.moravcik@gmail.com>
This commit is contained in:
Jiří Moravčík
2026-06-11 11:18:35 +02:00
parent 89b455a9e3
commit 9b37d78c89
4 changed files with 17 additions and 5 deletions
+2 -2
View File
@@ -585,10 +585,10 @@ workers0:
fmt.Fprintf(tw, "Resource Limits:\t%s\n", out.Config.Ulimit)
}
if out.Config.Memory != "" {
fmt.Fprintf(tw, "Memory:\t%s\n", out.Config.Memory)
fmt.Fprintf(tw, "Memory:\t%s\n", humanizeBytes(out.Config.Memory))
}
if out.Config.MemorySwap != "" {
fmt.Fprintf(tw, "Memory Swap:\t%s\n", out.Config.MemorySwap)
fmt.Fprintf(tw, "Memory Swap:\t%s\n", humanizeBytes(out.Config.MemorySwap))
}
if out.Config.CPUShares != "" {
fmt.Fprintf(tw, "CPU Shares:\t%s\n", out.Config.CPUShares)
+12
View File
@@ -14,6 +14,7 @@ import (
"github.com/docker/buildx/builder"
"github.com/docker/cli/cli/command"
"github.com/docker/go-units"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/frontend/dockerfile/dfgitutil"
"github.com/pkg/errors"
@@ -192,6 +193,17 @@ func formatDuration(d time.Duration) string {
return fmt.Sprintf("%dm %2ds", int(d.Minutes()), int(d.Seconds())%60)
}
// humanizeBytes formats a raw byte-count string (as stored in the frontend
// attributes) into a human-readable size. Non-numeric values such as "-1"
// (unlimited swap) are returned unchanged.
func humanizeBytes(v string) string {
n, err := strconv.ParseInt(v, 10, 64)
if err != nil || n < 0 {
return v
}
return units.BytesSize(float64(n))
}
type matchFunc func(*controlapi.BuildHistoryRecord) bool
func dockerFiltersToBuildkit(in []string) ([]string, []matchFunc, error) {