MCPcopy
hub / github.com/docker/compose / watch

Method watch

pkg/compose/watch.go:189–293  ·  view source on GitHub ↗
(ctx context.Context, project *types.Project, options api.WatchOptions)

Source from the content-addressed store, hash-verified

187}
188
189func (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 }

Callers 1

WatchMethod · 0.95

Calls 12

getSyncImplementationMethod · 0.95
initialSyncMethod · 0.95
StartMethod · 0.95
watchEventsMethod · 0.95
NewWatcherFunction · 0.92
loadDevelopmentConfigFunction · 0.85
isSyncFunction · 0.85
getWatchRulesFunction · 0.85
LogMethod · 0.65
WaitMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected