-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Support multi-stage dockerbuilds via imagebuilder #18741
Support multi-stage dockerbuilds via imagebuilder #18741
Conversation
52005a7
to
2181416
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.
what's the behavior of manageDockerFile w/ respect to this? I believe manageDockerFile replaces the "last" FROM statement in the dockerfile, with the resolved imagestreamtag reference. That's because at the time, multistage builds weren't a thing and if you had multiple FROM statements in your dockerfile, only the last one mattered. But if we actually expect multiple FROMs in a dockerfile now, the behavior of manageDockerFile needs to change (though it's not clear which FROM should be replaced in that case? Perhaps neither?)
pkg/build/builder/docker.go
Outdated
} | ||
} | ||
} | ||
return images.List(), len(stages) > 0, nil |
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.
should this be greater than 1?
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
With multi-stage builds, image source suddenly gets a lot more powerful / direct, because you can bypass needing to copy the image content around. I'm thinking that we want to add an Current thinking:
Thoughts? No matter what we'd rewrite the dockerfile prior to sending onwards |
afdd1b9
to
95db0fd
Compare
if i'm understanding your sample, the "replacement precedence" would be:
i don't love (2). The rest makes sense and i'm not sure what i'd recommend instead of (2)... I suppose it just forces people to be explicit about their imagesource references which isn't a terrible thing, but might break some people unexpectedly when they create a docker buildconfig w/ an explicit buildconfig.from and all their image references get overwritten instead of just the first one. Regarding the FROM x AS y behavior, i agree w/ the idea that future references to "y" should now get "x" instead of whatever "y" used to be defined as. |
We could just say that the build "from" is an implicit image source for the value of the last stage. That's effectively what we do today. |
95db0fd
to
afbfb34
Compare
afbfb34
to
77481e8
Compare
93e40ef
to
7ecdea9
Compare
i like that better than treating it as a default. But would it also sub in for other stages that used the same value? And how does an "AS" in the dockerfile come into play? |
var set sets.String | ||
for i, image := range input.Images { | ||
for j, name := range image.As { | ||
if len(name) == 0 { |
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.
probably worth a comment explaining that you don't record an error here because validateImageSource already did.
// paths is a list of source and destination paths to copy from the image. This content will be copied | ||
// into the build context prior to starting the build. If no paths are set, the build context will | ||
// not be altered. | ||
// +optional |
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.
have you validated that the rest of the build logic properly handles this being empty?
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.
Went over all the uses of image paths - there weren't many. We didn't actually ever require them to be set that I could find outside of validation.
I don't think it should sub in. However, we could say we do that replacement first, and if you did something like AS I think always takes priority no matter what, since an AS always has an underlying name that can be replaced safely. |
i'm thinking about ordering. Do we do all the dockerfile AS replacements first, or all the imagesource.as+build.from replacements first? I think the simplest thing to reason about would be do that do all the substitutions into the dockerfile, then use the dockerfile normally. But that potentially contradicts your statement of and i think that in "FROM x AS y" we should perhaps not substitute the value of y, ever. That value should be reserved for users trying to alias things, we shouldn't mess with it. ('x', of course, is fair game for substitution) |
7ecdea9
to
22cb127
Compare
I don't think it should sub in. However, we could say we do that replacement first, and if you did something like |
So for |
Take a look at the test cases I added and see if they make logical sense to you (in common_test.go for addBuildParameters). |
22cb127
to
f633f7f
Compare
f633f7f
to
d4dd228
Compare
Comments addressed |
d4dd228
to
5897394
Compare
5897394
to
3b4f777
Compare
3b4f777
to
75579a9
Compare
/test all |
75579a9
to
7d96b1d
Compare
/retest |
The previous code is too complex and tries to be clever with existing values. test-cmd is local, just stomp the set of values.
Unless the user sets the imageOptimizationPolicy to None, use imagebuilder to perform multi-stage builds.
7d96b1d
to
6f6a1d5
Compare
/retest |
5 similar comments
/retest |
/retest |
/retest |
/retest |
/retest |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bparees, smarterclayton The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Automatic merge from submit-queue (batch tested with PRs 18887, 18741). |
Needs an e2e test and a way to perform replacement on the stage images.
Will allow standard multi-stage Dockerfile builds against any Docker 1.12+ backend.
API PR openshift/api#34