1- package swarm
1+ package stack
22
33import (
44 "context"
77
88 "github.com/containerd/errdefs"
99 "github.com/docker/cli/cli/command"
10- servicecli "github.com/docker/cli/cli/command/service"
11- "github.com/docker/cli/cli/command/stack/options"
10+ "github.com/docker/cli/cli/command/service"
1211 "github.com/docker/cli/cli/compose/convert"
1312 composetypes "github.com/docker/cli/cli/compose/types"
1413 "github.com/moby/moby/api/types/container"
@@ -17,7 +16,7 @@ import (
1716 "github.com/moby/moby/client"
1817)
1918
20- func deployCompose (ctx context.Context , dockerCli command.Cli , opts * options. Deploy , config * composetypes.Config ) error {
19+ func deployCompose (ctx context.Context , dockerCli command.Cli , opts * deployOptions , config * composetypes.Config ) error {
2120 if err := checkDaemonIsSwarmManager (ctx , dockerCli ); err != nil {
2221 return err
2322 }
@@ -26,8 +25,8 @@ func deployCompose(ctx context.Context, dockerCli command.Cli, opts *options.Dep
2625
2726 if opts .Prune {
2827 services := map [string ]struct {}{}
29- for _ , service := range config .Services {
30- services [service .Name ] = struct {}{}
28+ for _ , svc := range config .Services {
29+ services [svc .Name ] = struct {}{}
3130 }
3231 pruneServices (ctx , dockerCli , namespace , services )
3332 }
@@ -196,8 +195,8 @@ func deployServices(ctx context.Context, dockerCLI command.Cli, services map[str
196195 }
197196
198197 existingServiceMap := make (map [string ]swarm.Service )
199- for _ , service := range existingServices {
200- existingServiceMap [service .Spec .Name ] = service
198+ for _ , svc := range existingServices {
199+ existingServiceMap [svc .Spec .Name ] = svc
201200 }
202201
203202 var serviceIDs []string
@@ -217,42 +216,42 @@ func deployServices(ctx context.Context, dockerCLI command.Cli, services map[str
217216 }
218217 }
219218
220- if service , exists := existingServiceMap [name ]; exists {
221- _ , _ = fmt .Fprintf (out , "Updating service %s (id: %s)\n " , name , service .ID )
219+ if svc , exists := existingServiceMap [name ]; exists {
220+ _ , _ = fmt .Fprintf (out , "Updating service %s (id: %s)\n " , name , svc .ID )
222221
223222 updateOpts := client.ServiceUpdateOptions {EncodedRegistryAuth : encodedAuth }
224223
225224 switch resolveImage {
226- case ResolveImageAlways :
225+ case resolveImageAlways :
227226 // image should be updated by the server using QueryRegistry
228227 updateOpts .QueryRegistry = true
229- case ResolveImageChanged :
230- if image != service .Spec .Labels [convert .LabelImage ] {
228+ case resolveImageChanged :
229+ if image != svc .Spec .Labels [convert .LabelImage ] {
231230 // Query the registry to resolve digest for the updated image
232231 updateOpts .QueryRegistry = true
233232 } else {
234233 // image has not changed; update the serviceSpec with the
235234 // existing information that was set by QueryRegistry on the
236235 // previous deploy. Otherwise this will trigger an incorrect
237236 // service update.
238- serviceSpec .TaskTemplate .ContainerSpec .Image = service .Spec .TaskTemplate .ContainerSpec .Image
237+ serviceSpec .TaskTemplate .ContainerSpec .Image = svc .Spec .TaskTemplate .ContainerSpec .Image
239238 }
240239 default :
241- if image == service .Spec .Labels [convert .LabelImage ] {
240+ if image == svc .Spec .Labels [convert .LabelImage ] {
242241 // image has not changed; update the serviceSpec with the
243242 // existing information that was set by QueryRegistry on the
244243 // previous deploy. Otherwise this will trigger an incorrect
245244 // service update.
246- serviceSpec .TaskTemplate .ContainerSpec .Image = service .Spec .TaskTemplate .ContainerSpec .Image
245+ serviceSpec .TaskTemplate .ContainerSpec .Image = svc .Spec .TaskTemplate .ContainerSpec .Image
247246 }
248247 }
249248
250249 // Stack deploy does not have a `--force` option. Preserve existing
251250 // ForceUpdate value so that tasks are not re-deployed if not updated.
252251 // TODO move this to API client?
253- serviceSpec .TaskTemplate .ForceUpdate = service .Spec .TaskTemplate .ForceUpdate
252+ serviceSpec .TaskTemplate .ForceUpdate = svc .Spec .TaskTemplate .ForceUpdate
254253
255- response , err := apiClient .ServiceUpdate (ctx , service .ID , service .Version , serviceSpec , updateOpts )
254+ response , err := apiClient .ServiceUpdate (ctx , svc .ID , svc .Version , serviceSpec , updateOpts )
256255 if err != nil {
257256 return nil , fmt .Errorf ("failed to update service %s: %w" , name , err )
258257 }
@@ -261,12 +260,12 @@ func deployServices(ctx context.Context, dockerCLI command.Cli, services map[str
261260 _ , _ = fmt .Fprintln (dockerCLI .Err (), warning )
262261 }
263262
264- serviceIDs = append (serviceIDs , service .ID )
263+ serviceIDs = append (serviceIDs , svc .ID )
265264 } else {
266265 _ , _ = fmt .Fprintln (out , "Creating service" , name )
267266
268267 // query registry if flag disabling it was not set
269- queryRegistry := resolveImage == ResolveImageAlways || resolveImage == ResolveImageChanged
268+ queryRegistry := resolveImage == resolveImageAlways || resolveImage == resolveImageChanged
270269
271270 response , err := apiClient .ServiceCreate (ctx , serviceSpec , client.ServiceCreateOptions {
272271 EncodedRegistryAuth : encodedAuth ,
@@ -286,7 +285,7 @@ func deployServices(ctx context.Context, dockerCLI command.Cli, services map[str
286285func waitOnServices (ctx context.Context , dockerCli command.Cli , serviceIDs []string , quiet bool ) error {
287286 var errs []error
288287 for _ , serviceID := range serviceIDs {
289- if err := servicecli .WaitOnService (ctx , dockerCli , serviceID , quiet ); err != nil {
288+ if err := service .WaitOnService (ctx , dockerCli , serviceID , quiet ); err != nil {
290289 errs = append (errs , fmt .Errorf ("%s: %w" , serviceID , err ))
291290 }
292291 }
0 commit comments