Ver Fonte

report docker resources creation in progress

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof há 5 anos atrás
pai
commit
0d33e5cdcc
1 ficheiros alterados com 45 adições e 0 exclusões
  1. 45 0
      local/compose.go

+ 45 - 0
local/compose.go

@@ -77,6 +77,13 @@ func (s *local) Up(ctx context.Context, project *types.Project, detach bool) err
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
+		w := progress.ContextWriter(ctx)
+		w.Event(progress.Event{
+			ID:         fmt.Sprintf("Service %q", service.Name),
+			Status:     progress.Working,
+			StatusText: "Create",
+			Done:       false,
+		})
 		name := fmt.Sprintf("%s_%s", project.Name, service.Name)
 		name := fmt.Sprintf("%s_%s", project.Name, service.Name)
 		id, err := s.containerService.create(ctx, containerConfig, hostConfig, networkingConfig, name)
 		id, err := s.containerService.create(ctx, containerConfig, hostConfig, networkingConfig, name)
 		if err != nil {
 		if err != nil {
@@ -89,10 +96,22 @@ func (s *local) Up(ctx context.Context, project *types.Project, detach bool) err
 				return err
 				return err
 			}
 			}
 		}
 		}
+		w.Event(progress.Event{
+			ID:         fmt.Sprintf("Service %q", service.Name),
+			Status:     progress.Working,
+			StatusText: "Start",
+			Done:       false,
+		})
 		err = s.containerService.apiClient.ContainerStart(ctx, id, moby.ContainerStartOptions{})
 		err = s.containerService.apiClient.ContainerStart(ctx, id, moby.ContainerStartOptions{})
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
+		w.Event(progress.Event{
+			ID:         fmt.Sprintf("Service %q", service.Name),
+			Status:     progress.Done,
+			StatusText: "Started",
+			Done:       true,
+		})
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -488,9 +507,22 @@ func (s *local) ensureNetwork(ctx context.Context, n types.NetworkConfig) error
 				}
 				}
 				createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
 				createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
 			}
 			}
+			w := progress.ContextWriter(ctx)
+			w.Event(progress.Event{
+				ID:         fmt.Sprintf("Network %q", n.Name),
+				Status:     progress.Working,
+				StatusText: "Create",
+				Done:       false,
+			})
 			if _, err := s.containerService.apiClient.NetworkCreate(context.Background(), n.Name, createOpts); err != nil {
 			if _, err := s.containerService.apiClient.NetworkCreate(context.Background(), n.Name, createOpts); err != nil {
 				return errors.Wrapf(err, "failed to create network %s", n.Name)
 				return errors.Wrapf(err, "failed to create network %s", n.Name)
 			}
 			}
+			w.Event(progress.Event{
+				ID:         fmt.Sprintf("Network %q", n.Name),
+				Status:     progress.Working,
+				StatusText: "Created",
+				Done:       true,
+			})
 			return nil
 			return nil
 		} else {
 		} else {
 			return err
 			return err
@@ -514,8 +546,21 @@ func (s *local) ensureVolume(ctx context.Context, volume types.VolumeConfig) err
 	_, err := s.volumeService.Inspect(ctx, volume.Name)
 	_, err := s.volumeService.Inspect(ctx, volume.Name)
 	if err != nil {
 	if err != nil {
 		if errdefs.IsNotFound(err) {
 		if errdefs.IsNotFound(err) {
+			w := progress.ContextWriter(ctx)
+			w.Event(progress.Event{
+				ID:         fmt.Sprintf("Volume %q", volume.Name),
+				Status:     progress.Working,
+				StatusText: "Create",
+				Done:       false,
+			})
 			// TODO we miss support for driver_opts and labels
 			// TODO we miss support for driver_opts and labels
 			_, err := s.volumeService.Create(ctx, volume.Name, nil)
 			_, err := s.volumeService.Create(ctx, volume.Name, nil)
+			w.Event(progress.Event{
+				ID:         fmt.Sprintf("Volume %q", volume.Name),
+				Status:     progress.Done,
+				StatusText: "Created",
+				Done:       true,
+			})
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}