-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5091 from jsternberg/lint-redundant-target-platform
checks: add redundant target platform check
- Loading branch information
Showing
7 changed files
with
152 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
frontend/dockerfile/docs/rules/redundant-target-platform.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: RedundantTargetPlatform | ||
description: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior | ||
aliases: | ||
- /go/dockerfile/rule/redundant-target-platform/ | ||
--- | ||
|
||
## Output | ||
|
||
```text | ||
Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior | ||
``` | ||
|
||
## Description | ||
|
||
A custom platform can be used for a base image. The default platform is the | ||
same platform as the target output so setting the platform to `$TARGETPLATFORM` | ||
is redundant and unnecessary. | ||
|
||
## Examples | ||
|
||
❌ Bad: this usage of `--platform` is redundant since `$TARGETPLATFORM` is the default. | ||
|
||
```dockerfile | ||
FROM --platform=$TARGETPLATFORM alpine AS builder | ||
RUN apk add --no-cache git | ||
``` | ||
|
||
✅ Good: omit the `--platform` argument. | ||
|
||
```dockerfile | ||
FROM alpine AS builder | ||
RUN apk add --no-cache git | ||
``` | ||
|
27 changes: 27 additions & 0 deletions
27
frontend/dockerfile/linter/docs/RedundantTargetPlatform.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Output | ||
|
||
```text | ||
Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior | ||
``` | ||
|
||
## Description | ||
|
||
A custom platform can be used for a base image. The default platform is the | ||
same platform as the target output so setting the platform to `$TARGETPLATFORM` | ||
is redundant and unnecessary. | ||
|
||
## Examples | ||
|
||
❌ Bad: this usage of `--platform` is redundant since `$TARGETPLATFORM` is the default. | ||
|
||
```dockerfile | ||
FROM --platform=$TARGETPLATFORM alpine AS builder | ||
RUN apk add --no-cache git | ||
``` | ||
|
||
✅ Good: omit the `--platform` argument. | ||
|
||
```dockerfile | ||
FROM alpine AS builder | ||
RUN apk add --no-cache git | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters