@@ -25,6 +25,10 @@ import (
2525 "strings"
2626 "sync"
2727
28+ "github.com/docker/buildx/builder"
29+ "github.com/docker/buildx/util/imagetools"
30+ "github.com/docker/cli/cli/command"
31+
2832 "github.com/distribution/distribution/v3/uuid"
2933 moby "github.com/docker/docker/api/types"
3034 containerType "github.com/docker/docker/api/types/container"
@@ -52,6 +56,7 @@ type DryRunKey struct{}
5256type DryRunClient struct {
5357 apiClient client.APIClient
5458 execs sync.Map
59+ resolver * imagetools.Resolver
5560}
5661
5762type execDetails struct {
@@ -60,11 +65,20 @@ type execDetails struct {
6065}
6166
6267// NewDryRunClient produces a DryRunClient
63- func NewDryRunClient (apiClient client.APIClient ) * DryRunClient {
68+ func NewDryRunClient (apiClient client.APIClient , cli * command.DockerCli ) (* DryRunClient , error ) {
69+ b , err := builder .New (cli , builder .WithSkippedValidation ())
70+ if err != nil {
71+ return nil , err
72+ }
73+ configFile , err := b .ImageOpt ()
74+ if err != nil {
75+ return nil , err
76+ }
6477 return & DryRunClient {
6578 apiClient : apiClient ,
6679 execs : sync.Map {},
67- }
80+ resolver : imagetools .New (configFile ),
81+ }, nil
6882}
6983
7084// All methods and functions which need to be overridden for dry run.
@@ -129,8 +143,16 @@ func (d *DryRunClient) ImageBuild(ctx context.Context, reader io.Reader, options
129143 return moby.ImageBuildResponse {}, ErrNotImplemented
130144}
131145
146+ func (d * DryRunClient ) ImageInspectWithRaw (ctx context.Context , imageName string ) (moby.ImageInspect , []byte , error ) {
147+ return moby.ImageInspect {ID : "dryRunId" }, nil , nil
148+ }
149+
132150func (d * DryRunClient ) ImagePull (ctx context.Context , ref string , options moby.ImagePullOptions ) (io.ReadCloser , error ) {
133- return nil , ErrNotImplemented
151+ if _ , _ , err := d .resolver .Resolve (ctx , ref ); err != nil {
152+ return nil , err
153+ }
154+ rc := io .NopCloser (strings .NewReader ("" ))
155+ return rc , nil
134156}
135157
136158func (d * DryRunClient ) ImagePush (ctx context.Context , ref string , options moby.ImagePushOptions ) (io.ReadCloser , error ) {
@@ -304,10 +326,6 @@ func (d *DryRunClient) ImageImport(ctx context.Context, source moby.ImageImportS
304326 return d .apiClient .ImageImport (ctx , source , ref , options )
305327}
306328
307- func (d * DryRunClient ) ImageInspectWithRaw (ctx context.Context , imageName string ) (moby.ImageInspect , []byte , error ) {
308- return d .apiClient .ImageInspectWithRaw (ctx , imageName )
309- }
310-
311329func (d * DryRunClient ) ImageList (ctx context.Context , options moby.ImageListOptions ) ([]moby.ImageSummary , error ) {
312330 return d .apiClient .ImageList (ctx , options )
313331}
0 commit comments