Skip to content

Commit e63cbfb

Browse files
committed
use tilt watcher to track filesystem changes
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 2557628 commit e63cbfb

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/docker/docker v20.10.20+incompatible // replaced; see replace rule for actual version
1717
github.com/docker/go-connections v0.4.0
1818
github.com/docker/go-units v0.5.0
19-
github.com/fsnotify/fsnotify v1.6.0
19+
github.com/fsnotify/fsnotify v1.6.0 // indirect
2020
github.com/golang/mock v1.6.0
2121
github.com/hashicorp/go-multierror v1.1.1
2222
github.com/hashicorp/go-version v1.6.0
@@ -153,8 +153,6 @@ require (
153153

154154
require go.uber.org/goleak v1.1.12
155155

156-
require github.com/fsnotify/fsevents v0.1.1
157-
158156
replace (
159157
// Override for e2e tests
160158
github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
205205
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
206206
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
207207
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
208-
github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=
209-
github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc=
210208
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
211209
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
212210
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=

pkg/compose/watch.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/compose-spec/compose-go/types"
2525
"github.com/docker/compose/v2/pkg/api"
2626
"github.com/docker/compose/v2/pkg/utils"
27-
"github.com/fsnotify/fsnotify"
27+
"github.com/docker/compose/v2/pkg/watch"
2828
"github.com/jonboulle/clockwork"
2929
"github.com/mitchellh/mapstructure"
3030
"github.com/pkg/errors"
@@ -88,25 +88,32 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
8888
}
8989
context := service.Build.Context
9090

91-
watcher, err := fsnotify.NewWatcher()
91+
ignore, err := watch.LoadDockerIgnore(context)
9292
if err != nil {
9393
return err
9494
}
95+
96+
watcher, err := watch.NewWatcher([]string{context}, ignore)
97+
if err != nil {
98+
return err
99+
}
100+
95101
fmt.Println("watching " + context)
96-
err = watcher.Add(context)
102+
err = watcher.Start()
97103
if err != nil {
98104
return err
99105
}
106+
100107
eg.Go(func() error {
101108
defer watcher.Close() //nolint:errcheck
102109
for {
103110
select {
104111
case <-ctx.Done():
105112
return nil
106-
case event := <-watcher.Events:
107-
log.Println("fs event :", event.String())
113+
case event := <-watcher.Events():
114+
log.Println("fs event :", event.Path())
108115
needRefresh <- service.Name
109-
case err := <-watcher.Errors:
116+
case err := <-watcher.Errors():
110117
return err
111118
}
112119
}

pkg/watch/dockerignore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (i dockerPathMatcher) MatchesEntireDir(f string) (bool, error) {
6060
return true, nil
6161
}
6262

63-
func NewDockerIgnoreTester(repoRoot string) (*dockerPathMatcher, error) {
63+
func LoadDockerIgnore(repoRoot string) (*dockerPathMatcher, error) {
6464
absRoot, err := filepath.Abs(repoRoot)
6565
if err != nil {
6666
return nil, err

pkg/watch/watcher_fsevent.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package watch
2121

22+
/**
23+
FIXME this implementation requires CGO
24+
2225
import (
2326
"path/filepath"
2427
"time"
@@ -155,3 +158,4 @@ func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, erro
155158
}
156159
157160
var _ Notify = &fseventNotify{}
161+
**/

0 commit comments

Comments
 (0)