Skip to content

Commit 5ff524d

Browse files
committed
introduce watch.include
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 876ecc4 commit 5ff524d

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/Microsoft/go-winio v0.6.2
88
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
99
github.com/buger/goterm v1.0.4
10-
github.com/compose-spec/compose-go/v2 v2.4.9-0.20250225151507-331db8fefcb7
10+
github.com/compose-spec/compose-go/v2 v2.4.9-0.20250302154753-e508c724a35f
1111
github.com/containerd/containerd/v2 v2.0.2
1212
github.com/containerd/platforms v1.0.0-rc.1
1313
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e
8181
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
8282
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
8383
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
84-
github.com/compose-spec/compose-go/v2 v2.4.9-0.20250225151507-331db8fefcb7 h1:7NlxAsQcWvLpFlEHsBo80sJ1UMMs84kkf0yXGs6de2k=
85-
github.com/compose-spec/compose-go/v2 v2.4.9-0.20250225151507-331db8fefcb7/go.mod h1:6k5l/0TxCg0/2uLEhRVEsoBWBprS2uvZi32J7xub3lo=
84+
github.com/compose-spec/compose-go/v2 v2.4.9-0.20250302154753-e508c724a35f h1:kbmTPhf7d9kTnmH0ghAQTqxs1zenKnwKczJlC4z5WSc=
85+
github.com/compose-spec/compose-go/v2 v2.4.9-0.20250302154753-e508c724a35f/go.mod h1:6k5l/0TxCg0/2uLEhRVEsoBWBprS2uvZi32J7xub3lo=
8686
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
8787
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
8888
github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=

pkg/compose/watch.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
8181

8282
type watchRule struct {
8383
types.Trigger
84+
include watch.PathMatcher
8485
ignore watch.PathMatcher
8586
service string
8687
}
@@ -90,6 +91,15 @@ func (r watchRule) Matches(event watch.FileEvent) *sync.PathMapping {
9091
if !pathutil.IsChild(r.Path, hostPath) {
9192
return nil
9293
}
94+
included, err := r.include.Matches(hostPath)
95+
if err != nil {
96+
logrus.Warnf("error include matching %q: %v", hostPath, err)
97+
return nil
98+
}
99+
if !included {
100+
logrus.Debugf("%s is not matching include pattern", hostPath)
101+
return nil
102+
}
93103
isIgnored, err := r.ignore.Matches(hostPath)
94104
if err != nil {
95105
logrus.Warnf("error ignore matching %q: %v", hostPath, err)
@@ -244,8 +254,19 @@ func getWatchRules(config *types.DevelopConfig, service types.ServiceConfig) ([]
244254
return nil, err
245255
}
246256

257+
var include watch.PathMatcher
258+
if len(trigger.Include) == 0 {
259+
include = watch.AnyMatcher{}
260+
} else {
261+
include, err = watch.NewDockerPatternMatcher(trigger.Path, trigger.Include)
262+
if err != nil {
263+
return nil, err
264+
}
265+
}
266+
247267
rules = append(rules, watchRule{
248268
Trigger: trigger,
269+
include: include,
249270
ignore: watch.NewCompositeMatcher(
250271
dockerIgnores,
251272
watch.EphemeralPathMatcher(),

pkg/watch/notify.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ type PathMatcher interface {
6868
MatchesEntireDir(file string) (bool, error)
6969
}
7070

71+
// AnyMatcher is a PathMatcher to match any path
72+
type AnyMatcher struct{}
73+
74+
func (AnyMatcher) Matches(f string) (bool, error) { return true, nil }
75+
func (AnyMatcher) MatchesEntireDir(f string) (bool, error) { return true, nil }
76+
77+
var _ PathMatcher = AnyMatcher{}
78+
79+
// EmptyMatcher is a PathMatcher to match no path
7180
type EmptyMatcher struct{}
7281

7382
func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil }

0 commit comments

Comments
 (0)