-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checks: add check for constant in from platform flag #5140
checks: add check for constant in from platform flag #5140
Conversation
fc7a908
to
989d184
Compare
@@ -315,6 +315,7 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS | |||
platMatch, err := shlex.ProcessWordWithMatches(v, platEnv) | |||
reportUnusedFromArgs(metaArgsKeys(optMetaArgs), platMatch.Unmatched, st.Location, lint) | |||
reportRedundantTargetPlatform(st.Platform, platMatch, st.Location, platEnv, lint) | |||
reportFromConstDisallowed(st.Name, platMatch, st.Location, lint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reportConstPlatformDisallowed
```dockerfile | ||
FROM --platform=${BUILDPLATFORM} alpine AS base | ||
RUN apk add --no-cache git | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this multi-stage example as good example:
FROM --platform=linux/amd64 alpine:3.20 AS build_amd64
...
FROM --platform=linux/arm64 alpine:3.19 AS build_arm64
...
FROM build_${TARGETARCH} AS build
...
...
## Output | ||
|
||
```text | ||
FROM --platform=linux/amd64 should not use a constant value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"FROM --platform flag should not ... " ?
|
||
* Omit `FROM --platform` in the Dockerfile and use the `--platform` argument on the command line. | ||
* Use `$BUILDPLATFORM` or some other combination of variables for the `--platform` argument. | ||
* Stage name should include the platform, OS, or architecture name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Stage name should include the platform, OS, or architecture name to indicate that it only contains platform-specific instructions"
c48d349
to
c644927
Compare
This linter rule triggers if a constant value has been used in the `FROM --platform` flag and the stage name doesn't contain the OS or architecture mentioned. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
c644927
to
58753e8
Compare
Test failure seems to be unrelated:
|
@jsternberg covered by #5142 |
This linter rule triggers if a constant value has been used in the
FROM --platform
flag and the stage name doesn't contain the OS orarchitecture mentioned.
Fixes #5131.