Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Use multi-stage builds to reduce build-time and image-size #25

Open
sokki opened this issue Sep 12, 2017 · 3 comments
Open

Use multi-stage builds to reduce build-time and image-size #25

sokki opened this issue Sep 12, 2017 · 3 comments

Comments

@sokki
Copy link
Contributor

sokki commented Sep 12, 2017

I guess, we could combine the advantages of both methods script and Dockerfile.

Multi-stage builds are a new feature in Docker 17.05. With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image.
https://docs.docker.com/engine/userguide/eng-image/multistage-build/

An applications Dockerfile might look like

FROM aedm/minimeteor:1.5.2-build # debian and alpine-node with build-deps
FROM aedm/minimeteor:1.5.2-production # alpine-node minimal
COPY --from=0 /bundle .

This way, we would not need to install dependencies and meteor on every build and still have a minimal-weight image in the end 🙃

I have not tried out how to combine the new COPY --from and ONBUILD though. But I hope, that works.

@aedm
Copy link
Owner

aedm commented Sep 12, 2017

Yes, multi-stage builds are definitely the future of Minimeteor. I'd actually be really glad not having to support two different build mechanisms. :)

What I can't really figure out yet is how to select base images dynamically. I want to specify mhart/alpine-node:x.x based on the output of meteor build, since it specifies the Node version required to run the bundle. What you suggested above would work, but it would also require the user to update the Dockerfile every time the Meteor version is upgraded. Still, that would probably be a good start.

I'm still lamenting about this. Any suggestions are welcome.

@csillag
Copy link
Contributor

csillag commented Sep 12, 2017

This way, we would not need to install dependencies and meteor on every build and still have a minimal-weight image in the end

That would be awesome.

@sokki
Copy link
Contributor Author

sokki commented Sep 12, 2017

select base images dynamically

True, that would be much nicer.
I could only imagine to take a plain alpine, COPY --from from the meteor build-image and install the corresponding node version ONBUILD. But - for me - it's not worth the increased build-time. We build our apps every few hours and update meteor just every few weeks ...

Now that I think about it - I guess, we could hide all three steps inside one image. So my example above could be stripped down to one statement:

FROM aedm/minimeteor:1.5.2 # debian, alpine-node with build-deps and finally: alpine-node minimal

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants