Skip to content

Commit 51d78c0

Browse files
authored
Merge pull request docker-archive#1203 from gtardif/nicer_progress_events_names
Make progress event display homogeneous between up, down, start, stop
2 parents fd906c6 + 3252c40 commit 51d78c0

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

local/compose/convergence.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (s *composeService) ensureService(ctx context.Context, observedState Contai
9898
}
9999

100100
for _, container := range actual {
101-
name := getCanonicalContainerName(container)
101+
name := getContainerProgressName(container)
102102

103103
diverged := container.Labels[configHashLabel] != expected
104104
if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
@@ -132,6 +132,10 @@ func getContainerName(projectName string, service types.ServiceConfig, number in
132132
return name
133133
}
134134

135+
func getContainerProgressName(container moby.Container) string {
136+
return "Container " + getCanonicalContainerName(container)
137+
}
138+
135139
func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, service types.ServiceConfig) error {
136140
eg, _ := errgroup.WithContext(ctx)
137141
for dep, config := range service.DependsOn {
@@ -191,18 +195,19 @@ func getScale(config types.ServiceConfig) (int, error) {
191195

192196
func (s *composeService) createContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, name string, number int, autoRemove bool) error {
193197
w := progress.ContextWriter(ctx)
194-
w.Event(progress.CreatingEvent(name))
198+
eventName := "Container " + name
199+
w.Event(progress.CreatingEvent(eventName))
195200
err := s.createMobyContainer(ctx, project, service, name, number, nil, autoRemove)
196201
if err != nil {
197202
return err
198203
}
199-
w.Event(progress.CreatedEvent(name))
204+
w.Event(progress.CreatedEvent(eventName))
200205
return nil
201206
}
202207

203208
func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, container moby.Container) error {
204209
w := progress.ContextWriter(ctx)
205-
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Working, "Recreate"))
210+
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Recreate"))
206211
err := s.apiClient.ContainerStop(ctx, container.ID, nil)
207212
if err != nil {
208213
return err
@@ -225,7 +230,7 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
225230
if err != nil {
226231
return err
227232
}
228-
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Done, "Recreated"))
233+
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Done, "Recreated"))
229234
setDependentLifecycle(project, service.Name, forceRecreate)
230235
return nil
231236
}
@@ -245,12 +250,12 @@ func setDependentLifecycle(project *types.Project, service string, strategy stri
245250

246251
func (s *composeService) restartContainer(ctx context.Context, container moby.Container) error {
247252
w := progress.ContextWriter(ctx)
248-
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Working, "Restart"))
253+
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Restart"))
249254
err := s.apiClient.ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
250255
if err != nil {
251256
return err
252257
}
253-
w.Event(progress.NewEvent(getCanonicalContainerName(container), progress.Done, "Restarted"))
258+
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Done, "Restarted"))
254259
return nil
255260
}
256261

@@ -336,10 +341,11 @@ func (s *composeService) startService(ctx context.Context, project *types.Projec
336341
}
337342
eg.Go(func() error {
338343
w := progress.ContextWriter(ctx)
339-
w.Event(progress.StartingEvent(getCanonicalContainerName(container)))
344+
eventName := getContainerProgressName(container)
345+
w.Event(progress.StartingEvent(eventName))
340346
err := s.apiClient.ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
341347
if err == nil {
342-
w.Event(progress.StartedEvent(getCanonicalContainerName(container)))
348+
w.Event(progress.StartedEvent(eventName))
343349
}
344350
return err
345351
})

local/compose/down.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
9292
func (s *composeService) stopContainers(ctx context.Context, w progress.Writer, containers []moby.Container) error {
9393
for _, container := range containers {
9494
toStop := container
95-
eventName := "Container " + getCanonicalContainerName(toStop)
95+
eventName := getContainerProgressName(toStop)
9696
w.Event(progress.StoppingEvent(eventName))
9797
err := s.apiClient.ContainerStop(ctx, toStop.ID, nil)
9898
if err != nil {
@@ -109,9 +109,11 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
109109
for _, container := range containers {
110110
toDelete := container
111111
eg.Go(func() error {
112-
eventName := "Container " + getCanonicalContainerName(toDelete)
113-
err := s.stopContainers(ctx, w, []moby.Container{container})
112+
eventName := getContainerProgressName(toDelete)
113+
w.Event(progress.StoppingEvent(eventName))
114+
err := s.stopContainers(ctx, w, []moby.Container{toDelete})
114115
if err != nil {
116+
w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
115117
return err
116118
}
117119
w.Event(progress.RemovingEvent(eventName))

0 commit comments

Comments
 (0)