Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore services without a build section #10271

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions pkg/compose/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Trigger struct {

const quietPeriod = 2 * time.Second

func (s *composeService) Watch(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error {
func (s *composeService) Watch(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error { //nolint:gocyclo
needRebuild := make(chan string)
needSync := make(chan api.CopyOptions, 5)

Expand All @@ -62,27 +62,37 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv

eg.Go(s.makeSyncFn(ctx, project, needSync))

err := project.WithServices(services, func(service types.ServiceConfig) error {
ss, err := project.GetServices(services...)
if err != nil {
return err
}
for _, service := range ss {
config, err := loadDevelopmentConfig(service, project)
if err != nil {
return err
}
name := service.Name
if service.Build == nil {
return errors.New("can't watch a service without a build section")
if len(services) != 0 || len(config.Watch) != 0 {
// watch explicitly requested on service, but no build section set
return fmt.Errorf("service %s doesn't have a build section", name)
}
logrus.Infof("service %s ignored. Can't watch a service without a build section", name)
continue
}
context := service.Build.Context
bc := service.Build.Context

ignore, err := watch.LoadDockerIgnore(context)
ignore, err := watch.LoadDockerIgnore(bc)
if err != nil {
return err
}

watcher, err := watch.NewWatcher([]string{context}, ignore)
watcher, err := watch.NewWatcher([]string{bc}, ignore)
if err != nil {
return err
}

fmt.Fprintf(s.stderr(), "watching %s\n", context)
fmt.Fprintf(s.stderr(), "watching %s\n", bc)
err = watcher.Start()
if err != nil {
return err
Expand Down Expand Up @@ -113,11 +123,11 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
dest := filepath.Join(trigger.Target, rel)
needSync <- api.CopyOptions{
Source: path,
Destination: fmt.Sprintf("%s:%s", service.Name, dest),
Destination: fmt.Sprintf("%s:%s", name, dest),
}
case WatchActionRebuild:
logrus.Debugf("modified file %s require image to be rebuilt", path)
needRebuild <- service.Name
needRebuild <- name
default:
return fmt.Errorf("watch action %q is not supported", trigger)
}
Expand All @@ -126,17 +136,13 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
}

// default
needRebuild <- service.Name
needRebuild <- name

case err := <-watcher.Errors():
return err
}
}
})
return nil
})
if err != nil {
return err
}

return eg.Wait()
Expand Down