瀏覽代碼

report error (re)creating container

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 6 月之前
父節點
當前提交
cc50ada725
共有 2 個文件被更改,包括 20 次插入5 次删除
  1. 20 4
      pkg/compose/convergence.go
  2. 0 1
      pkg/compose/pull.go

+ 20 - 4
pkg/compose/convergence.go

@@ -595,6 +595,13 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
 	w.Event(progress.CreatingEvent(eventName))
 	ctr, err = s.createMobyContainer(ctx, project, service, name, number, nil, opts, w)
 	if err != nil {
+		if ctx.Err() == nil {
+			w.Event(progress.Event{
+				ID:         eventName,
+				Status:     progress.Error,
+				StatusText: err.Error(),
+			})
+		}
 		return
 	}
 	w.Event(progress.CreatedEvent(eventName))
@@ -603,10 +610,19 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
 
 func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig,
 	replaced containerType.Summary, inherit bool, timeout *time.Duration,
-) (containerType.Summary, error) {
-	var created containerType.Summary
+) (created containerType.Summary, err error) {
 	w := progress.ContextWriter(ctx)
-	w.Event(progress.NewEvent(getContainerProgressName(replaced), progress.Working, "Recreate"))
+	eventName := getContainerProgressName(replaced)
+	w.Event(progress.NewEvent(eventName, progress.Working, "Recreate"))
+	defer func() {
+		if err != nil && ctx.Err() == nil {
+			w.Event(progress.Event{
+				ID:         eventName,
+				Status:     progress.Error,
+				StatusText: err.Error(),
+			})
+		}
+	}()
 
 	number, err := strconv.Atoi(replaced.Labels[api.ContainerNumberLabel])
 	if err != nil {
@@ -646,7 +662,7 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
 		return created, err
 	}
 
-	w.Event(progress.NewEvent(getContainerProgressName(replaced), progress.Done, "Recreated"))
+	w.Event(progress.NewEvent(eventName, progress.Done, "Recreated"))
 	return created, err
 }
 

+ 0 - 1
pkg/compose/pull.go

@@ -208,7 +208,6 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
 		w.Event(progress.Event{
 			ID:         service.Name,
 			Status:     progress.Warning,
-			Text:       "Warning",
 			StatusText: "Interrupted",
 		})
 		return "", nil