@@ -30,7 +30,7 @@ import (
3030
3131 "github.com/compose-spec/compose-go/v2/types"
3232 "github.com/containerd/platforms"
33- containerType "github.com/docker/docker/api/types/container"
33+ "github.com/docker/docker/api/types/container"
3434 mmount "github.com/docker/docker/api/types/mount"
3535 "github.com/docker/docker/api/types/versions"
3636 specs "github.com/opencontainers/image-spec/specs-go/v1"
@@ -152,19 +152,19 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
152152 })
153153
154154 slices .Reverse (containers )
155- for i , container := range containers {
155+ for i , ctr := range containers {
156156 if i >= expected {
157157 // Scale Down
158158 // As we sorted containers, obsolete ones and/or highest number will be removed
159- container := container
160- traceOpts := append (tracing .ServiceOptions (service ), tracing .ContainerOptions (container )... )
159+ ctr := ctr
160+ traceOpts := append (tracing .ServiceOptions (service ), tracing .ContainerOptions (ctr )... )
161161 eg .Go (tracing .SpanWrapFuncForErrGroup (ctx , "service/scale/down" , traceOpts , func (ctx context.Context ) error {
162- return c .service .stopAndRemoveContainer (ctx , container , & service , timeout , false )
162+ return c .service .stopAndRemoveContainer (ctx , ctr , & service , timeout , false )
163163 }))
164164 continue
165165 }
166166
167- mustRecreate , err := c .mustRecreate (service , container , recreate )
167+ mustRecreate , err := c .mustRecreate (service , ctr , recreate )
168168 if err != nil {
169169 return err
170170 }
@@ -174,9 +174,9 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
174174 return err
175175 }
176176
177- i , container := i , container
178- eg .Go (tracing .SpanWrapFuncForErrGroup (ctx , "container/recreate" , tracing .ContainerOptions (container ), func (ctx context.Context ) error {
179- recreated , err := c .service .recreateContainer (ctx , project , service , container , inherit , timeout )
177+ i , ctr := i , ctr
178+ eg .Go (tracing .SpanWrapFuncForErrGroup (ctx , "container/recreate" , tracing .ContainerOptions (ctr ), func (ctx context.Context ) error {
179+ recreated , err := c .service .recreateContainer (ctx , project , service , ctr , inherit , timeout )
180180 updated [i ] = recreated
181181 return err
182182 }))
@@ -185,20 +185,20 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
185185
186186 // Enforce non-diverged containers are running
187187 w := progress .ContextWriter (ctx )
188- name := getContainerProgressName (container )
189- switch container .State {
190- case ContainerRunning :
188+ name := getContainerProgressName (ctr )
189+ switch ctr .State {
190+ case container . StateRunning :
191191 w .Event (progress .RunningEvent (name ))
192- case ContainerCreated :
193- case ContainerRestarting :
194- case ContainerExited :
192+ case container . StateCreated :
193+ case container . StateRestarting :
194+ case container . StateExited :
195195 default :
196- container := container
197- eg .Go (tracing .EventWrapFuncForErrGroup (ctx , "service/start" , tracing .ContainerOptions (container ), func (ctx context.Context ) error {
198- return c .service .startContainer (ctx , container )
196+ ctr := ctr
197+ eg .Go (tracing .EventWrapFuncForErrGroup (ctx , "service/start" , tracing .ContainerOptions (ctr ), func (ctx context.Context ) error {
198+ return c .service .startContainer (ctx , ctr )
199199 }))
200200 }
201- updated [i ] = container
201+ updated [i ] = ctr
202202 }
203203
204204 next := nextContainerNumber (containers )
@@ -214,8 +214,8 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
214214 UseNetworkAliases : true ,
215215 Labels : mergeLabels (service .Labels , service .CustomLabels ),
216216 }
217- container , err := c .service .createContainer (ctx , project , service , name , number , opts )
218- updated [actual + i ] = container
217+ ctr , err := c .service .createContainer (ctx , project , service , name , number , opts )
218+ updated [actual + i ] = ctr
219219 return err
220220 }))
221221 continue
@@ -245,7 +245,7 @@ func (c *convergence) stopDependentContainers(ctx context.Context, project *type
245245 for _ , name := range dependents {
246246 dependentStates := c .getObservedState (name )
247247 for i , dependent := range dependentStates {
248- dependent .State = ContainerExited
248+ dependent .State = container . StateExited
249249 dependentStates [i ] = dependent
250250 }
251251 c .setObservedState (name , dependentStates )
@@ -328,7 +328,7 @@ func (c *convergence) resolveSharedNamespaces(service *types.ServiceConfig) erro
328328 return nil
329329}
330330
331- func (c * convergence ) mustRecreate (expected types.ServiceConfig , actual containerType .Summary , policy string ) (bool , error ) {
331+ func (c * convergence ) mustRecreate (expected types.ServiceConfig , actual container .Summary , policy string ) (bool , error ) {
332332 if policy == api .RecreateNever {
333333 return false , nil
334334 }
@@ -360,7 +360,7 @@ func (c *convergence) mustRecreate(expected types.ServiceConfig, actual containe
360360 return false , nil
361361}
362362
363- func checkExpectedNetworks (expected types.ServiceConfig , actual containerType .Summary , networks map [string ]string ) bool {
363+ func checkExpectedNetworks (expected types.ServiceConfig , actual container .Summary , networks map [string ]string ) bool {
364364 // check the networks container is connected to are the expected ones
365365 for net := range expected .Networks {
366366 id := networks [net ]
@@ -383,7 +383,7 @@ func checkExpectedNetworks(expected types.ServiceConfig, actual containerType.Su
383383 return false
384384}
385385
386- func checkExpectedVolumes (expected types.ServiceConfig , actual containerType .Summary , volumes map [string ]string ) bool {
386+ func checkExpectedVolumes (expected types.ServiceConfig , actual container .Summary , volumes map [string ]string ) bool {
387387 // check container's volume mounts and search for the expected ones
388388 for _ , vol := range expected .Volumes {
389389 if vol .Type != string (mmount .TypeVolume ) {
@@ -423,7 +423,7 @@ func getDefaultContainerName(projectName, serviceName, index string) string {
423423 return strings .Join ([]string {projectName , serviceName , index }, api .Separator )
424424}
425425
426- func getContainerProgressName (ctr containerType .Summary ) string {
426+ func getContainerProgressName (ctr container .Summary ) string {
427427 return "Container " + getCanonicalContainerName (ctr )
428428}
429429
@@ -571,7 +571,7 @@ func shouldWaitForDependency(serviceName string, dependencyConfig types.ServiceD
571571 return true , nil
572572}
573573
574- func nextContainerNumber (containers []containerType .Summary ) int {
574+ func nextContainerNumber (containers []container .Summary ) int {
575575 maxNumber := 0
576576 for _ , c := range containers {
577577 s , ok := c .Labels [api .ContainerNumberLabel ]
@@ -592,7 +592,7 @@ func nextContainerNumber(containers []containerType.Summary) int {
592592
593593func (s * composeService ) createContainer (ctx context.Context , project * types.Project , service types.ServiceConfig ,
594594 name string , number int , opts createOptions ,
595- ) (ctr containerType .Summary , err error ) {
595+ ) (ctr container .Summary , err error ) {
596596 w := progress .ContextWriter (ctx )
597597 eventName := "Container " + name
598598 w .Event (progress .CreatingEvent (eventName ))
@@ -612,8 +612,8 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
612612}
613613
614614func (s * composeService ) recreateContainer (ctx context.Context , project * types.Project , service types.ServiceConfig ,
615- replaced containerType .Summary , inherit bool , timeout * time.Duration ,
616- ) (created containerType .Summary , err error ) {
615+ replaced container .Summary , inherit bool , timeout * time.Duration ,
616+ ) (created container .Summary , err error ) {
617617 w := progress .ContextWriter (ctx )
618618 eventName := getContainerProgressName (replaced )
619619 w .Event (progress .NewEvent (eventName , progress .Working , "Recreate" ))
@@ -632,7 +632,7 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
632632 return created , err
633633 }
634634
635- var inherited * containerType .Summary
635+ var inherited * container .Summary
636636 if inherit {
637637 inherited = & replaced
638638 }
@@ -655,12 +655,12 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
655655 }
656656
657657 timeoutInSecond := utils .DurationSecondToInt (timeout )
658- err = s .apiClient ().ContainerStop (ctx , replaced .ID , containerType .StopOptions {Timeout : timeoutInSecond })
658+ err = s .apiClient ().ContainerStop (ctx , replaced .ID , container .StopOptions {Timeout : timeoutInSecond })
659659 if err != nil {
660660 return created , err
661661 }
662662
663- err = s .apiClient ().ContainerRemove (ctx , replaced .ID , containerType .RemoveOptions {})
663+ err = s .apiClient ().ContainerRemove (ctx , replaced .ID , container .RemoveOptions {})
664664 if err != nil {
665665 return created , err
666666 }
@@ -677,12 +677,12 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
677677// force sequential calls to ContainerStart to prevent race condition in engine assigning ports from ranges
678678var startMx sync.Mutex
679679
680- func (s * composeService ) startContainer (ctx context.Context , ctr containerType .Summary ) error {
680+ func (s * composeService ) startContainer (ctx context.Context , ctr container .Summary ) error {
681681 w := progress .ContextWriter (ctx )
682682 w .Event (progress .NewEvent (getContainerProgressName (ctr ), progress .Working , "Restart" ))
683683 startMx .Lock ()
684684 defer startMx .Unlock ()
685- err := s .apiClient ().ContainerStart (ctx , ctr .ID , containerType .StartOptions {})
685+ err := s .apiClient ().ContainerStart (ctx , ctr .ID , container .StartOptions {})
686686 if err != nil {
687687 return err
688688 }
@@ -695,11 +695,11 @@ func (s *composeService) createMobyContainer(ctx context.Context,
695695 service types.ServiceConfig ,
696696 name string ,
697697 number int ,
698- inherit * containerType .Summary ,
698+ inherit * container .Summary ,
699699 opts createOptions ,
700700 w progress.Writer ,
701- ) (containerType .Summary , error ) {
702- var created containerType .Summary
701+ ) (container .Summary , error ) {
702+ var created container .Summary
703703 cfgs , err := s .getCreateConfigs (ctx , project , service , number , inherit , opts )
704704 if err != nil {
705705 return created , err
@@ -733,11 +733,11 @@ func (s *composeService) createMobyContainer(ctx context.Context,
733733 if err != nil {
734734 return created , err
735735 }
736- created = containerType .Summary {
736+ created = container .Summary {
737737 ID : inspectedContainer .ID ,
738738 Labels : inspectedContainer .Config .Labels ,
739739 Names : []string {inspectedContainer .Name },
740- NetworkSettings : & containerType .NetworkSettingsSummary {
740+ NetworkSettings : & container .NetworkSettingsSummary {
741741 Networks : inspectedContainer .NetworkSettings .Networks ,
742742 },
743743 }
@@ -834,24 +834,24 @@ func (s *composeService) isServiceHealthy(ctx context.Context, containers Contai
834834 }
835835 name := ctr .Name [1 :]
836836
837- if ctr .State .Status == containerType .StateExited {
837+ if ctr .State .Status == container .StateExited {
838838 return false , fmt .Errorf ("container %s exited (%d)" , name , ctr .State .ExitCode )
839839 }
840840
841841 if ctr .Config .Healthcheck == nil && fallbackRunning {
842842 // Container does not define a health check, but we can fall back to "running" state
843- return ctr .State != nil && ctr .State .Status == containerType .StateRunning , nil
843+ return ctr .State != nil && ctr .State .Status == container .StateRunning , nil
844844 }
845845
846846 if ctr .State == nil || ctr .State .Health == nil {
847847 return false , fmt .Errorf ("container %s has no healthcheck configured" , name )
848848 }
849849 switch ctr .State .Health .Status {
850- case containerType .Healthy :
850+ case container .Healthy :
851851 // Continue by checking the next container.
852- case containerType .Unhealthy :
852+ case container .Unhealthy :
853853 return false , fmt .Errorf ("container %s is unhealthy" , name )
854- case containerType .Starting :
854+ case container .Starting :
855855 return false , nil
856856 default :
857857 return false , fmt .Errorf ("container %s had unexpected health status %q" , name , ctr .State .Health .Status )
@@ -866,7 +866,7 @@ func (s *composeService) isServiceCompleted(ctx context.Context, containers Cont
866866 if err != nil {
867867 return false , 0 , err
868868 }
869- if ctr .State != nil && ctr .State .Status == containerType .StateExited {
869+ if ctr .State != nil && ctr .State .Status == container .StateExited {
870870 return true , ctr .State .ExitCode , nil
871871 }
872872 }
@@ -896,7 +896,7 @@ func (s *composeService) startService(ctx context.Context,
896896
897897 w := progress .ContextWriter (ctx )
898898 for _ , ctr := range containers .filter (isService (service .Name )) {
899- if ctr .State == ContainerRunning {
899+ if ctr .State == container . StateRunning {
900900 continue
901901 }
902902
@@ -912,7 +912,7 @@ func (s *composeService) startService(ctx context.Context,
912912
913913 eventName := getContainerProgressName (ctr )
914914 w .Event (progress .StartingEvent (eventName ))
915- err = s .apiClient ().ContainerStart (ctx , ctr .ID , containerType .StartOptions {})
915+ err = s .apiClient ().ContainerStart (ctx , ctr .ID , container .StartOptions {})
916916 if err != nil {
917917 return err
918918 }
0 commit comments