@@ -58,9 +58,10 @@ type DryRunKey struct{}
58
58
59
59
// DryRunClient implements APIClient by delegating to implementation functions. This allows lazy init and per-method overrides
60
60
type DryRunClient struct {
61
- apiClient client.APIClient
62
- execs sync.Map
63
- resolver * imagetools.Resolver
61
+ apiClient client.APIClient
62
+ containers []moby.Container
63
+ execs sync.Map
64
+ resolver * imagetools.Resolver
64
65
}
65
66
66
67
type execDetails struct {
@@ -79,9 +80,10 @@ func NewDryRunClient(apiClient client.APIClient, cli *command.DockerCli) (*DryRu
79
80
return nil , err
80
81
}
81
82
return & DryRunClient {
82
- apiClient : apiClient ,
83
- execs : sync.Map {},
84
- resolver : imagetools .New (configFile ),
83
+ apiClient : apiClient ,
84
+ containers : []moby.Container {},
85
+ execs : sync.Map {},
86
+ resolver : imagetools .New (configFile ),
85
87
}, nil
86
88
}
87
89
@@ -99,15 +101,36 @@ func (d *DryRunClient) ContainerAttach(ctx context.Context, container string, op
99
101
100
102
func (d * DryRunClient ) ContainerCreate (ctx context.Context , config * containerType.Config , hostConfig * containerType.HostConfig ,
101
103
networkingConfig * network.NetworkingConfig , platform * specs.Platform , containerName string ) (containerType.CreateResponse , error ) {
102
- return containerType.CreateResponse {ID : "dryRunId" }, nil
104
+ d .containers = append (d .containers , moby.Container {
105
+ ID : containerName ,
106
+ Names : []string {containerName },
107
+ Labels : config .Labels ,
108
+ HostConfig : struct {
109
+ NetworkMode string `json:",omitempty"`
110
+ }{},
111
+ })
112
+ return containerType.CreateResponse {ID : containerName }, nil
103
113
}
104
114
105
115
func (d * DryRunClient ) ContainerInspect (ctx context.Context , container string ) (moby.ContainerJSON , error ) {
106
116
containerJSON , err := d .apiClient .ContainerInspect (ctx , container )
107
117
if err != nil {
118
+ id := "dryRunId"
119
+ for _ , c := range d .containers {
120
+ if c .ID == container {
121
+ id = container
122
+ }
123
+ }
108
124
return moby.ContainerJSON {
109
125
ContainerJSONBase : & moby.ContainerJSONBase {
110
- ID : "dryRunId" ,
126
+ ID : id ,
127
+ Name : container ,
128
+ State : & moby.ContainerState {
129
+ Status : "running" , // needed for --wait option
130
+ Health : & moby.Health {
131
+ Status : moby .Healthy , // needed for healthcheck control
132
+ },
133
+ },
111
134
},
112
135
Mounts : nil ,
113
136
Config : & containerType.Config {},
@@ -121,6 +144,21 @@ func (d *DryRunClient) ContainerKill(ctx context.Context, container, signal stri
121
144
return nil
122
145
}
123
146
147
+ func (d * DryRunClient ) ContainerList (ctx context.Context , options moby.ContainerListOptions ) ([]moby.Container , error ) {
148
+ caller := getCallingFunction ()
149
+ switch caller {
150
+ case "start" :
151
+ return d .containers , nil
152
+ case "getContainers" :
153
+ if len (d .containers ) == 0 {
154
+ var err error
155
+ d .containers , err = d .apiClient .ContainerList (ctx , options )
156
+ return d .containers , err
157
+ }
158
+ }
159
+ return d .apiClient .ContainerList (ctx , options )
160
+ }
161
+
124
162
func (d * DryRunClient ) ContainerPause (ctx context.Context , container string ) error {
125
163
return nil
126
164
}
@@ -246,7 +284,13 @@ func (d *DryRunClient) NetworkRemove(ctx context.Context, networkName string) er
246
284
}
247
285
248
286
func (d * DryRunClient ) VolumeCreate (ctx context.Context , options volume.CreateOptions ) (volume.Volume , error ) {
249
- return volume.Volume {}, ErrNotImplemented
287
+ return volume.Volume {
288
+ ClusterVolume : nil ,
289
+ Driver : options .Driver ,
290
+ Labels : options .Labels ,
291
+ Name : options .Name ,
292
+ Options : options .DriverOpts ,
293
+ }, nil
250
294
}
251
295
252
296
func (d * DryRunClient ) VolumeRemove (ctx context.Context , volumeID string , force bool ) error {
@@ -324,10 +368,6 @@ func (d *DryRunClient) ContainerInspectWithRaw(ctx context.Context, container st
324
368
return d .apiClient .ContainerInspectWithRaw (ctx , container , getSize )
325
369
}
326
370
327
- func (d * DryRunClient ) ContainerList (ctx context.Context , options moby.ContainerListOptions ) ([]moby.Container , error ) {
328
- return d .apiClient .ContainerList (ctx , options )
329
- }
330
-
331
371
func (d * DryRunClient ) ContainerLogs (ctx context.Context , container string , options moby.ContainerLogsOptions ) (io.ReadCloser , error ) {
332
372
return d .apiClient .ContainerLogs (ctx , container , options )
333
373
}
0 commit comments