timoschlueter / nightscout-librelink-up

Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout.
MIT License
189 stars 246 forks source link

Reduce docker image size #136

Closed outlyer-net closed 2 months ago

outlyer-net commented 2 months ago

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
timoschlueter commented 2 months ago

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