Skip to content

Commit d127432

Browse files
committed
lint: add doc for UndefinedArgInFrom
Signed-off-by: David Karlsson <[email protected]>
1 parent aebcc1f commit d127432

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

frontend/dockerfile/docs/rules/undefined-arg-in-from.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,47 @@ aliases:
88
## Output
99

1010
```text
11+
FROM argument 'VARIANT' is not declared
1112
```
1213

1314
## Description
1415

16+
This rule warns for cases where you're consuming an undefined build argument in
17+
`FROM` instructions.
18+
19+
Interpolating build arguments in `FROM` instructions can be a good way to add
20+
flexibility to your build, and lets you pass arguments that overriding the base
21+
image of a stage. For example, you might use a build argument to specify the
22+
image tag:
23+
24+
```dockerfile
25+
ARG ALPINE_VERSION=3.20
26+
27+
FROM alpine:${ALPINE_VERSION}
28+
```
29+
30+
This makes it possible to run the build with a different `alpine` version by
31+
specifying a build argument:
32+
33+
```console
34+
$ docker buildx build --build-arg ALPINE_VERSION=edge .
35+
```
36+
37+
This check also tries to detect and warn when a `FROM` instruction reference
38+
miss-spelled built-in build arguments, like `BUILDPLATFORM`.
39+
1540
## Examples
1641

17-
❌ Bad
42+
❌ Bad: the `VARIANT` build argument is undefined.
1843

1944
```dockerfile
45+
FROM node:22${VARIANT} AS jsbuilder
2046
```
2147

22-
✅ Good
48+
✅ Good: the `VARIANT` build argument is defined.
2349

2450
```dockerfile
51+
ARG VARIANT="-alpine3.20"
52+
FROM node:22${VARIANT} AS jsbuilder
2553
```
2654

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
11
## Output
22

33
```text
4+
FROM argument 'VARIANT' is not declared
45
```
56

67
## Description
78

9+
This rule warns for cases where you're consuming an undefined build argument in
10+
`FROM` instructions.
11+
12+
Interpolating build arguments in `FROM` instructions can be a good way to add
13+
flexibility to your build, and lets you pass arguments that overriding the base
14+
image of a stage. For example, you might use a build argument to specify the
15+
image tag:
16+
17+
```dockerfile
18+
ARG ALPINE_VERSION=3.20
19+
20+
FROM alpine:${ALPINE_VERSION}
21+
```
22+
23+
This makes it possible to run the build with a different `alpine` version by
24+
specifying a build argument:
25+
26+
```console
27+
$ docker buildx build --build-arg ALPINE_VERSION=edge .
28+
```
29+
30+
This check also tries to detect and warn when a `FROM` instruction reference
31+
miss-spelled built-in build arguments, like `BUILDPLATFORM`.
32+
833
## Examples
934

10-
❌ Bad
35+
❌ Bad: the `VARIANT` build argument is undefined.
1136

1237
```dockerfile
38+
FROM node:22${VARIANT} AS jsbuilder
1339
```
1440

15-
✅ Good
41+
✅ Good: the `VARIANT` build argument is defined.
1642

1743
```dockerfile
44+
ARG VARIANT="-alpine3.20"
45+
FROM node:22${VARIANT} AS jsbuilder
1846
```

0 commit comments

Comments
 (0)