Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ linters:
alias:
- pkg: "github.com/containerd/errdefs"
alias: "cerrdefs"
- pkg: "github.com/docker/docker/client"
- pkg: "github.com/moby/moby/client"
alias: "dockerclient"
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
alias: "ocispecs"
Expand Down
12 changes: 7 additions & 5 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"github.com/docker/buildx/util/resolver"
"github.com/docker/buildx/util/waitmap"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
Expand All @@ -43,6 +41,8 @@ import (
spb "github.com/moby/buildkit/sourcepolicy/pb"
"github.com/moby/buildkit/util/progress/progresswriter"
"github.com/moby/buildkit/util/tracing"
"github.com/moby/moby/api/types/jsonstream"
dockerclient "github.com/moby/moby/client"
"github.com/opencontainers/go-digest"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -802,7 +802,7 @@ func pushWithMoby(ctx context.Context, d *driver.DriverHandle, name string, l pr
return err
}

rc, err := api.ImagePush(ctx, name, image.PushOptions{
rc, err := api.ImagePush(ctx, name, dockerclient.ImagePushOptions{
RegistryAuth: creds,
})
if err != nil {
Expand All @@ -824,7 +824,7 @@ func pushWithMoby(ctx context.Context, d *driver.DriverHandle, name string, l pr
dec := json.NewDecoder(rc)
var parsedError error
for {
var jm jsonmessage.JSONMessage
var jm jsonstream.Message
if err := dec.Decode(&jm); err != nil {
if parsedError != nil {
return parsedError
Expand Down Expand Up @@ -888,7 +888,9 @@ func remoteDigestWithMoby(ctx context.Context, d *driver.DriverHandle, name stri
if len(img.RepoDigests) == 0 {
return "", nil
}
remoteImage, err := api.DistributionInspect(ctx, name, creds)
remoteImage, err := api.DistributionInspect(ctx, name, dockerclient.DistributionInspectOptions{
EncodedRegistryAuth: creds,
})
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
dopts "github.com/docker/cli/opts"
"github.com/google/shlex"
"github.com/moby/buildkit/util/progress/progressui"
dockerclient "github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/tonistiigi/go-csvvalue"
Expand Down Expand Up @@ -247,7 +248,7 @@ func (b *Builder) Factory(ctx context.Context, dialMeta map[string][]string) (_
}
// check if endpoint is healthy is needed to determine the driver type.
// if this fails then can't continue with driver selection.
if _, err = dockerapi.Ping(ctx); err != nil {
if _, err = dockerapi.Ping(ctx, dockerclient.PingOptions{}); err != nil {
return
}
b.driverFactory.Factory, err = driver.GetDefaultFactory(ctx, ep, dockerapi, false, dialMeta)
Expand Down
2 changes: 1 addition & 1 deletion commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
dockeropts "github.com/docker/cli/opts"
"github.com/docker/docker/api/types/versions"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/frontend/subrequests"
Expand All @@ -49,6 +48,7 @@ import (
sourcepolicy "github.com/moby/buildkit/sourcepolicy/pb"
"github.com/moby/buildkit/util/grpcerrors"
"github.com/moby/buildkit/util/progress/progressui"
"github.com/moby/moby/client/pkg/versions"
"github.com/moby/sys/atomicwriter"
"github.com/morikuni/aec"
"github.com/pkg/errors"
Expand Down
2 changes: 1 addition & 1 deletion commands/diskusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func runDiskUsage(ctx context.Context, dockerCli command.Cli, opts duOptions) er
}

defer func() {
if (fctx.Format != duDefaultTableFormat && fctx.Format != duDefaultPrettyTemplate) || fctx.Format.IsJSON() || opts.filter.Value().Len() > 0 {
if (fctx.Format != duDefaultTableFormat && fctx.Format != duDefaultPrettyTemplate) || fctx.Format.IsJSON() || len(opts.filter.Value()) > 0 {
return
}
printSummary(dockerCli.Out(), out)
Expand Down
38 changes: 20 additions & 18 deletions commands/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"fmt"
"io"
"maps"
"os"
"slices"
"strings"
"text/tabwriter"
"time"
Expand All @@ -14,12 +16,12 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/filters"
"github.com/docker/go-units"
"github.com/moby/buildkit/client"
gateway "github.com/moby/buildkit/frontend/gateway/client"
pb "github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/apicaps"
dclient "github.com/moby/moby/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
Expand All @@ -42,9 +44,7 @@ const (
)

func runPrune(ctx context.Context, dockerCli command.Cli, opts pruneOptions) error {
pruneFilters := opts.filter.Value()
pruneFilters = command.PruneFilters(dockerCli, pruneFilters)

pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value())
pi, err := toBuildkitPruneInfo(pruneFilters)
if err != nil {
return err
Expand Down Expand Up @@ -189,20 +189,22 @@ func pruneCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
return cmd
}

func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
var until time.Duration
untilValues := f.Get("until") // canonical
unusedForValues := f.Get("unused-for") // deprecated synonym for "until" filter
// getFilter returns the list of values associated with the key
func getFilter(f dclient.Filters, key string) []string {
return slices.Collect(maps.Keys(f[key]))
}

if len(untilValues) > 0 && len(unusedForValues) > 0 {
return nil, errors.Errorf("conflicting filters %q and %q", "until", "unused-for")
func toBuildkitPruneInfo(pruneFilters dclient.Filters) (*client.PruneInfo, error) {
var until time.Duration
if len(pruneFilters["until"]) > 0 && len(pruneFilters["unused-for"]) > 0 {
return nil, errors.New(`conflicting filters "until" and "unused-for"`)
}
untilKey := "until"
if len(unusedForValues) > 0 {
untilKey = "unused-for"
if len(pruneFilters["unused-for"]) > 0 {
untilKey = "unused-for" // deprecated synonym for "until" filter
}
untilValues = append(untilValues, unusedForValues...)

untilValues := getFilter(pruneFilters, untilKey)
switch len(untilValues) {
case 0:
// nothing to do
Expand All @@ -213,16 +215,16 @@ func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
return nil, errors.Wrapf(err, "%q filter expects a duration (e.g., '24h')", untilKey)
}
default:
return nil, errors.Errorf("filters expect only one value")
return nil, errors.Errorf("%q filter expects only one value", untilKey)
}

filters := make([]string, 0, f.Len())
for _, filterKey := range f.Keys() {
filters := make([]string, 0, len(pruneFilters))
for filterKey := range pruneFilters {
if filterKey == untilKey {
continue
}

values := f.Get(filterKey)
values := getFilter(pruneFilters, filterKey)
switch len(values) {
case 0:
filters = append(filters, filterKey)
Expand All @@ -235,7 +237,7 @@ func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
filters = append(filters, filterKey+"=="+values[0])
}
default:
return nil, errors.Errorf("filters expect only one value")
return nil, errors.Errorf("%q filter expects only one value", filterKey)
}
}
return &client.PruneInfo{
Expand Down
Loading
Loading