mirror of
https://github.com/docker/compose.git
synced 2025-07-28 16:14:06 +02:00
ignore services without a build section
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
5e3e2171d4
commit
313b82e94c
@ -49,7 +49,7 @@ type Trigger struct {
|
|||||||
|
|
||||||
const quietPeriod = 2 * time.Second
|
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)
|
needRebuild := make(chan string)
|
||||||
needSync := make(chan api.CopyOptions, 5)
|
needSync := make(chan api.CopyOptions, 5)
|
||||||
|
|
||||||
@ -62,27 +62,37 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
|
|||||||
|
|
||||||
eg.Go(s.makeSyncFn(ctx, project, needSync))
|
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)
|
config, err := loadDevelopmentConfig(service, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
name := service.Name
|
||||||
if service.Build == nil {
|
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)
|
||||||
}
|
}
|
||||||
context := service.Build.Context
|
logrus.Infof("service %s ignored. Can't watch a service without a build section", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bc := service.Build.Context
|
||||||
|
|
||||||
ignore, err := watch.LoadDockerIgnore(context)
|
ignore, err := watch.LoadDockerIgnore(bc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
watcher, err := watch.NewWatcher([]string{context}, ignore)
|
watcher, err := watch.NewWatcher([]string{bc}, ignore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(s.stderr(), "watching %s\n", context)
|
fmt.Fprintf(s.stderr(), "watching %s\n", bc)
|
||||||
err = watcher.Start()
|
err = watcher.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -113,11 +123,11 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
|
|||||||
dest := filepath.Join(trigger.Target, rel)
|
dest := filepath.Join(trigger.Target, rel)
|
||||||
needSync <- api.CopyOptions{
|
needSync <- api.CopyOptions{
|
||||||
Source: path,
|
Source: path,
|
||||||
Destination: fmt.Sprintf("%s:%s", service.Name, dest),
|
Destination: fmt.Sprintf("%s:%s", name, dest),
|
||||||
}
|
}
|
||||||
case WatchActionRebuild:
|
case WatchActionRebuild:
|
||||||
logrus.Debugf("modified file %s require image to be rebuilt", path)
|
logrus.Debugf("modified file %s require image to be rebuilt", path)
|
||||||
needRebuild <- service.Name
|
needRebuild <- name
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("watch action %q is not supported", trigger)
|
return fmt.Errorf("watch action %q is not supported", trigger)
|
||||||
}
|
}
|
||||||
@ -126,17 +136,13 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default
|
// default
|
||||||
needRebuild <- service.Name
|
needRebuild <- name
|
||||||
|
|
||||||
case err := <-watcher.Errors():
|
case err := <-watcher.Errors():
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return eg.Wait()
|
return eg.Wait()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user