Skip to content

Commit

Permalink
builder: add worker gc policies and labels
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Nov 30, 2022
1 parent 94e1113 commit 45de5d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
9 changes: 8 additions & 1 deletion builder/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/docker/buildx/util/dockerutil"
"github.com/docker/buildx/util/imagetools"
"github.com/docker/buildx/util/platformutil"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/util/grpcerrors"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand All @@ -23,6 +24,8 @@ type Driver struct {
Driver driver.Driver
Info *driver.Info
Platforms []ocispecs.Platform
GCPolicy []client.PruneInfo
Labels map[string]string
ImageOpt imagetools.Opt
ProxyConfig map[string]string
Version string
Expand Down Expand Up @@ -206,8 +209,12 @@ func (d *Driver) loadData(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "listing workers")
}
for _, w := range workers {
for idx, w := range workers {
d.Platforms = append(d.Platforms, w.Platforms...)
if idx == 0 {
d.GCPolicy = w.GCPolicy
d.Labels = w.Labels
}
}
d.Platforms = platformutil.Dedupe(d.Platforms)
inf, err := driverClient.Info(ctx)
Expand Down
35 changes: 34 additions & 1 deletion commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"sort"
"strings"
"text/tabwriter"
"time"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/docker/buildx/util/platformutil"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/go-units"
"github.com/moby/buildkit/util/appcontext"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -84,7 +86,27 @@ func runInspect(dockerCli command.Cli, in inspectOptions) error {
fmt.Fprintf(w, "Flags:\t%s\n", strings.Join(n.Flags, " "))
}
if drivers[i].Version != "" {
fmt.Fprintf(w, "Buildkit:\t%s\n", drivers[i].Version)
fmt.Fprintf(w, "BuildKit:\t%s\n", drivers[i].Version)
}
if len(drivers[i].Labels) > 0 {
fmt.Fprintf(w, "Labels:\n")
for _, k := range sortedKeys(drivers[i].Labels) {
v := drivers[i].Labels[k]
fmt.Fprintf(w, "\t%s:\t%s\n", k, v)
}
}
for ri, rule := range drivers[i].GCPolicy {
fmt.Fprintf(w, "GC Policy rule#%d:\n", ri)
fmt.Fprintf(w, "\tAll:\t%v\n", rule.All)
if len(rule.Filter) > 0 {
fmt.Fprintf(w, "\tFilters:\t%s\n", strings.Join(rule.Filter, " "))
}
if rule.KeepDuration > 0 {
fmt.Fprintf(w, "\tKeep Duration:\t%v\n", rule.KeepDuration.String())
}
if rule.KeepBytes > 0 {
fmt.Fprintf(w, "\tKeep Bytes:\t%s\n", units.BytesSize(float64(rule.KeepBytes)))
}
}
fmt.Fprintf(w, "Platforms:\t%s\n", strings.Join(platformutil.FormatInGroups(n.Platforms, drivers[i].Platforms), ", "))
}
Expand Down Expand Up @@ -117,3 +139,14 @@ func inspectCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {

return cmd
}

func sortedKeys(m map[string]string) []string {
s := make([]string, len(m))
i := 0
for k := range m {
s[i] = k
i++
}
sort.Strings(s)
return s
}

0 comments on commit 45de5d4

Please sign in to comment.