mirror of https://github.com/docker/compose.git
Make progress event display homogeneous between up, down, start, stop
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
fd906c6c91
commit
3252c409f8
|
@ -98,7 +98,7 @@ func (s *composeService) ensureService(ctx context.Context, observedState Contai
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, container := range actual {
|
for _, container := range actual {
|
||||||
name := getCanonicalContainerName(container)
|
name := getContainerProgressName(container)
|
||||||
|
|
||||||
diverged := container.Labels[configHashLabel] != expected
|
diverged := container.Labels[configHashLabel] != expected
|
||||||
if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
|
if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
|
||||||
|
@ -132,6 +132,10 @@ func getContainerName(projectName string, service types.ServiceConfig, number in
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getContainerProgressName(container moby.Container) string {
|
||||||
|
return "Container " + getCanonicalContainerName(container)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, service types.ServiceConfig) error {
|
func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, service types.ServiceConfig) error {
|
||||||
eg, _ := errgroup.WithContext(ctx)
|
eg, _ := errgroup.WithContext(ctx)
|
||||||
for dep, config := range service.DependsOn {
|
for dep, config := range service.DependsOn {
|
||||||
|
@ -191,18 +195,19 @@ func getScale(config types.ServiceConfig) (int, error) {
|
||||||
|
|
||||||
func (s *composeService) createContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, name string, number int, autoRemove bool) error {
|
func (s *composeService) createContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, name string, number int, autoRemove bool) error {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
w.Event(progress.CreatingEvent(name))
|
eventName := "Container " + name
|
||||||
|
w.Event(progress.CreatingEvent(eventName))
|
||||||
err := s.createMobyContainer(ctx, project, service, name, number, nil, autoRemove)
|
err := s.createMobyContainer(ctx, project, service, name, number, nil, autoRemove)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Event(progress.CreatedEvent(name))
|
w.Event(progress.CreatedEvent(eventName))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, container moby.Container) error {
|
func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, container moby.Container) error {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Working, "Recreate"))
|
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Recreate"))
|
||||||
err := s.apiClient.ContainerStop(ctx, container.ID, nil)
|
err := s.apiClient.ContainerStop(ctx, container.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -225,7 +230,7 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Done, "Recreated"))
|
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Done, "Recreated"))
|
||||||
setDependentLifecycle(project, service.Name, forceRecreate)
|
setDependentLifecycle(project, service.Name, forceRecreate)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -245,12 +250,12 @@ func setDependentLifecycle(project *types.Project, service string, strategy stri
|
||||||
|
|
||||||
func (s *composeService) restartContainer(ctx context.Context, container moby.Container) error {
|
func (s *composeService) restartContainer(ctx context.Context, container moby.Container) error {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Working, "Restart"))
|
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Restart"))
|
||||||
err := s.apiClient.ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
|
err := s.apiClient.ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Done, "Restarted"))
|
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Done, "Restarted"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,10 +341,11 @@ func (s *composeService) startService(ctx context.Context, project *types.Projec
|
||||||
}
|
}
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
w.Event(progress.StartingEvent(getCanonicalContainerName(container)))
|
eventName := getContainerProgressName(container)
|
||||||
|
w.Event(progress.StartingEvent(eventName))
|
||||||
err := s.apiClient.ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
|
err := s.apiClient.ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
w.Event(progress.StartedEvent(getCanonicalContainerName(container)))
|
w.Event(progress.StartedEvent(eventName))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
|
||||||
func (s *composeService) stopContainers(ctx context.Context, w progress.Writer, containers []moby.Container) error {
|
func (s *composeService) stopContainers(ctx context.Context, w progress.Writer, containers []moby.Container) error {
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
toStop := container
|
toStop := container
|
||||||
eventName := "Container " + getCanonicalContainerName(toStop)
|
eventName := getContainerProgressName(toStop)
|
||||||
w.Event(progress.StoppingEvent(eventName))
|
w.Event(progress.StoppingEvent(eventName))
|
||||||
err := s.apiClient.ContainerStop(ctx, toStop.ID, nil)
|
err := s.apiClient.ContainerStop(ctx, toStop.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,9 +109,11 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
toDelete := container
|
toDelete := container
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
eventName := "Container " + getCanonicalContainerName(toDelete)
|
eventName := getContainerProgressName(toDelete)
|
||||||
err := s.stopContainers(ctx, w, []moby.Container{container})
|
w.Event(progress.StoppingEvent(eventName))
|
||||||
|
err := s.stopContainers(ctx, w, []moby.Container{toDelete})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Event(progress.RemovingEvent(eventName))
|
w.Event(progress.RemovingEvent(eventName))
|
||||||
|
|
Loading…
Reference in New Issue