Add new bare image tag
What does this PR do
This PR introduce a new image tag (name proposals: node:14-scratch, node:14-minimal, node:14-bare) which correspond to a minimal image containing only Node binary and it's dependencies (mostly the libstdc++ and musl).
The image size is 68.9MB which is 40% smaller than the 14-alpine3.10 image (117MB).
If you like the idea I will adds images for other Node version.
EDIT (2020/07/03):
This image is now based on alpine to benefits from the shell and package manager for only 5MB.
The image is 71MB.
I've renamed the image tag from scratch to bare.
Usage
This image can be used in a multi-stage build:
- from the
alpineimage, build the application - from the
bareimage, just copy the files
FROM node:14-alpine3.10 as builder
COPY . /opt/kuzzle
RUN cd /opt/kuzzle && npm install --production
FROM node:14-bare
COPY --from=builder /opt/kuzzle /opt/kuzzle
CMD ["node", "/opt/kuzzle/bin/start-kuzzle-server"]
Why
When you go to production, you may want to deploy images containing only your application and not your build chain (npm, yarn). Also there is a lot of unnecessary files like documentation or c headers that you don't need either.
This could allows to save a lot of disk space but also bandwidth for people deploying Node.js applications.
How
Builder image steps description:
- use the node 14 alpine 3.10 build steps to download and compile Node
- strip node binaries
- remove unnecessary files (NPM, headers, documentation, some binaries)
Then in the final image is built from alpine with only Node.js.
I'm not sure whether this would match the multi-stage restrictions on official images or not https://github.com/docker-library/faq#multi-stage-builds
If you can get a FROM scratch image down to ~68.9MB, shouldn't you be able to get the FROM alpine image down to ~74.47MB (given alpine:3.12 is only ~5.57MB)? :smile:
where the necessary artifact does not exist and must be built from source and/or the build process is going to be similarly highly deterministic (thus mitigating the cache concern somewhat);
@nschonni From what I understand of this sentence, it would be better to directly add the Node binaries to the image rather than building them. If we don't have the choice to build them I'm not sure if we can consider Node build "highly deterministic"
@tianon The problem is I don't know how the users rely on what part of the existing alpine image so removing some part of the image may be a breaking change
Following your comment @tianon I switch to use alpine image as base and I end up with a 71MB image.
(I just saw that you are also the guy who answered me here :smile: )
I updated the original PR description.
Any updates on this PR ?