Skip to content

Conversation

@featheredtoast
Copy link
Member

apt using caches for /var/cache/apt, /var/cache/debconf, and var/lib/apt.

Ensure /usr/share/doc and /usr/share/man do not get saved to the image by mounting temporary folders to paths.

Drop build-essential from installs, in favor of selective cmake, g++, pkg-config, and patch packages.

drop apt-get -y upgrade in dockerfile. We should inherit upgrades from base images. No need to apt-mark hold initscripts now that we're not running upgrade

Remove calls to vim as we no longer install vim here. Remove comment for slimming locales as we have now done so.

apt using caches for /var/cache/apt, /var/cache/debconf, and var/lib/apt.

Ensure /usr/share/doc and /usr/share/man do not get saved to the image by
mounting temporary folders to paths.

Drop autoconf and build-essential from installs, in favor of selective cmake,
g++, pkg-config, and patch packages.

drop apt-get -y upgrade in dockerfile. We should inherit upgrades from base
images. No need to apt-mark hold initscripts now that we're not running `upgrade`

Remove calls to vim as we no longer install vim here. Remove comment for
slimming locales as we have now done so.
@featheredtoast
Copy link
Member Author

@tgxworld this one's the next phase for slimming image size

@tgxworld
Copy link
Contributor

tgxworld commented Oct 16, 2024

How much of the image size are we shaving off here? My first reaction here is that all these changes is making the Dockerfile much harder to understand and we really have to be saving a significant amount of disk space for the added complexity to be warranted.

@featheredtoast
Copy link
Member Author

This is saving 100MB uncompressed/ 30MB compressed. The majority of the changes here are just adding --mount arguments to the RUN commands.

Comment on lines 84 to 85
DEBIAN_FRONTEND=noninteractive apt-get -y install ca-certificates rsync \
cmake g++ pkg-config patch \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can combine this with line 35?

--mount=type=tmpfs,target=/usr/share/doc \
--mount=type=tmpfs,target=/usr/share/man \
--mount=type=tmpfs,target=/var/log \
DEBIAN_FRONTEND=noninteractive apt-get install -y locales
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be combined with line 35 too.

--mount=type=tmpfs,target=/usr/share/doc \
--mount=type=tmpfs,target=/usr/share/man \
--mount=type=tmpfs,target=/root/.npm \
cd / &&\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we install the apt packages early so we don't have to duplicate these lines here?

Copy link
Member Author

@featheredtoast featheredtoast Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is dependent on the curl calls for all the apt sources above. I've moved all dependent code bundled into the same run command to reduce the number of --mount calls

Comment on lines 76 to 77
--mount=type=tmpfs,target=/usr/share/doc \
--mount=type=tmpfs,target=/usr/share/man \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try to configure /etc/dpkg/dpkg.conf.d/01_nodoc to exclude /usr/share/doc and /usr/share/man? That will allow us to remove these two lines.

Copy link
Member Author

@featheredtoast featheredtoast Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this and debian slim's doing this for us already. They do keep the copyright content, but manpages are all clean!

remove tmpfs in favor of nodoc which already is in slim
@featheredtoast
Copy link
Member Author

it looks like some time ago, a proxy was setup for installing packages, which was causing some complexity in which apt-get install needed to be called multiple times to engage the proxy.

To my knowledge, we no longer use a proxy to install packages, and we're grabbing them directly from upstream, and if so we can safely move and combine apt calls.

@featheredtoast
Copy link
Member Author

featheredtoast commented Oct 16, 2024

Re-ordering and merging the apt-get layers here also seems to have squashed the size down impressively to 511.27 MB from 668.47 MB compressed (on local macos, arm64).

@featheredtoast featheredtoast merged commit 785fda3 into main Nov 4, 2024
5 checks passed
@featheredtoast featheredtoast deleted the slim-image-2 branch November 4, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants