Browse Source

use project we just created to start services

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 3 years ago
parent
commit
db698562a9
3 changed files with 15 additions and 9 deletions
  1. 1 0
      cmd/compose/up.go
  2. 2 0
      pkg/api/api.go
  3. 12 9
      pkg/compose/start.go

+ 1 - 0
cmd/compose/up.go

@@ -204,6 +204,7 @@ func runUp(ctx context.Context, backend api.Service, createOptions createOptions
 	return backend.Up(ctx, project, api.UpOptions{
 		Create: create,
 		Start: api.StartOptions{
+			Project:      project,
 			Attach:       consumer,
 			AttachTo:     attachTo,
 			ExitCodeFrom: upOptions.exitCodeFrom,

+ 2 - 0
pkg/api/api.go

@@ -117,6 +117,8 @@ type CreateOptions struct {
 
 // StartOptions group options of the Start API
 type StartOptions struct {
+	// Project is the compose project used to define this app. Might be nil if user ran `start` just with project name
+	Project *types.Project
 	// Attach to container and forward logs if not nil
 	Attach LogConsumer
 	// AttachTo set the services to attach to

+ 12 - 9
pkg/compose/start.go

@@ -35,15 +35,18 @@ func (s *composeService) Start(ctx context.Context, projectName string, options
 }
 
 func (s *composeService) start(ctx context.Context, projectName string, options api.StartOptions, listener api.ContainerEventListener) error {
-	var containers Containers
-	containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
-	if err != nil {
-		return err
-	}
+	project := options.Project
+	if project == nil {
+		var containers Containers
+		containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
+		if err != nil {
+			return err
+		}
 
-	project, err := s.projectFromName(containers, projectName, options.AttachTo...)
-	if err != nil {
-		return err
+		project, err = s.projectFromName(containers, projectName, options.AttachTo...)
+		if err != nil {
+			return err
+		}
 	}
 
 	eg, ctx := errgroup.WithContext(ctx)
@@ -60,7 +63,7 @@ func (s *composeService) start(ctx context.Context, projectName string, options
 		})
 	}
 
-	err = InDependencyOrder(ctx, project, func(c context.Context, name string) error {
+	err := InDependencyOrder(ctx, project, func(c context.Context, name string) error {
 		service, err := project.GetService(name)
 		if err != nil {
 			return err