ababaian / serratus

Ultra-deep search for novel viruses
http://serratus.io
GNU General Public License v3.0
255 stars 33 forks source link

:whale: Use the simplest possible multi-stage builds #110

Closed itzamna314 closed 4 years ago

itzamna314 commented 4 years ago

This PR won't remove any extra files from the final images, but it does remove the layer cache. The builds will take longer, because we're copying the whole FS across. However, the multi-stage images are about half the size of the builder stage across the board:

image
ababaian commented 4 years ago

Can you give me a quick rundown of what this does? I don't understand how using the base amazon image after the install commands reduces image size.

FROM amazonlinux:2 AS runtime
COPY --from=build_base / /
itzamna314 commented 4 years ago

Sure!

FROM amazonlinux:2 AS runtime starts a new build-stage, fresh from the amazonlinux:2 base image. At that point, we've got a fresh filesystem with only amazonlinux:2's contents in it. We've also got a fresh layer cache, so none of the layers that have been created in build_base exist in the new image.

COPY --from=build_base / / will create a new layer, and copy in the entire filesystem contents from build_base. At this point, runtime's filesystem is exactly the same as build_base, so all of the scripts will work exactly the same. However, we haven't copied over any of the layers that were used to arrive at the filesystem in build_base.

All of the space savings are from dropping that layer cache from the final image.

itzamna314 commented 4 years ago

https://github.com/ababaian/serratus/issues/108