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

Function getWatchRules

pkg/compose/watch.go:295–340  ·  view source on GitHub ↗
(config *types.DevelopConfig, service types.ServiceConfig)

Source from the content-addressed store, hash-verified

293}
294
295func getWatchRules(config *types.DevelopConfig, service types.ServiceConfig) ([]watchRule, error) {
296 var rules []watchRule
297
298 dockerIgnores, err := watch.LoadDockerIgnore(service.Build)
299 if err != nil {
300 return nil, err
301 }
302
303 // add a hardcoded set of ignores on top of what came from .dockerignore
304 // some of this should likely be configurable (e.g. there could be cases
305 // where you want `.git` to be synced) but this is suitable for now
306 dotGitIgnore, err := watch.NewDockerPatternMatcher("/", []string{".git/"})
307 if err != nil {
308 return nil, err
309 }
310
311 for _, trigger := range config.Watch {
312 ignore, err := watch.NewDockerPatternMatcher(trigger.Path, trigger.Ignore)
313 if err != nil {
314 return nil, err
315 }
316
317 var include watch.PathMatcher
318 if len(trigger.Include) == 0 {
319 include = watch.AnyMatcher{}
320 } else {
321 include, err = watch.NewDockerPatternMatcher(trigger.Path, trigger.Include)
322 if err != nil {
323 return nil, err
324 }
325 }
326
327 rules = append(rules, watchRule{
328 Trigger: trigger,
329 include: include,
330 ignore: watch.NewCompositeMatcher(
331 dockerIgnores,
332 watch.EphemeralPathMatcher(),
333 dotGitIgnore,
334 ignore,
335 ),
336 service: service.Name,
337 })
338 }
339 return rules, nil
340}
341
342func isSync(trigger types.Trigger) bool {
343 return trigger.Action == types.WatchActionSync || trigger.Action == types.WatchActionSyncRestart

Callers 2

TestWatch_SyncFunction · 0.85
watchMethod · 0.85

Calls 4

LoadDockerIgnoreFunction · 0.92
NewDockerPatternMatcherFunction · 0.92
NewCompositeMatcherFunction · 0.92
EphemeralPathMatcherFunction · 0.92

Tested by 1

TestWatch_SyncFunction · 0.68