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

Reduce docker image size #136

Merged

Conversation

outlyer-net
Copy link
Contributor

@outlyer-net outlyer-net commented May 3, 2024

This PR reduces the Docker image size massively while remaining on Debian Bookworm, as far as I can tell there should be no ill effects. Below are my comparisons.

Each step was rebuilt to ease comparison with:

docker build -t librelink-up-pr .

And they include the changes from previous steps.

Sizes are compared with:

docker image ls | grep librelink | awk '{print $NF,$1}'

Also a .dockerignore file is included to avoid copying the git-related files and directories into the image.

Starting point

1.51GB librelink-up-pr
1.51GB timoschlueter/nightscout-librelink-up

Switch to node:20-bookworm-slim as base image

618MB librelink-up-pr
1.51GB timoschlueter/nightscout-librelink-up

Use a separate builder stage

277MB librelink-up-pr
1.51GB timoschlueter/nightscout-librelink-up

Remove devDependencies

This also involves pre-compiling the TypeScript code, I've changed the CMD to reuse start-heroku

204MB librelink-up-pr
1.51GB timoschlueter/nightscout-librelink-up

Compressed size difference

For additional context:

$ docker save librelink-up-pr | gzip -c | pv -b >/dev/null
67,7MiB
$ docker save timoschlueter/nightscout-librelink-up | gzip -c | pv -b >/dev/null
 448MiB

Removes all git-related stuff from the image.
Reduces unnecessary rebuilds.
Side-effect: Compile TypeScript and use the start-heroku script to run compiled code
@outlyer-net outlyer-net reopened this May 3, 2024
@outlyer-net outlyer-net marked this pull request as ready for review May 3, 2024 12:45
@timoschlueter timoschlueter changed the base branch from main to release/2.6.0 May 14, 2024 16:30
@timoschlueter timoschlueter merged commit 11119d0 into timoschlueter:release/2.6.0 May 14, 2024
0 of 2 checks passed
@timoschlueter
Copy link
Owner

Great work @outlyer-net. Thank you very much for this contribution :)

@outlyer-net outlyer-net deleted the docker-image-shrink branch May 16, 2024 15:07
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.

None yet

2 participants