@@ -25,6 +25,10 @@ import (
25
25
"strings"
26
26
"sync"
27
27
28
+ "github.com/docker/buildx/builder"
29
+ "github.com/docker/buildx/util/imagetools"
30
+ "github.com/docker/cli/cli/command"
31
+
28
32
"github.com/distribution/distribution/v3/uuid"
29
33
moby "github.com/docker/docker/api/types"
30
34
containerType "github.com/docker/docker/api/types/container"
@@ -52,6 +56,7 @@ type DryRunKey struct{}
52
56
type DryRunClient struct {
53
57
apiClient client.APIClient
54
58
execs sync.Map
59
+ resolver * imagetools.Resolver
55
60
}
56
61
57
62
type execDetails struct {
@@ -60,11 +65,20 @@ type execDetails struct {
60
65
}
61
66
62
67
// 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
+ }
64
77
return & DryRunClient {
65
78
apiClient : apiClient ,
66
79
execs : sync.Map {},
67
- }
80
+ resolver : imagetools .New (configFile ),
81
+ }, nil
68
82
}
69
83
70
84
// 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
129
143
return moby.ImageBuildResponse {}, ErrNotImplemented
130
144
}
131
145
146
+ func (d * DryRunClient ) ImageInspectWithRaw (ctx context.Context , imageName string ) (moby.ImageInspect , []byte , error ) {
147
+ return moby.ImageInspect {ID : "dryRunId" }, nil , nil
148
+ }
149
+
132
150
func (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
134
156
}
135
157
136
158
func (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
304
326
return d .apiClient .ImageImport (ctx , source , ref , options )
305
327
}
306
328
307
- func (d * DryRunClient ) ImageInspectWithRaw (ctx context.Context , imageName string ) (moby.ImageInspect , []byte , error ) {
308
- return d .apiClient .ImageInspectWithRaw (ctx , imageName )
309
- }
310
-
311
329
func (d * DryRunClient ) ImageList (ctx context.Context , options moby.ImageListOptions ) ([]moby.ImageSummary , error ) {
312
330
return d .apiClient .ImageList (ctx , options )
313
331
}
0 commit comments