-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
dockerfile: add suggestions to how to fix certain errors #2218
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
277517e
add error suggest pkg
tonistiigi 768a12b
dockerfile: suggest mistyped flag names
tonistiigi df9781b
dockerfile: provide suggestions for mount options
tonistiigi de5e108
dockerfile: add tests for error suggestions
tonistiigi 4e41528
dockerfile: remove unnecessary error wrappings
tonistiigi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"github.com/moby/buildkit/frontend/dockerfile/shell" | ||
"github.com/moby/buildkit/solver/pb" | ||
"github.com/moby/buildkit/util/apicaps" | ||
"github.com/moby/buildkit/util/suggest" | ||
"github.com/moby/buildkit/util/system" | ||
specs "github.com/opencontainers/image-spec/specs-go/v1" | ||
"github.com/pkg/errors" | ||
|
@@ -216,6 +217,13 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, | |
allDispatchStates.states[0].stageName = "" | ||
} | ||
|
||
allStageNames := make([]string, 0, len(allDispatchStates.states)) | ||
for _, s := range allDispatchStates.states { | ||
if s.stageName != "" { | ||
allStageNames = append(allStageNames, s.stageName) | ||
} | ||
} | ||
|
||
eg, ctx := errgroup.WithContext(ctx) | ||
for i, d := range allDispatchStates.states { | ||
reachable := isReachable(target, d) | ||
|
@@ -233,6 +241,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, | |
err = parser.WithLocation(err, d.stage.Location) | ||
} | ||
}() | ||
origName := d.stage.BaseName | ||
ref, err := reference.ParseNormalizedNamed(d.stage.BaseName) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse stage name %q", d.stage.BaseName) | ||
|
@@ -243,7 +252,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, | |
} | ||
d.stage.BaseName = reference.TagNameOnly(ref).String() | ||
var isScratch bool | ||
if metaResolver != nil && reachable && !d.unregistered { | ||
if metaResolver != nil && reachable { | ||
prefix := "[" | ||
if opt.PrefixPlatform && platform != nil { | ||
prefix += platforms.Format(*platform) + " " | ||
|
@@ -255,7 +264,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, | |
LogName: fmt.Sprintf("%s load metadata for %s", prefix, d.stage.BaseName), | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, d.stage.BaseName) | ||
return suggest.WrapError(errors.Wrap(err, origName), origName, append(allStageNames, commonImageNames()...), true) | ||
} | ||
var img Image | ||
if err := json.Unmarshal(dt, &img); err != nil { | ||
|
@@ -1535,3 +1544,14 @@ func summarizeHeredoc(doc string) string { | |
} | ||
return summary | ||
} | ||
|
||
func commonImageNames() []string { | ||
repos := []string{ | ||
"alpine", "busybox", "centos", "debian", "golang", "ubuntu", "fedora", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CentOS is about to die soon :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I noticed this is used only for typo-checking, so it's fine to retain |
||
} | ||
out := make([]string, 0, len(repos)*4) | ||
for _, name := range repos { | ||
out = append(out, name, "docker.io/library"+name, name+":latest", "docker.io/library"+name+":latest") | ||
} | ||
return out | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Copy from image will now load image config here although it is not needed to get an error in the correct place. The config would have been still downloaded together with the image layers before.