Skip to content

Commit 373d0ad

Browse files
authored
Merge pull request #6534 from jsternberg/copy-ignored-file-linter-negated-matches
linter: do not attempt to check for copying ignored file when negated patterns exist
2 parents 9a083f4 + d4e025a commit 373d0ad

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,13 @@ func addReachableStages(s *dispatchState, stages map[*dispatchState]struct{}) {
20412041
}
20422042

20432043
func validateCopySourcePath(src string, cfg *copyConfig) error {
2044-
if cfg.ignoreMatcher == nil {
2044+
// Do not validate copy source paths if there is no dockerignore file
2045+
// or if the dockerignore file contains exclusions.
2046+
//
2047+
// Exclusions are too difficult to statically determine if they're proper
2048+
// because it's ok for a directory to be excluded and a file inside the directory
2049+
// to be negated.
2050+
if cfg.ignoreMatcher == nil || cfg.ignoreMatcher.Exclusions() {
20452051
return nil
20462052
}
20472053
cmd := "Copy"

frontend/dockerfile/dockerfile_lint_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ COPY ./Dockerfile .
230230
Dockerfile: dockerfile,
231231
DockerIgnore: dockerignore,
232232
})
233+
234+
// No warnings should occur if we copy the directory.
235+
dockerfile = []byte(`
236+
FROM scratch
237+
COPY . .
238+
`)
239+
checkLinterWarnings(t, sb, &lintTestParams{
240+
Dockerfile: dockerfile,
241+
DockerIgnore: dockerignore,
242+
})
233243
}
234244

235245
func testSecretsUsedInArgOrEnv(t *testing.T, sb integration.Sandbox) {

0 commit comments

Comments
 (0)