-
Notifications
You must be signed in to change notification settings - Fork 760
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
Add multi-stage builds support #495
Conversation
@nalind PTAL |
Travis CI isn't happy @bertinatto
|
8ccfb2c
to
8a96829
Compare
Right, I have a question about this failing test ( In a multi-stage build, each What do you think about this? |
f807c99
to
ecec5e2
Compare
I am no expert on this. but isn't multi-stage the equivalent of doing two different Dockerfile, where the second Dockerfile from is from the artifact of the first Dockerfile. Anything that is in the image created by the first |
@rhatdan Here's an example: This is all based around the flexibility of needing to use one images utilities to bootstrap the toolchain for another (i.e. - using alpine gpg to validate or busybox to copy/untar). |
@rhatdan, AFAIU the idea is that we can selectively copy artifacts from one stage to another, leaving the final image without unnecessary artifacts. Using the example of #440, the first |
Do these workloads work with this patch? |
Yup, but unfortunately multi-stage builds support changes the way |
ecec5e2
to
0da653b
Compare
@nalind PTAL |
@ipbabble @TomSweeneyRedHat Could you try out a couple of Dockerfiles against this to make sure it works fairly well. I would like to get this merged along with SHELL Support so we can cut a new version of Buildah. |
FWIW, I tested using both of the below Dockerfiles and these worked. I tried a couple of other more complex Dockerfiles that I found on the net and they had failures, but the same failure happened in Docker too. I don't believe it was a Buildah issue. If you've a pointer to other multi-stage Dockerfiles, happy to try them.
and
|
imagebuildah/build.go
Outdated
@@ -113,6 +113,8 @@ type BuildOptions struct { | |||
// Executor is a buildah-based implementation of the imagebuilder.Executor | |||
// interface. | |||
type Executor struct { | |||
name 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.
Please add a field for the numeric index of the stage which this Executor
is responsible for building. We'll need that information to ensure that COPY
instructions that try to reference this stage or a later stage, can be rejected.
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.
Done, although I think it was rejecting invalid stages before.
imagebuildah/build.go
Outdated
@@ -329,6 +343,12 @@ func (b *Executor) Copy(excludes []string, copies ...imagebuilder.Copy) error { | |||
for _, src := range copy.Src { | |||
if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") { | |||
sources = append(sources, src) | |||
} else if len(copy.From) > 0 { | |||
if other, ok := b.named[copy.From]; ok { |
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'll need to check that the stage number for other
is less than the one for b
.
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.
Done.
imagebuildah/build.go
Outdated
} | ||
var stageExecutor *Executor | ||
for _, stage := range stages { | ||
stageExecutor = b.withName(stage.Name) |
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 should take the index of the stage as an argument, since whether a name for the stage is specified with AS
or not, its contents still need to be accessible by referring to the stage using its numeric index, and we want to know where a given Executor
is in the list of them. Converting the number to a string in withName()
and using it as another key for adding copied
to the named
map, since the values are pointers, should be fine.
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.
Done. Thanks for catching this.
I checked the behaviour of docker
and it does accept both indexes and names. On the other hand, imagebuilder
does not. We might report this.
Apologies for the delay. A couple of notes about stage ordering and numbers, but the rest looks really good. Thanks! |
☔ The latest upstream changes (presumably 5ce8009) made this pull request unmergeable. Please resolve the merge conflicts. |
@bertinatto Needs a rebase. |
I've been traveling and haven't been able to take a look at this. Sorry.
I've been doing som eof my own testing of complex Dockerfiles.
William Henry
Senior Consulting Software Engineer
Red Hat
Colorado, USA.
…On Thu, Apr 5, 2018 at 1:24 AM, Fábio Bertinatto ***@***.***> wrote:
@nalind <https://github.com/nalind>, thanks for the review. I'll apply
your suggestions as soon as I have time (probably over the weekend, if
that's not a problem).
@rhatdan <https://github.com/rhatdan>, will do, thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#495 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABPpgZe3tN_RcxG5ARGHbCRlQnVwhoAPks5tlcavgaJpZM4SR3Us>
.
|
64a78ab
to
847aff2
Compare
LGTM pending CI. |
Signed-off-by: Fabio Bertinatto <fbertina@redhat.com>
Signed-off-by: Fabio Bertinatto <fbertina@redhat.com>
Signed-off-by: Fabio Bertinatto <fbertina@redhat.com>
I had to close/reopen to retest. All green now. |
Thanks! |
📌 Commit b5ef4be has been approved by |
⚡ Test exempted: pull fully rebased and already tested. |
Signed-off-by: Fabio Bertinatto <fbertina@redhat.com> Closes: #495 Approved by: nalind
Signed-off-by: Fabio Bertinatto <fbertina@redhat.com> Closes: #495 Approved by: nalind
Time for a new build? I think this could be buildah 1.0? @nalind @TomSweeneyRedHat WDYT |
My vote doesn't count, but it would be awesome to have buildah 1.0! |
On 04/11/2018 01:43 AM, Daniel J Walsh wrote:
Time for a new build? I think this could be buildah 1.0? @nalind
<https://github.com/nalind> @TomSweeneyRedHat
<https://github.com/TomSweeneyRedHat> WDYT
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#495 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYbWBRJkNd9F4NiftznvUOnxXMgF5nZSks5tnZgBgaJpZM4SR3Us>.
+1
|
/me being excited! 😀 |
This PR adds multi-stage builds support to buildah.
Addresses #440.