-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Use only official Dockerfile parser #4838
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
Use only official Dockerfile parser #4838
Conversation
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.
We should stop right away if the Dockerfile is unparseable: no chance Docker will be able to build it, since we rely on Docker's Dockerfile parser.
f236a99 to
d4f789a
Compare
|
@bparees educational question / potential limitation: E.g.: # rhcarvalho/httphostname
FROM gliderlabs/alpine
RUN apk-install curl
COPY httphostname /
EXPOSE 8080
ENTRYPOINT ["/httphostname"]# app/Dockerfile
FROM rhcarvalho/httphostnameIn practice, So, two questions:
|
|
@rhcarvalho i don't know the answer to those questions, maybe @csrwng does. |
|
@rhcarvalho @bparees For new-app we have two inputs... the image that you want to base your build on (builder image for s2i builds, or FROM image in the case of Docker builds) and source. In the case of a Docker build, we can inspect the FROM image because it exists, but the image that results from building your Dockerfile doesn't exist yet, all we have is the source. Therefore we need both, the ports exposed by the parent image if any, and the ports exposed in your source Dockerfile. |
|
thanks @csrwng! Could you give me a pointer to where we Docker inspect the parent? |
d4f789a to
d5d13ec
Compare
|
Maybe answering my own question, this is the only place I found in new-app code with a call to |
|
@bparees comment addressed: consider regular files or symlinks named "Dockerfile" PTAL |
|
@rhcarvalho the image metadata can come from one of 3 places (in order of priority):
|
|
lgtm, needs squash. |
|
@bparees the changes to pkg/generate/dockerfile/finder.go (first commit) are unrelated to "Use only official Dockerfile parser". But I put that commit in the same PR as I was reviewing the whole package. Should I submit it as a separate PR? |
d5d13ec to
6ec5ad9
Compare
|
[test][extended:core] |
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.
Shouldn't we depart from the graph terminology and use something more understandable like Arguments? I would prefer this to check if the provided node is a Dockerfile command, too.
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 a helper for manipulating the AST. Calling it Arguments is promising something we cannot fulfill, at least not generically.
For most commands, collecting the values of the linked list formed by the node.Next pointers gives the "arguments" of the given command, therefore the usefulness of this helper. It's not true for ONBUILD, for instance. It's also less useful for instructions that take pairs of arguments like ENV. You have to know what you're feeding the function with.
IMHO, what we can do is to have helpers to work with specific commands. E.g., given a Dockerfile's root node, return:
- a list of all exposed ports;
- the image of every from instruction.
WDYT?
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.
After the discussion we had, yes, i think specialized exported funcs is the way to go. This has to be unexported. 👍
efc6c4d to
ca5eb18
Compare
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.
@csrwng @bparees could you please have a closer look here?
Existing code will proceed to call b.AddComponents in case you have a Dockerfile like this:
# missing image argument below
FROM
RUN yum install -y apache
...What should we be doing here? Maybe we should remove the continue and call b.AddComponents passing []string{""}?!
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.
We replacing the FROM anyway, right? So it does not matter what you have in FROM
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.
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.
BTW, unless we manipulate the Dockerfile to define a base image, building a Dockerfile without FROM will fail. AFAIK there's no way to define the base image in the new-app flow.
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 we do use it to look up the parent image and get its metadata. I didn't know we could have an empty FROM statement, is that equivalent to FROM scratch ?
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
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.
works for me. @csrwng i don't think my proposed changes would impact this flow anyway. you could still have a case where you specify a repo with a dockerfile and do not specify an explicit docker image to use with it, in which case new-app would need to process the Dockerfile From to learn about the image being FROM'd.
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.
@bparees true, though you could imagine a Dockerfile that has an empty FROM that will only work with new-app where you specify which FROM you want :)
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.
also true :)
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.
Completing the list of crazy possibilities, I think today we don't handle "replacing" the FROM of images that have no FROM instruction. We could certainly insert one at the very beginning of the Dockerfile in that case.
Anyway, I wouldn't recommend anyone that pattern, as you'd be creating invalid Dockerfiles that happen to work in OpenShift, sometimes. Also, if one day Docker will have code to validate the parsed file independent of executing a build, we could use that validation ourselves before manipulating the AST, which would make those crazy Dockerfiles broken.
baa7b15 to
aaa7b24
Compare
|
The test that is failing is the integration test |
|
continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/5717/) |
aaa7b24 to
bb6c97c
Compare
bb6c97c to
6394aeb
Compare
|
Trying to sort out the failing tests.... According to @deads2k TestSimpleImageChangeBuildTriggerFromImageStreamTagDocker failed with: I think that's also a flake? |
Fix handling Dockerfiles with multiple FROM and multiple EXPOSE instructions.
6394aeb to
8a9cb99
Compare
|
Evaluated for origin test up to 8a9cb99 |
|
@rhcarvalho can you report the flake as separate issue?> |
|
LGTM (are there any open issues about this? of so, lets convert them to follow ups and move on :) |
|
@mfojtik all the comments were addressed. Just the (seemingly unrelated) extended tests keep falling... |
|
[merge] |
|
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/3613/) (Image: devenv-fedora_2464) |
|
Evaluated for origin merge up to 8a9cb99 |
…p-pkg-generate-dockerfile Merged by openshift-bot
This is a followup on @Kargakis' comment: #4562 (comment).
pkg/generate/dockerfile, in favor of the official Dockerfile parser and AST traversal.