Skip to content

Commit cc237ff

Browse files
committed
adjust code and dependencies
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent c0bdbb0 commit cc237ff

15 files changed

+637
-85
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ COPY --from=xx / /
3535
RUN apk add --no-cache \
3636
docker \
3737
file \
38+
findutils \
3839
git \
3940
make \
4041
protoc \

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
github.com/spf13/pflag v1.0.5
3434
github.com/stretchr/testify v1.8.1
3535
github.com/theupdateframework/notary v0.7.0
36+
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375
3637
go.opentelemetry.io/otel v1.12.0
3738
golang.org/x/sync v0.1.0
3839
gopkg.in/yaml.v2 v2.4.0
@@ -92,7 +93,7 @@ require (
9293
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
9394
github.com/miekg/pkcs11 v1.1.1 // indirect
9495
github.com/moby/locker v1.0.1 // indirect
95-
github.com/moby/patternmatcher v0.5.0 // indirect
96+
github.com/moby/patternmatcher v0.5.0
9697
github.com/moby/spdystream v0.2.0 // indirect
9798
github.com/moby/sys/sequential v0.5.0 // indirect
9899
github.com/moby/sys/signal v0.7.0 // indirect
@@ -152,6 +153,8 @@ require (
152153

153154
require go.uber.org/goleak v1.1.12
154155

156+
require github.com/fsnotify/fsevents v0.1.1
157+
155158
replace (
156159
// Override for e2e tests
157160
github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7

go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ 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=
208210
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
209211
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
210212
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
@@ -649,6 +651,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
649651
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
650652
github.com/theupdateframework/notary v0.7.0 h1:QyagRZ7wlSpjT5N2qQAh/pN+DVqgekv4DzbAiAiEL3c=
651653
github.com/theupdateframework/notary v0.7.0/go.mod h1:c9DRxcmhHmVLDay4/2fUYdISnHqbFDGRSlXPO0AhYWw=
654+
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 h1:QB54BJwA6x8QU9nHY3xJSZR2kX9bgpZekRKGkLTmEXA=
655+
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375/go.mod h1:xRroudyp5iVtxKqZCrA6n2TLFRBf8bmnjr1UD4x+z7g=
652656
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
653657
github.com/tonistiigi/fsutil v0.0.0-20220930225714-4638ad635be5 h1:NJ1nZs4j4XcBJKIY5sAwTGp9w5b78Zxr3+r0zXRuKnA=
654658
github.com/tonistiigi/fsutil v0.0.0-20220930225714-4638ad635be5/go.mod h1:F83XRhNblQsKQH9hcKEE45GAOkL9590mtw9KsD0Q4fE=
@@ -904,6 +908,7 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
904908
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
905909
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
906910
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
911+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
907912
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
908913
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
909914
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

pkg/watch/dockerignore.go

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package watch
18+
19+
import (
20+
"fmt"
21+
"os"
22+
"path/filepath"
23+
"strings"
24+
25+
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
26+
"github.com/moby/patternmatcher"
27+
)
28+
29+
type dockerPathMatcher struct {
30+
repoRoot string
31+
matcher *patternmatcher.PatternMatcher
32+
}
33+
34+
func (i dockerPathMatcher) Matches(f string) (bool, error) {
35+
if !filepath.IsAbs(f) {
36+
f = filepath.Join(i.repoRoot, f)
37+
}
38+
return i.matcher.Matches(f)
39+
}
40+
41+
func (i dockerPathMatcher) MatchesEntireDir(f string) (bool, error) {
42+
matches, err := i.Matches(f)
43+
if !matches || err != nil {
44+
return matches, err
45+
}
46+
47+
// We match the dir, but we might exclude files underneath it.
48+
if i.matcher.Exclusions() {
49+
for _, pattern := range i.matcher.Patterns() {
50+
if !pattern.Exclusion() {
51+
continue
52+
}
53+
if IsChild(f, pattern.String()) {
54+
// Found an exclusion match -- we don't match this whole dir
55+
return false, nil
56+
}
57+
}
58+
return true, nil
59+
}
60+
return true, nil
61+
}
62+
63+
func NewDockerIgnoreTester(repoRoot string) (*dockerPathMatcher, error) {
64+
absRoot, err := filepath.Abs(repoRoot)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
patterns, err := readDockerignorePatterns(absRoot)
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
return NewDockerPatternMatcher(absRoot, patterns)
75+
}
76+
77+
// Make all the patterns use absolute paths.
78+
func absPatterns(absRoot string, patterns []string) []string {
79+
absPatterns := make([]string, 0, len(patterns))
80+
for _, p := range patterns {
81+
// The pattern parsing here is loosely adapted from fileutils' NewPatternMatcher
82+
p = strings.TrimSpace(p)
83+
if p == "" {
84+
continue
85+
}
86+
p = filepath.Clean(p)
87+
88+
pPath := p
89+
isExclusion := false
90+
if p[0] == '!' {
91+
pPath = p[1:]
92+
isExclusion = true
93+
}
94+
95+
if !filepath.IsAbs(pPath) {
96+
pPath = filepath.Join(absRoot, pPath)
97+
}
98+
absPattern := pPath
99+
if isExclusion {
100+
absPattern = fmt.Sprintf("!%s", pPath)
101+
}
102+
absPatterns = append(absPatterns, absPattern)
103+
}
104+
return absPatterns
105+
}
106+
107+
func NewDockerPatternMatcher(repoRoot string, patterns []string) (*dockerPathMatcher, error) {
108+
absRoot, err := filepath.Abs(repoRoot)
109+
if err != nil {
110+
return nil, err
111+
}
112+
113+
pm, err := patternmatcher.New(absPatterns(absRoot, patterns))
114+
if err != nil {
115+
return nil, err
116+
}
117+
118+
return &dockerPathMatcher{
119+
repoRoot: absRoot,
120+
matcher: pm,
121+
}, nil
122+
}
123+
124+
func readDockerignorePatterns(repoRoot string) ([]string, error) {
125+
var excludes []string
126+
127+
f, err := os.Open(filepath.Join(repoRoot, ".dockerignore"))
128+
switch {
129+
case os.IsNotExist(err):
130+
return excludes, nil
131+
case err != nil:
132+
return nil, err
133+
}
134+
defer func() { _ = f.Close() }()
135+
136+
return dockerignore.ReadAll(f)
137+
}
138+
139+
func DockerIgnoreTesterFromContents(repoRoot string, contents string) (*dockerPathMatcher, error) {
140+
patterns, err := dockerignore.ReadAll(strings.NewReader(contents))
141+
if err != nil {
142+
return nil, err
143+
}
144+
145+
return NewDockerPatternMatcher(repoRoot, patterns)
146+
}

pkg/watch/notify.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package watch
218

319
import (
@@ -8,8 +24,6 @@ import (
824
"runtime"
925
"strconv"
1026
"strings"
11-
12-
"github.com/tilt-dev/tilt/pkg/logger"
1327
)
1428

1529
var (
@@ -68,8 +82,8 @@ func (EmptyMatcher) MatchesEntireDir(f string) (bool, error) { return false, nil
6882

6983
var _ PathMatcher = EmptyMatcher{}
7084

71-
func NewWatcher(paths []string, ignore PathMatcher, l logger.Logger) (Notify, error) {
72-
return newWatcher(paths, ignore, l)
85+
func NewWatcher(paths []string, ignore PathMatcher) (Notify, error) {
86+
return newWatcher(paths, ignore)
7387
}
7488

7589
const WindowsBufferSizeEnvVar = "TILT_WATCH_WINDOWS_BUFFER_SIZE"

0 commit comments

Comments
 (0)