use project we just created to start services

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2022-04-07 12:13:30 +02:00 committed by Nicolas De loof
parent 7fea9f7e8b
commit db698562a9
3 changed files with 15 additions and 9 deletions

View File

@ -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,

View File

@ -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

View File

@ -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