Skip to content

Commit 5485103

Browse files
authored
Merge pull request #6362 from jsternberg/linter-promote-experimental-rules
dockerfile: promote experimental linter rule
2 parents 3441ded + 4187c34 commit 5485103

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

frontend/dockerfile/dockerfile_lint_test.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var lintTests = integration.TestFuncs(
5454
)
5555

5656
func testDefinitionDescription(t *testing.T, sb integration.Sandbox) {
57-
dockerfile := []byte(`# check=experimental=InvalidDefinitionDescription
57+
dockerfile := []byte(`# check=skip=all;experimental=InvalidDefinitionDescription
5858
# foo this is the foo
5959
ARG foo=bar
6060
@@ -131,18 +131,6 @@ Dockerfile
131131
FROM scratch
132132
COPY Dockerfile .
133133
ADD Dockerfile /windy
134-
`)
135-
checkLinterWarnings(t, sb, &lintTestParams{
136-
Dockerfile: dockerfile,
137-
DockerIgnore: dockerignore,
138-
BuildErrLocation: 3,
139-
StreamBuildErrRegexp: regexp.MustCompile(`failed to solve: failed to compute cache key: failed to calculate checksum of ref [^\s]+ "/Dockerfile": not found`),
140-
})
141-
142-
dockerfile = []byte(`# check=experimental=CopyIgnoredFile
143-
FROM scratch
144-
COPY Dockerfile .
145-
ADD Dockerfile /windy
146134
`)
147135

148136
checkLinterWarnings(t, sb, &lintTestParams{
@@ -170,7 +158,7 @@ ADD Dockerfile /windy
170158
},
171159
})
172160

173-
dockerfile = []byte(`# check=skip=all;experimental=CopyIgnoredFile
161+
dockerfile = []byte(`
174162
FROM scratch
175163
COPY Dockerfile .
176164
ADD Dockerfile /windy
@@ -201,6 +189,19 @@ ADD Dockerfile /windy
201189
},
202190
})
203191

192+
dockerfile = []byte(`# check=skip=CopyIgnoredFile
193+
194+
FROM scratch
195+
COPY Dockerfile .
196+
ADD Dockerfile /windy
197+
`)
198+
checkLinterWarnings(t, sb, &lintTestParams{
199+
Dockerfile: dockerfile,
200+
DockerIgnore: dockerignore,
201+
BuildErrLocation: 3,
202+
StreamBuildErrRegexp: regexp.MustCompile(`failed to solve: failed to compute cache key: failed to calculate checksum of ref [^\s]+ "/Dockerfile": not found`),
203+
})
204+
204205
dockerignore = []byte(`
205206
foobar
206207
`)
@@ -232,7 +233,8 @@ COPY ./Dockerfile .
232233
}
233234

234235
func testSecretsUsedInArgOrEnv(t *testing.T, sb integration.Sandbox) {
235-
dockerfile := []byte(`
236+
dockerfile := []byte(`# check=skip=InvalidDefinitionDescription
237+
236238
FROM scratch
237239
ARG SECRET_PASSPHRASE
238240
ENV SUPER_Secret=foo
@@ -260,63 +262,63 @@ ARG alternate_password
260262
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "SECRET_PASSPHRASE")`,
261263
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
262264
Level: 1,
263-
Line: 3,
265+
Line: 4,
264266
},
265267
{
266268
RuleName: "SecretsUsedInArgOrEnv",
267269
Description: "Sensitive data should not be used in the ARG or ENV commands",
268270
Detail: `Do not use ARG or ENV instructions for sensitive data (ENV "SUPER_Secret")`,
269271
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
270272
Level: 1,
271-
Line: 4,
273+
Line: 5,
272274
},
273275
{
274276
RuleName: "SecretsUsedInArgOrEnv",
275277
Description: "Sensitive data should not be used in the ARG or ENV commands",
276278
Detail: `Do not use ARG or ENV instructions for sensitive data (ENV "password")`,
277279
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
278280
Level: 1,
279-
Line: 5,
281+
Line: 6,
280282
},
281283
{
282284
RuleName: "SecretsUsedInArgOrEnv",
283285
Description: "Sensitive data should not be used in the ARG or ENV commands",
284286
Detail: `Do not use ARG or ENV instructions for sensitive data (ENV "secret")`,
285287
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
286288
Level: 1,
287-
Line: 5,
289+
Line: 6,
288290
},
289291
{
290292
RuleName: "SecretsUsedInArgOrEnv",
291293
Description: "Sensitive data should not be used in the ARG or ENV commands",
292294
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "auth")`,
293295
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
294296
Level: 1,
295-
Line: 6,
297+
Line: 7,
296298
},
297299
{
298300
RuleName: "SecretsUsedInArgOrEnv",
299301
Description: "Sensitive data should not be used in the ARG or ENV commands",
300302
Detail: `Do not use ARG or ENV instructions for sensitive data (ARG "super_duper_secret_token")`,
301303
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
302304
Level: 1,
303-
Line: 6,
305+
Line: 7,
304306
},
305307
{
306308
RuleName: "SecretsUsedInArgOrEnv",
307309
Description: "Sensitive data should not be used in the ARG or ENV commands",
308310
Detail: `Do not use ARG or ENV instructions for sensitive data (ENV "apikey")`,
309311
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
310312
Level: 1,
311-
Line: 7,
313+
Line: 8,
312314
},
313315
{
314316
RuleName: "SecretsUsedInArgOrEnv",
315317
Description: "Sensitive data should not be used in the ARG or ENV commands",
316318
Detail: `Do not use ARG or ENV instructions for sensitive data (ENV "git_key")`,
317319
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
318320
Level: 1,
319-
Line: 8,
321+
Line: 9,
320322
},
321323
},
322324
})
@@ -1692,8 +1694,9 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes
16921694
} else {
16931695
if lintTest.BuildErr != "" {
16941696
require.ErrorContains(t, err, lintTest.BuildErr)
1695-
} else if !lintTest.StreamBuildErrRegexp.MatchString(err.Error()) {
1696-
t.Fatalf("error %q does not match %q", err.Error(), lintTest.StreamBuildErrRegexp.String())
1697+
} else {
1698+
require.Error(t, err)
1699+
require.Regexp(t, lintTest.StreamBuildErrRegexp, err)
16971700
}
16981701
}
16991702

@@ -1745,10 +1748,10 @@ func checkLinterWarnings(t *testing.T, sb integration.Sandbox, lintTest *lintTes
17451748

17461749
if lintTest.TmpDir == nil {
17471750
testfiles := []fstest.Applier{
1748-
fstest.CreateFile("Dockerfile", lintTest.Dockerfile, 0600),
1751+
fstest.CreateFile("Dockerfile", lintTest.Dockerfile, 0o600),
17491752
}
17501753
if lintTest.DockerIgnore != nil {
1751-
testfiles = append(testfiles, fstest.CreateFile(".dockerignore", lintTest.DockerIgnore, 0600))
1754+
testfiles = append(testfiles, fstest.CreateFile(".dockerignore", lintTest.DockerIgnore, 0o600))
17521755
}
17531756
lintTest.TmpDir = integration.Tmpdir(
17541757
t,

frontend/dockerfile/docs/rules/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ To learn more about how to use build checks, see
100100
<td>FROM --platform flag should not use a constant value</td>
101101
</tr>
102102
<tr>
103-
<td><a href="./copy-ignored-file/">CopyIgnoredFile (experimental)</a></td>
103+
<td><a href="./copy-ignored-file/">CopyIgnoredFile</a></td>
104104
<td>Attempting to Copy file that is excluded by .dockerignore</td>
105105
</tr>
106106
<tr>

frontend/dockerfile/docs/rules/copy-ignored-file.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ aliases:
66
- /go/dockerfile/rule/copy-ignored-file/
77
---
88

9-
> [!NOTE]
10-
> This check is experimental and is not enabled by default. To enable it, see
11-
> [Experimental checks](https://docs.docker.com/go/build-checks-experimental/).
12-
139
## Output
1410

1511
```text

frontend/dockerfile/linter/ruleset.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ var (
163163
Format: func(cmd, file string) string {
164164
return fmt.Sprintf("Attempting to %s file %q that is excluded by .dockerignore", cmd, file)
165165
},
166-
Experimental: true,
167166
}
168167
RuleInvalidDefinitionDescription = LinterRule[func(string, string) string]{
169168
Name: "InvalidDefinitionDescription",

0 commit comments

Comments
 (0)