Skip to content

Conversation

Aschen
Copy link

@Aschen Aschen commented Jun 26, 2020

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 alpine image, build the application
  • from the bare image, 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.

@nschonni
Copy link
Member

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

@tianon
Copy link
Contributor

tianon commented Jun 26, 2020

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)? 😄

@Aschen
Copy link
Author

Aschen commented Jun 29, 2020

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

@Aschen
Copy link
Author

Aschen commented Jul 3, 2020

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 😄 )

I updated the original PR description.

@Aschen Aschen changed the title Add new scratch image tag Add new bare image tag Jul 3, 2020
@Aschen
Copy link
Author

Aschen commented Jul 21, 2020

Any updates on this PR ?

Base automatically changed from master to main March 15, 2021 16:23
@kuzzleio kuzzleio closed this by deleting the head repository Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants