1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

builder: enable shm-size and ulimit for buildkit

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-03-17 12:04:13 +01:00
parent aadb3bf766
commit b899db6423
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7

View file

@ -20,6 +20,7 @@ import (
"github.com/docker/docker/libnetwork"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/go-units"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/control"
@ -319,6 +320,17 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
}
frontendAttrs["add-hosts"] = extraHosts
if opt.Options.ShmSize > 0 {
frontendAttrs["shm-size"] = strconv.FormatInt(opt.Options.ShmSize, 10)
}
ulimits, err := toBuildkitUlimits(opt.Options.Ulimits)
if err != nil {
return nil, err
} else if len(ulimits) > 0 {
frontendAttrs["ulimit"] = ulimits
}
exporterName := ""
exporterAttrs := map[string]string{}
@ -558,6 +570,18 @@ func toBuildkitExtraHosts(inp []string) (string, error) {
return strings.Join(hosts, ","), nil
}
// toBuildkitUlimits converts ulimits from docker type=soft:hard format to buildkit's csv format
func toBuildkitUlimits(inp []*units.Ulimit) (string, error) {
if len(inp) == 0 {
return "", nil
}
ulimits := make([]string, 0, len(inp))
for _, ulimit := range inp {
ulimits = append(ulimits, ulimit.String())
}
return strings.Join(ulimits, ","), nil
}
func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, error) {
var until time.Duration
untilValues := opts.Filters.Get("until") // canonical