|
@@ -85,7 +85,8 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
|
|
|
|
|
|
err = InReverseDependencyOrder(ctx, project, func(c context.Context, service string) error {
|
|
err = InReverseDependencyOrder(ctx, project, func(c context.Context, service string) error {
|
|
serviceContainers := containers.filter(isService(service))
|
|
serviceContainers := containers.filter(isService(service))
|
|
- err := s.removeContainers(ctx, serviceContainers, options.Timeout, options.Volumes)
|
|
|
|
|
|
+ serv := project.Services[service]
|
|
|
|
+ err := s.removeContainers(ctx, serviceContainers, &serv, options.Timeout, options.Volumes)
|
|
return err
|
|
return err
|
|
}, WithRootNodesAndDown(options.Services))
|
|
}, WithRootNodesAndDown(options.Services))
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -94,7 +95,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
|
|
|
|
|
|
orphans := containers.filter(isOrphaned(project))
|
|
orphans := containers.filter(isOrphaned(project))
|
|
if options.RemoveOrphans && len(orphans) > 0 {
|
|
if options.RemoveOrphans && len(orphans) > 0 {
|
|
- err := s.removeContainers(ctx, orphans, options.Timeout, false)
|
|
|
|
|
|
+ err := s.removeContainers(ctx, orphans, nil, options.Timeout, false)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -296,9 +297,19 @@ func (s *composeService) removeVolume(ctx context.Context, id string, w progress
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *composeService) stopContainer(ctx context.Context, w progress.Writer, container moby.Container, timeout *time.Duration) error {
|
|
|
|
|
|
+func (s *composeService) stopContainer(ctx context.Context, w progress.Writer, service *types.ServiceConfig, container moby.Container, timeout *time.Duration) error {
|
|
eventName := getContainerProgressName(container)
|
|
eventName := getContainerProgressName(container)
|
|
w.Event(progress.StoppingEvent(eventName))
|
|
w.Event(progress.StoppingEvent(eventName))
|
|
|
|
+
|
|
|
|
+ if service != nil {
|
|
|
|
+ for _, hook := range service.PreStop {
|
|
|
|
+ err := s.runHook(ctx, container, *service, hook, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
timeoutInSecond := utils.DurationSecondToInt(timeout)
|
|
timeoutInSecond := utils.DurationSecondToInt(timeout)
|
|
err := s.apiClient().ContainerStop(ctx, container.ID, containerType.StopOptions{Timeout: timeoutInSecond})
|
|
err := s.apiClient().ContainerStop(ctx, container.ID, containerType.StopOptions{Timeout: timeoutInSecond})
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -309,32 +320,32 @@ func (s *composeService) stopContainer(ctx context.Context, w progress.Writer, c
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *composeService) stopContainers(ctx context.Context, w progress.Writer, containers []moby.Container, timeout *time.Duration) error {
|
|
|
|
|
|
+func (s *composeService) stopContainers(ctx context.Context, w progress.Writer, serv *types.ServiceConfig, containers []moby.Container, timeout *time.Duration) error {
|
|
eg, ctx := errgroup.WithContext(ctx)
|
|
eg, ctx := errgroup.WithContext(ctx)
|
|
for _, container := range containers {
|
|
for _, container := range containers {
|
|
container := container
|
|
container := container
|
|
eg.Go(func() error {
|
|
eg.Go(func() error {
|
|
- return s.stopContainer(ctx, w, container, timeout)
|
|
|
|
|
|
+ return s.stopContainer(ctx, w, serv, container, timeout)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
return eg.Wait()
|
|
return eg.Wait()
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *composeService) removeContainers(ctx context.Context, containers []moby.Container, timeout *time.Duration, volumes bool) error {
|
|
|
|
|
|
+func (s *composeService) removeContainers(ctx context.Context, containers []moby.Container, service *types.ServiceConfig, timeout *time.Duration, volumes bool) error {
|
|
eg, _ := errgroup.WithContext(ctx)
|
|
eg, _ := errgroup.WithContext(ctx)
|
|
for _, container := range containers {
|
|
for _, container := range containers {
|
|
container := container
|
|
container := container
|
|
eg.Go(func() error {
|
|
eg.Go(func() error {
|
|
- return s.stopAndRemoveContainer(ctx, container, timeout, volumes)
|
|
|
|
|
|
+ return s.stopAndRemoveContainer(ctx, container, service, timeout, volumes)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
return eg.Wait()
|
|
return eg.Wait()
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *composeService) stopAndRemoveContainer(ctx context.Context, container moby.Container, timeout *time.Duration, volumes bool) error {
|
|
|
|
|
|
+func (s *composeService) stopAndRemoveContainer(ctx context.Context, container moby.Container, service *types.ServiceConfig, timeout *time.Duration, volumes bool) error {
|
|
w := progress.ContextWriter(ctx)
|
|
w := progress.ContextWriter(ctx)
|
|
eventName := getContainerProgressName(container)
|
|
eventName := getContainerProgressName(container)
|
|
- err := s.stopContainer(ctx, w, container, timeout)
|
|
|
|
|
|
+ err := s.stopContainer(ctx, w, service, container, timeout)
|
|
if errdefs.IsNotFound(err) {
|
|
if errdefs.IsNotFound(err) {
|
|
w.Event(progress.RemovedEvent(eventName))
|
|
w.Event(progress.RemovedEvent(eventName))
|
|
return nil
|
|
return nil
|