-
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
Enhancement: print warnings when falling back from JSON to "shell" syntax (and other warnings) #1952
Comments
@tonistiigi happy to work on this, if you could provide some input on what approach would work best ( |
There is no support for sending warnings to the progressbar from a frontend. That would need to happen first. |
@tonistiigi wouldn't this do that? buildkit/frontend/dockerfile/parser/parser.go Lines 240 to 246 in 6b1c950
|
Related; cdalvaro/docker-salt-master#78 |
BuildKit; echo -e 'FROM scratch\nCOPY ["foo", "bar", "."' | docker build -
...
------
> [internal] load build context:
------
ERROR: failed to solve: rpc error: code = Unknown desc = invalid includepatterns: []: syntax error in pattern Compared to; echo -e 'FROM scratch\nCOPY ["foo", "bar", "."' | DOCKER_BUILDKIT=0 docker build -
...
Step 2/2 : COPY ["foo", "bar", "."
COPY failed: file not found in build context or excluded by .dockerignore: stat bar,: file does not exist I wonder if we have ways to surface more what happened; i.e., “we fell back to handling this as non-JSON”. or even “WARNING: did you mean xxx here?” because as a human, this LOOKS perfectly valid; COPY ["./foo", "."] # copy the foo dir Overall, I think we can be pretty confident that (specifically with |
Background
Some Dockerfile instructions support both JSON and "shell" form syntax. Dockerfile parser handles these by checking if the command contains a valid JSON, and otherwise considers it to be a "shell form". When falling back to "shell form", the command is used "as-is". Reason for this is that
[
is a valid command, and therefore the command could be valid;Writing valid JSON can be tricky, and user-mistakes, such as using single quotes instead of double quotes are easy to make;
While this behavior may be "by design", and technically correct, it's often confusing users. In many cases, running
[
is not the result the user was expecting, and many users are not aware of JSON requiring double-quotes, making it difficult for them to parse the error that's produced, and to locate the mistake;Suggested change
I suggest that we print an informational message to notify the user that we attempted to parse the Dockerfile instruction as JSON, but failed to parse it as valid JSON, and thus fell back to treating it as a shell instruction.
Implementation / changes needed
I had a quick look at what changes would be needed to implement this. The
parseMaybeJSON()
andparseMaybeJSONToList()
functions parse Dockerfile instructions that support either aJSON
array format ("exec form"), or a string format ("shell" form);buildkit/frontend/dockerfile/parser/line_parsers.go
Line 307 in 7bdb659
buildkit/frontend/dockerfile/parser/line_parsers.go
Line 329 in 7bdb659
Looking at that code, parsers currently can only return an error, but don't have a way to return non-fatal "warnings" or "informational" messages;
buildkit/frontend/dockerfile/parser/parser.go
Lines 176 to 182 in 6b1c950
buildkit/frontend/dockerfile/parser/parser.go
Lines 218 to 230 in 6b1c950
Nodes are collected in a
Result
, which does have aWarnings
property, but is currently only used to warn about empty continuation lines;buildkit/frontend/dockerfile/parser/parser.go
Lines 298 to 311 in 6b1c950
Looking at the above, I see two possible implementations;
parseMaybeJSON()
), andnewNodeFromLine()
Warnings
property to theNode
structThe warning would be added to
Result.Warnings
, together with the line number2.
would be consistent withResult.Warnings
, but I don't know if changing theNode
struct would have side-effects, so opening this ticket first to discuss options.The text was updated successfully, but these errors were encountered: