Skip to content

Commit

Permalink
Merge pull request #5003 from dvdksn/doc-UndefinedArgInFrom
Browse files Browse the repository at this point in the history
lint: add doc for UndefinedArgInFrom
  • Loading branch information
crazy-max authored Jun 7, 2024
2 parents aebcc1f + d127432 commit efcde2f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
32 changes: 30 additions & 2 deletions frontend/dockerfile/docs/rules/undefined-arg-in-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,47 @@ aliases:
## Output

```text
FROM argument 'VARIANT' is not declared
```

## Description

This rule warns for cases where you're consuming an undefined build argument in
`FROM` instructions.

Interpolating build arguments in `FROM` instructions can be a good way to add
flexibility to your build, and lets you pass arguments that overriding the base
image of a stage. For example, you might use a build argument to specify the
image tag:

```dockerfile
ARG ALPINE_VERSION=3.20

FROM alpine:${ALPINE_VERSION}
```

This makes it possible to run the build with a different `alpine` version by
specifying a build argument:

```console
$ docker buildx build --build-arg ALPINE_VERSION=edge .
```

This check also tries to detect and warn when a `FROM` instruction reference
miss-spelled built-in build arguments, like `BUILDPLATFORM`.

## Examples

❌ Bad
❌ Bad: the `VARIANT` build argument is undefined.

```dockerfile
FROM node:22${VARIANT} AS jsbuilder
```

✅ Good
✅ Good: the `VARIANT` build argument is defined.

```dockerfile
ARG VARIANT="-alpine3.20"
FROM node:22${VARIANT} AS jsbuilder
```

32 changes: 30 additions & 2 deletions frontend/dockerfile/linter/docs/UndefinedArgInFrom.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
## Output

```text
FROM argument 'VARIANT' is not declared
```

## Description

This rule warns for cases where you're consuming an undefined build argument in
`FROM` instructions.

Interpolating build arguments in `FROM` instructions can be a good way to add
flexibility to your build, and lets you pass arguments that overriding the base
image of a stage. For example, you might use a build argument to specify the
image tag:

```dockerfile
ARG ALPINE_VERSION=3.20

FROM alpine:${ALPINE_VERSION}
```

This makes it possible to run the build with a different `alpine` version by
specifying a build argument:

```console
$ docker buildx build --build-arg ALPINE_VERSION=edge .
```

This check also tries to detect and warn when a `FROM` instruction reference
miss-spelled built-in build arguments, like `BUILDPLATFORM`.

## Examples

❌ Bad
❌ Bad: the `VARIANT` build argument is undefined.

```dockerfile
FROM node:22${VARIANT} AS jsbuilder
```

✅ Good
✅ Good: the `VARIANT` build argument is defined.

```dockerfile
ARG VARIANT="-alpine3.20"
FROM node:22${VARIANT} AS jsbuilder
```

0 comments on commit efcde2f

Please sign in to comment.