Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new bare image tag #1282

Open
wants to merge 1 commit into
base: master
from
Open

Add new bare image tag #1282

wants to merge 1 commit into from

Conversation

@Aschen
Copy link

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.

@Aschen Aschen force-pushed the kuzzleio:add-scratch-image branch from f54a3cc to 80d596a Jun 26, 2020
@nschonni
Copy link
Member

nschonni commented Jun 26, 2020

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.