diff --git a/cmd/compose/up.go b/cmd/compose/up.go index aebf53289..9e7e96c6f 100644 --- a/cmd/compose/up.go +++ b/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, diff --git a/pkg/api/api.go b/pkg/api/api.go index 3abe00626..510a1391e 100644 --- a/pkg/api/api.go +++ b/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 diff --git a/pkg/compose/start.go b/pkg/compose/start.go index 19e88e61c..4b1e3ed2d 100644 --- a/pkg/compose/start.go +++ b/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