minimeteor icon indicating copy to clipboard operation
minimeteor copied to clipboard

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

Open sokki opened this issue 7 years ago • 3 comments

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.

sokki avatar Sep 12 '17 11:09 sokki

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.

aedm avatar Sep 12 '17 11:09 aedm

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.

csillag avatar Sep 12 '17 11:09 csillag

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

sokki avatar Sep 12 '17 12:09 sokki