Skip to content

Commit

Permalink
perf: reduce phylum binary size for slim images (#385)
Browse files Browse the repository at this point in the history
This change uses `strip` to reduce the `phylum` binary size. This idea
comes from a blog post about making Rust release binaries smaller:

https://kobzol.github.io/rust/cargo/2024/01/23/making-rust-binaries-smaller-by-default.html

Instead of making the change in the release workflow of the Phylum CLI,
the binary stripping is limited to the `slim` Docker images here in an
effort to reduce the size for performance-oriented applications. The
benefit is a smaller image and therefore faster download times.

Benchmarks from this change on my local system:

* Image generation duration increased by a few seconds
  * This is due to installing and then removing the `binutils` package
* The `phylum` binary size went from 124MB --> 90MB
* Uncompressed image size went from 380MB --> 344MB
* Compressed image size went from 126.66MB --> 116.96MB
  • Loading branch information
maxrake authored Feb 6, 2024
1 parent 6a2a638 commit ac5e477
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile.slim
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,20 @@ RUN set -eux; \
# Install pre-requisites
apt-get update; \
apt-get upgrade --yes; \
apt-get install --yes --no-install-recommends git; \
apt-get install --yes --no-install-recommends git binutils; \
# Make ENTRYPOINT alternative script available
chmod +x "${PHYLUM_VENV}/bin/entrypoint.sh"; \
# Install Phylum CLI
phylum-init -vvv --phylum-release "${CLI_VER:-latest}" --global-install; \
strip "$(which phylum)"; \
# Create a git config file in a location accessible for $HOME-less users
# Ref: https://git-scm.com/docs/git-config#FILES
mkdir -vp "${XDG_CONFIG_HOME}/git" && touch "${XDG_CONFIG_HOME}/git/config"; \
# Ensure the XDG directories have permissions for non-root users
mkdir -vp "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_STATE_HOME}" "${XDG_CACHE_HOME}"; \
chmod -vR 777 "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_STATE_HOME}" "${XDG_CACHE_HOME}"; \
# Cleanup
apt-get remove --yes --auto-remove binutils; \
apt-get purge --yes --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*; \
rm -rf /tmp/*; \
Expand Down

0 comments on commit ac5e477

Please sign in to comment.