Merge pull request #1000 from gtardif/compose_down_display

In `compose down` progress display: prefix container names with “Container”,
This commit is contained in:
Guillaume Tardif 2020-12-03 15:58:05 +01:00 committed by GitHub
commit 7fd60bd97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -261,28 +261,28 @@ func (s *composeService) Down(ctx context.Context, projectName string) error {
} }
func (s *composeService) removeContainers(ctx context.Context, w progress.Writer, eg *errgroup.Group, filter filters.Args) error { func (s *composeService) removeContainers(ctx context.Context, w progress.Writer, eg *errgroup.Group, filter filters.Args) error {
cnts, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
Filters: filter, Filters: filter,
}) })
if err != nil { if err != nil {
return err return err
} }
for _, c := range cnts { for _, container := range containers {
eg.Go(func() error { eg.Go(func() error {
cName := getContainerName(c) eventName := "Container " + getContainerName(container)
w.Event(progress.StoppingEvent(cName)) w.Event(progress.StoppingEvent(eventName))
err := s.apiClient.ContainerStop(ctx, c.ID, nil) err := s.apiClient.ContainerStop(ctx, container.ID, nil)
if err != nil { if err != nil {
w.Event(progress.ErrorMessageEvent(cName, "Error while Stopping")) w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
return err return err
} }
w.Event(progress.RemovingEvent(cName)) w.Event(progress.RemovingEvent(eventName))
err = s.apiClient.ContainerRemove(ctx, c.ID, moby.ContainerRemoveOptions{}) err = s.apiClient.ContainerRemove(ctx, container.ID, moby.ContainerRemoveOptions{})
if err != nil { if err != nil {
w.Event(progress.ErrorMessageEvent(cName, "Error while Removing")) w.Event(progress.ErrorMessageEvent(eventName, "Error while Removing"))
return err return err
} }
w.Event(progress.RemovedEvent(cName)) w.Event(progress.RemovedEvent(eventName))
return nil return nil
}) })
} }
@ -290,7 +290,7 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
} }
func (s *composeService) projectFromContainerLabels(ctx context.Context, projectName string) (*types.Project, error) { func (s *composeService) projectFromContainerLabels(ctx context.Context, projectName string) (*types.Project, error) {
cnts, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
Filters: filters.NewArgs( Filters: filters.NewArgs(
projectFilter(projectName), projectFilter(projectName),
), ),
@ -298,10 +298,10 @@ func (s *composeService) projectFromContainerLabels(ctx context.Context, project
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(cnts) == 0 { if len(containers) == 0 {
return nil, nil return nil, nil
} }
options, err := loadProjectOptionsFromLabels(cnts[0]) options, err := loadProjectOptionsFromLabels(containers[0])
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -309,9 +309,9 @@ func (s *composeService) projectFromContainerLabels(ctx context.Context, project
fakeProject := &types.Project{ fakeProject := &types.Project{
Name: projectName, Name: projectName,
} }
for _, c := range cnts { for _, container := range containers {
fakeProject.Services = append(fakeProject.Services, types.ServiceConfig{ fakeProject.Services = append(fakeProject.Services, types.ServiceConfig{
Name: c.Labels[serviceLabel], Name: container.Labels[serviceLabel],
}) })
} }
return fakeProject, nil return fakeProject, nil