build: improve resource limits output and docs
Signed-off-by: Jiří Moravčík <jiri.moravcik@gmail.com>
This commit is contained in:
+1
-3
@@ -610,9 +610,7 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
|
|||||||
if len(keys) != 3 {
|
if len(keys) != 3 {
|
||||||
return nil, errors.Errorf("invalid key %s, resources requires name", parts[0])
|
return nil, errors.Errorf("invalid key %s, resources requires name", parts[0])
|
||||||
}
|
}
|
||||||
if len(parts) == 2 {
|
override.Value = parts[1]
|
||||||
override.Value = parts[1]
|
|
||||||
}
|
|
||||||
case "args":
|
case "args":
|
||||||
if len(keys) != 3 {
|
if len(keys) != 3 {
|
||||||
return nil, errors.Errorf("invalid key %s, args requires name", parts[0])
|
return nil, errors.Errorf("invalid key %s, args requires name", parts[0])
|
||||||
|
|||||||
@@ -585,10 +585,10 @@ workers0:
|
|||||||
fmt.Fprintf(tw, "Resource Limits:\t%s\n", out.Config.Ulimit)
|
fmt.Fprintf(tw, "Resource Limits:\t%s\n", out.Config.Ulimit)
|
||||||
}
|
}
|
||||||
if out.Config.Memory != "" {
|
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 != "" {
|
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 != "" {
|
if out.Config.CPUShares != "" {
|
||||||
fmt.Fprintf(tw, "CPU Shares:\t%s\n", out.Config.CPUShares)
|
fmt.Fprintf(tw, "CPU Shares:\t%s\n", out.Config.CPUShares)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/buildx/builder"
|
"github.com/docker/buildx/builder"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/go-units"
|
||||||
controlapi "github.com/moby/buildkit/api/services/control"
|
controlapi "github.com/moby/buildkit/api/services/control"
|
||||||
"github.com/moby/buildkit/frontend/dockerfile/dfgitutil"
|
"github.com/moby/buildkit/frontend/dockerfile/dfgitutil"
|
||||||
"github.com/pkg/errors"
|
"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)
|
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
|
type matchFunc func(*controlapi.BuildHistoryRecord) bool
|
||||||
|
|
||||||
func dockerFiltersToBuildkit(in []string) ([]string, []matchFunc, error) {
|
func dockerFiltersToBuildkit(in []string) ([]string, []matchFunc, error) {
|
||||||
|
|||||||
@@ -432,6 +432,7 @@ $ docker buildx bake --set *.platform=linux/arm64 # overrides platform for
|
|||||||
$ docker buildx bake --set foo*.no-cache # bypass caching only for targets starting with 'foo'
|
$ docker buildx bake --set foo*.no-cache # bypass caching only for targets starting with 'foo'
|
||||||
$ docker buildx bake --set target.platform+=linux/arm64 # appends 'linux/arm64' to the platform list
|
$ docker buildx bake --set target.platform+=linux/arm64 # appends 'linux/arm64' to the platform list
|
||||||
$ docker buildx bake --set target.contexts.bar=../bar # overrides 'bar' named context
|
$ docker buildx bake --set target.contexts.bar=../bar # overrides 'bar' named context
|
||||||
|
$ docker buildx bake --set target.resources.memory=2g # overrides memory resource limit
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
@@ -462,6 +463,7 @@ You can override the following fields:
|
|||||||
* `platform`
|
* `platform`
|
||||||
* `pull`
|
* `pull`
|
||||||
* `push`
|
* `push`
|
||||||
|
* `resources`
|
||||||
* `secrets`
|
* `secrets`
|
||||||
* `ssh`
|
* `ssh`
|
||||||
* `tags`
|
* `tags`
|
||||||
|
|||||||
Reference in New Issue
Block a user