@@ -15,14 +15,11 @@ import (
1515 "sync/atomic"
1616 "time"
1717
18- "github.com/docker/docker/api/types"
19- "github.com/docker/docker/api/types/container"
20- "github.com/docker/docker/api/types/filters"
21- "github.com/docker/docker/api/types/image"
22- "github.com/docker/docker/client"
23- "github.com/docker/docker/errdefs"
24- "github.com/docker/docker/pkg/jsonmessage"
25- "github.com/docker/docker/pkg/stdcopy"
18+ cerrdefs "github.com/containerd/errdefs"
19+ "github.com/moby/moby/api/pkg/stdcopy"
20+ "github.com/moby/moby/api/types/container"
21+ "github.com/moby/moby/client"
22+ "github.com/moby/moby/api/types/jsonstream"
2623 "github.com/perimeterx/envite"
2724)
2825
@@ -121,7 +118,11 @@ func (c *Component) Prepare(ctx context.Context) error {
121118
122119 // create a dedicated copy of the docker image to prevent
123120 // other environments running concurrently from removing our image.
124- return c .cli .ImageTag (ctx , c .config .Image , c .imageCloneTag )
121+ _ , err = c .cli .ImageTag (ctx , client.ImageTagOptions {
122+ Source : c .config .Image ,
123+ Target : c .imageCloneTag ,
124+ })
125+ return err
125126}
126127
127128// pullImage pulls the Docker image specified in the configuration.
@@ -144,7 +145,7 @@ func (c *Component) pullImage(ctx context.Context) error {
144145 scanner := bufio .NewScanner (reader )
145146 for scanner .Scan () {
146147 bytes := scanner .Bytes ()
147- msg := jsonmessage. JSONMessage {}
148+ msg := jsonstream. Message {}
148149 err = json .Unmarshal (bytes , & msg )
149150 if err != nil {
150151 return fmt .Errorf ("failed to parse image pull output: %w" , err )
@@ -191,17 +192,16 @@ func (c *Component) startContainer(ctx context.Context) (string, error) {
191192 defer c .lock .Unlock ()
192193
193194 var id string
194- res , err := c .cli .ContainerCreate (
195- ctx ,
196- c .runConfig .containerConfig ,
197- c .runConfig .hostConfig ,
198- c .runConfig .networkingConfig ,
199- c .runConfig .platformConfig ,
200- c .containerName ,
201- )
195+ res , err := c .cli .ContainerCreate (ctx , client.ContainerCreateOptions {
196+ Config : c .runConfig .containerConfig ,
197+ HostConfig : c .runConfig .hostConfig ,
198+ NetworkingConfig : c .runConfig .networkingConfig ,
199+ Platform : c .runConfig .platformConfig ,
200+ Name : c .containerName ,
201+ })
202202 if err == nil {
203203 id = res .ID
204- } else if ! errdefs .IsConflict (err ) {
204+ } else if ! cerrdefs .IsConflict (err ) {
205205 return "" , fmt .Errorf ("failed to create container: %w" , err )
206206 } else {
207207 cont , err := c .findContainer (ctx )
@@ -212,7 +212,7 @@ func (c *Component) startContainer(ctx context.Context) (string, error) {
212212 id = cont .ID
213213 }
214214
215- err = c .cli .ContainerStart (context .Background (), id , container. StartOptions {})
215+ _ , err = c .cli .ContainerStart (context .Background (), id , client. ContainerStartOptions {})
216216 if err != nil {
217217 return "" , fmt .Errorf ("failed to start container: %w" , err )
218218 }
@@ -234,13 +234,13 @@ func (c *Component) Stop(ctx context.Context) error {
234234 return nil
235235 }
236236
237- err = c .cli .ContainerStop (ctx , cont .ID , container. StopOptions {})
237+ _ , err = c .cli .ContainerStop (ctx , cont .ID , client. ContainerStopOptions {})
238238 if err != nil {
239239 return err
240240 }
241241
242- err = c .cli .ContainerRemove (ctx , cont .ID , container. RemoveOptions {Force : true })
243- if err != nil && ! errdefs .IsNotFound (err ) && ! errdefs .IsConflict (err ) {
242+ _ , err = c .cli .ContainerRemove (ctx , cont .ID , client. ContainerRemoveOptions {Force : true })
243+ if err != nil && ! cerrdefs .IsNotFound (err ) && ! cerrdefs .IsConflict (err ) {
244244 return err
245245 }
246246
@@ -261,7 +261,7 @@ func (c *Component) Cleanup(ctx context.Context) error {
261261}
262262
263263func (c * Component ) removeImage (ctx context.Context ) error {
264- _ , err := c .cli .ImageRemove (ctx , c .imageCloneTag , image. RemoveOptions {})
264+ _ , err := c .cli .ImageRemove (ctx , c .imageCloneTag , client. ImageRemoveOptions {})
265265 if err != nil && ! strings .Contains (err .Error (), "reference does not exist" ) && ! strings .Contains (err .Error (), "No such image" ) {
266266 return err
267267 }
@@ -271,8 +271,8 @@ func (c *Component) removeImage(ctx context.Context) error {
271271 return nil
272272 }
273273
274- _ , err = c .cli .ImageRemove (ctx , c .config .Image , image. RemoveOptions {})
275- if err != nil && ! errdefs .IsNotFound (err ) {
274+ _ , err = c .cli .ImageRemove (ctx , c .config .Image , client. ImageRemoveOptions {})
275+ if err != nil && ! cerrdefs .IsNotFound (err ) {
276276 return err
277277 }
278278
@@ -289,7 +289,7 @@ func (c *Component) Status(context.Context) (envite.ComponentStatus, error) {
289289 return "" , fmt .Errorf ("failed to find container: %w" , err )
290290 }
291291
292- if cont == nil || cont .State != "running" {
292+ if cont == nil || cont .State != container . StateRunning {
293293 status = envite .ComponentStatusStopped
294294 c .status .Store (envite .ComponentStatusStopped )
295295 }
@@ -327,17 +327,16 @@ func (c *Component) Exec(ctx context.Context, cmd []string) (int, error) {
327327 }
328328
329329 c .Writer ().WriteString (c .Writer ().Color .Cyan (fmt .Sprintf ("executing: %s" , strings .Join (cmd , " " ))))
330- response , err := c .cli .ContainerExecCreate (ctx , cont .ID , container. ExecOptions {
330+ response , err := c .cli .ExecCreate (ctx , cont .ID , client. ExecCreateOptions {
331331 Cmd : cmd ,
332- Detach : false ,
333332 AttachStdout : true ,
334333 AttachStderr : true ,
335334 })
336335 if err != nil {
337336 return 0 , fmt .Errorf ("failed to create exec: %w" , err )
338337 }
339338
340- hijack , err := c .cli .ContainerExecAttach (ctx , response .ID , container. ExecStartOptions {})
339+ hijack , err := c .cli .ExecAttach (ctx , response .ID , client. ExecAttachOptions {})
341340 if err != nil {
342341 return 0 , fmt .Errorf ("failed to attach exec: %w" , err )
343342 }
@@ -349,7 +348,7 @@ func (c *Component) Exec(ctx context.Context, cmd []string) (int, error) {
349348
350349 hijack .Close ()
351350
352- execResp , err := c .cli .ContainerExecInspect (ctx , response .ID )
351+ execResp , err := c .cli .ExecInspect (ctx , response .ID , client. ExecInspectOptions {} )
353352 if err != nil {
354353 return 0 , fmt .Errorf ("failed to inspect exec: %w" , err )
355354 }
@@ -358,16 +357,16 @@ func (c *Component) Exec(ctx context.Context, cmd []string) (int, error) {
358357 return execResp .ExitCode , nil
359358}
360359
361- func (c * Component ) findContainer (ctx context.Context ) (* types. Container , error ) {
362- containers , err := c .cli .ContainerList (ctx , container. ListOptions {
360+ func (c * Component ) findContainer (ctx context.Context ) (* container. Summary , error ) {
361+ listResult , err := c .cli .ContainerList (ctx , client. ContainerListOptions {
363362 All : true ,
364- Filters : filters . NewArgs ( filters . Arg ("name" , c .containerName ) ),
363+ Filters : make (client. Filters ). Add ("name" , c .containerName ),
365364 })
366365 if err != nil {
367366 return nil , fmt .Errorf ("failed to list containers: %w" , err )
368367 }
369368
370- for _ , co := range containers {
369+ for _ , co := range listResult . Items {
371370 if len (co .Names ) > 0 && co .Names [0 ][1 :] == c .containerName {
372371 return & co , nil
373372 }
0 commit comments