-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Fix dockerfile parser with empty line after escape #24725
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
Fix dockerfile parser with empty line after escape #24725
Conversation
|
actually, looks like tests are failing, need to look more into this ping @duglin |
|
Looks like tests are failing, think there may be more to look into |
|
Don't have time right now to full review but I do recall that we had some really funky rules w.r.t. auto-continuing lines when they're blank. Wouldn't surprise me if the failures are related to that. And the last time we thought about "fixing" this we didn't because we didn't want to break existing Dockerfiles that might count on this odd behavior. |
|
Yes, I was wondering, perhaps we strip the continuation character before we arrive here, in case this may see |
|
Thanks @duglin @thaJeztah. The failed test has the following file: and expect the result to be: In other words, the previous behavior of docker considers empty lines (and comments) as continuation. And you could place many empty lines (or comment) in between: The result of the above would be one command RUN: I think it makes sense to at least not allow empty lines to continue as it is quite misleading. People may place an escape by mistake, then it will continue forever, no matter how many empty lines have passed. We could keep the comment for continuation to not break many existing behaviors, i.e., will be and the old behavior is maintained in this case. I updated pull request for the test cases to allow the test pass. But let me know the best way to handle them in these situations, or we could leave the old behavior alone if needed. |
|
Sounds good, but we may want to look at the history of that test; if it was testing a specific case, or just confirming "broken" behavior |
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.
This comment makes me believe this was intentional functionality.
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.
yes this was intentionally weird and while I'm 100% in favor of "fixing" this, it needs to be discussed by the maintainers because this was purposely kept weird all this time.
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.
Let's remove, or edit, this comment to be more accurate
|
I think that the bug is not with our treatment of multi-line commands, but with comments: Currently the |
|
@cyphar yes, it surprised be that the If we stick to that then, in this case, the I'm not sure why we ever wanted to support the blank lines though, or if that was a bug in the past, that we decided to keep supporting |
|
TBH, I do actually prefer more lax commenting. It's weird to me (coming from shell scripts) that |
|
Looks like the blank line behavior was introduced here; #8580 |
|
@cyphar it's because everything inside the |
|
Thanks @cyphar @thaJeztah. Not knowing enough history of docker, I can only guess the reason comment line is continued might be related to the ambiguity when For example, in case of and The outputs of the above likely depends on if we parse from the left, or parse from the right. So continuation with comment lines avoids the issue mentioned above. Again, I don't know enough history of docker so I could be totally wrong here. On the other hand, I feel like the continuation on empty line is quite misleading. The issue is that, if the user adds an escape |
|
I personally don't like the fact that we are acting differently to shells with Also, please note that we don't actually support comments at the end of lines. We only support comments if the |
|
What are we doing with this? |
|
my vote is to "fix" this but since it has been this way for ages (intentionally) we'd need agreement to break backwards compatibility. |
|
to be clear, I'd like to see two fixes:
While I think supporting comments at the end of lines would be good, that's a bigger change that would be trickier since we don't have a formal "end of statement" in Dockerfiles so knowing when "#" isn't part of the RUN command itself could be tricky. So for now I think doing the two things above would be a good first step. |
5789bfa to
d442830
Compare
543d1e1 to
759f845
Compare
|
@thaJeztah that's fine - its just that this PR migrated a bit into fixing some of the oddities in our parser so I tossed in one that was related. Either way is fine with me. |
|
@duglin thanks - I wasn't sure if everyone would be on board with changing that, and potentially block this PR (which is already quite old) from being merged. @yongtang could you keep the change for comments out of this PR, that way I hope we'd be able to get this moving forward quicker. I'm open to doing it in a separate PR so that it can be discussed separately |
4512ca7 to
01421e9
Compare
|
Thanks @duglin @thaJeztah. The PR has been updated so that now only |
|
The current version seems to correctly break the continuation sequence. Provided that we're still ok to have a subsequent PR to fix the rest, LGTM ping @duglin @thaJeztah |
This fix tries to fix the bug reported by moby#24693 where an empty line after escape will not be stopped by the parser. This fix addresses this issue by stop the parser from continue with an empty line after escape. An additional integration test has been added. This fix fixes moby#24693. Signed-off-by: Yong Tang <[email protected]>
01421e9 to
3e1b539
Compare
|
The PR has been rebased to fix the merge conflict. All tests passed. Ping @duglin @thaJeztah |
|
LGTM |
thaJeztah
left a comment
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.
LGTM
|
This is a pretty huge breaking change for The failure mode is pretty awful too; here's an example error from trying to build one of the $ docker version
Client:
Version: 1.13.0-rc2
API version: 1.25
Go version: go1.7.3
Git commit: 1f9b3ef
Built: Wed Nov 23 17:40:58 2016
OS/Arch: linux/amd64
Server:
Version: 1.13.0-rc2
API version: 1.25
Minimum API version: 1.12
Go version: go1.7.3
Git commit: 1f9b3ef
Built: Wed Nov 23 17:40:58 2016
OS/Arch: linux/amd64
Experimental: false
$ docker build 7.0/alpine
Sending build context to Docker daemon 13.82 kB
Error response from daemon: Unknown instruction: --ENABLE-FTP |
|
For reference, here's the exact line that's failing on: https://github.com/docker-library/php/blob/7d058f79e6fdf7b8e97d5004d1098c436d348a47/7.0/alpine/Dockerfile#L97 |
|
|
||
| this is some more useful stuff | ||
| # this is a comment that breaks escape continuation | ||
| RUN echo this is some more useful stuff |
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.
This is the offending test change -- a comment by itself should still be valid in the middle of a continuation (very, very common, useful pattern, supported by Docker for ages now).
|
@tianon @duglin
will result in (many empty lines will continue):
will result in (may comment lines will continue): This PR changed both based on discussions. If there are concerns with "no-continuation-for-comments", maybe we could revert back? We probably could keep the other changes "no-continuation-for-empty-lines" alone as it is confusing. The reason is that, in case an user have placed a Alternatively, I am wondering if it makes sense to add a |
|
@yongtang was discussing with Tianon; problem is here; https://github.com/docker/docker/pull/24725/files#diff-a70e690b6dc1bcdbae36a5f54c868bbeR183 It breaks on a comment line, but should probably detect if it's a comment-only line, and if so, continue Due to the previous behavior, inside |
|
Thanks @thaJeztah. Let me take a look and see if I could provide a quick fix for it. |
This fix is to address moby#29005 where continuation after comments are not allowed after moby#24725. This fix made the change so that moby#29005 could be addressed. An integration test has been added. Other related tests have been udpated to conform to the behavior changes. This fix fixes moby#29005, but please feel free for any additional suggestions. Signed-off-by: Yong Tang <[email protected]>
|
The behaviour in 1.13-RC2 has broken all of my Dockerfiles as I depend on both spaces and comments being allowed after continuations in the RUN and ENV instructions. As a user, this is a huge and unwelcome breaking change for 1.13 if it stays. |
|
@kinghuang we are aware of this change, and will address before 1.13 GA. The discussion is taking place here; #29005, and is currently focussed on the "blank lines", perhaps you can add a minimal example of this from your Dockerfile. I'll lock the discussion here, so that the discussion does not take place on multiple places, but you're welcome to join in the discussion on #29005 |
- What I did
This fix tries to fix the bug reported by #24693 where an empty line after escape will not be stopped by the parser.
- How I did it
This fix addresses this issue by stop the parser from continue with an empty line after escape.
- How to verify it
An additional integration test has been added.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
This fix fixes #24693.
Signed-off-by: Yong Tang [email protected]