(ctx context.Context, project *types.Project, options api.WatchOptions)
| 187 | } |
| 188 | |
| 189 | func (s *composeService) watch(ctx context.Context, project *types.Project, options api.WatchOptions) (func() error, error) { //nolint: gocyclo |
| 190 | var err error |
| 191 | if project, err = project.WithSelectedServices(options.Services); err != nil { |
| 192 | return nil, err |
| 193 | } |
| 194 | syncer, err := s.getSyncImplementation(project) |
| 195 | if err != nil { |
| 196 | return nil, err |
| 197 | } |
| 198 | eg, ctx := errgroup.WithContext(ctx) |
| 199 | |
| 200 | var ( |
| 201 | rules []watchRule |
| 202 | paths []string |
| 203 | ) |
| 204 | for serviceName, service := range project.Services { |
| 205 | config, err := loadDevelopmentConfig(service, project) |
| 206 | if err != nil { |
| 207 | return nil, err |
| 208 | } |
| 209 | |
| 210 | if service.Develop != nil { |
| 211 | config = service.Develop |
| 212 | } |
| 213 | |
| 214 | if config == nil { |
| 215 | continue |
| 216 | } |
| 217 | |
| 218 | for _, trigger := range config.Watch { |
| 219 | if trigger.Action == types.WatchActionRebuild { |
| 220 | if service.Build == nil { |
| 221 | return nil, fmt.Errorf("can't watch service %q with action %s without a build context", service.Name, types.WatchActionRebuild) |
| 222 | } |
| 223 | if options.Build == nil { |
| 224 | return nil, fmt.Errorf("--no-build is incompatible with watch action %s in service %s", types.WatchActionRebuild, service.Name) |
| 225 | } |
| 226 | // set the service to always be built - watch triggers `Up()` when it receives a rebuild event |
| 227 | service.PullPolicy = types.PullPolicyBuild |
| 228 | project.Services[serviceName] = service |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | for _, trigger := range config.Watch { |
| 233 | if isSync(trigger) && checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) { |
| 234 | logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path) |
| 235 | continue |
| 236 | } else { |
| 237 | shouldInitialSync := trigger.InitialSync |
| 238 | |
| 239 | // Check legacy extension attribute for backward compatibility |
| 240 | if !shouldInitialSync { |
| 241 | var legacyInitialSync bool |
| 242 | success, err := trigger.Extensions.Get("x-initialSync", &legacyInitialSync) |
| 243 | if err == nil && success && legacyInitialSync { |
| 244 | shouldInitialSync = true |
| 245 | logrus.Warnf("x-initialSync is DEPRECATED, please use the official `initial_sync` attribute\n") |
| 246 | } |
no test coverage detected