Skip to content

Adjust installation order and purge "libpythonXX.a" files #508

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

Merged
merged 3 commits into from
Aug 3, 2020

Conversation

tianon
Copy link
Member

@tianon tianon commented Jul 31, 2020

Closes #507
Closes #503
Closes #504

@tianon
Copy link
Member Author

tianon commented Jul 31, 2020

(Cognitively, I think it makes sense to finish everything we need to do with the source code, then purge all traces of the source code, then purge files we didn't want to have installed, then detect necessary dependencies, hence my reordering.)

@tianon
Copy link
Member Author

tianon commented Aug 1, 2020

@tianon
Copy link
Member Author

tianon commented Aug 1, 2020

I built before/after locally to help minimize differences in the packages installed, etc to try and narrow down why python:3.8-slim-buster got slightly bigger:

  • Before: ~165MB
  • After: ~169MB

(In other words, building locally didn't actually help narrow down anything....)

This will have to be a project for next week. 😞

@Lebvanih
Copy link

Lebvanih commented Aug 1, 2020

Hello,

The size increase that you see on the debian buster slim seems to come from the ordering.
If I take the new docker file and stop it after the build of python (so before the part for PIP) and then check the amount of package installed on the system:
root@b96d018c9659:/usr# dpkg --list | wc -l
123

If I check the same on the old image:
root@e1e2a2280dd3:/usr# dpkg --list | wc -l
98

I am not really an expert with ldconfig and what it does and how this affect the whole build, but it seems that if ldconfig is placed at the end, less package are cleaned during the apt-get purge resulting in more space used in /usr/lib and /usr/share directory:
After:

root@b96d018c9659:/usr# du -xhs *
14M	bin
4.0K	games
9.8M	include
55M	lib
26M	local
2.0M	sbin
38M	share
4.0K	src

Before:

14M	bin
4.0K	games
4.0K	include
33M	lib
85M	local
2.0M	sbin
6.9M	share
4.0K	src

The line of the dockerfile i'm mentioning:

find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
		| awk '/=>/ { print $(NF-1) }' \
		| sort -u \
		| xargs -r dpkg-query --search \
		| cut -d: -f1 \
		| sort -u \
		| xargs -r apt-mark manual \
	&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \

I tried to move the ldconfig line above the two mentioned above and I got back to 98 packages visible from dpkg --list.
If I recheck on my image (still without pip for the comparison):

root@2e927fb79cf3:/usr# du -xhs *
14M	bin
4.0K	games
4.0K	include
33M	lib
26M	local
2.0M	sbin
6.9M	share
4.0K	src

Adding the part with pip I get this size:

REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
cleaned3                                                 latest              449a3f524048        5 seconds ago       113MB

The only difference with your dockerfile is the place of the ldconfig.
How it looks on mine:

       && apt-mark auto '.*' > /dev/null \
	&& apt-mark manual $savedAptMark \
	\
	&& ldconfig \
	&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
		| awk '/=>/ { print $(NF-1) }' \
		| sort -u \
		| xargs -r dpkg-query --search \
		| cut -d: -f1 \
		| sort -u \
		| xargs -r apt-mark manual \
	&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
	&& rm -rf /var/lib/apt/lists/* \
	\
	&& python3 --version

Hoping this helps, as I said, I am not an expert, so I am not sure why this is affecting, but as you moved it in this commit, I tried to see if that could be the issue of the size change.

@tianon
Copy link
Member Author

tianon commented Aug 3, 2020

Yeah, great catch! I realized right after I left for the day on Friday that I can't ldd before I ldconfig, and that was probably exactly the reason for the discrepancy. 🤦

After fixing that:

  • python:3.8-slim-buster before: ~172MB (freshly built)
  • python:3.8-slim-buster after: ~120MB

Much better 😇

@tianon
Copy link
Member Author

tianon commented Aug 3, 2020

This helped me notice #439 (comment) (we missed slim-buster variants entirely for 3.9-rc, so we should add those back after we finish this).

@yosifkit yosifkit merged commit 5d71a7c into docker-library:master Aug 3, 2020
@yosifkit yosifkit deleted the no-a-files branch August 3, 2020 21:37
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Aug 3, 2020
Changes:

- docker-library/python@5d71a7c: Merge pull request docker-library/python#508 from infosiftr/no-a-files
- docker-library/python@7a3801a: Fix ldconfig ordering
- docker-library/python@0bba31b: Also remove "wininst-*" on Python versions lower than 3.9
- docker-library/python@ffd659a: Adjust installation order and purge "libpythonXX.a" files
tianon added a commit that referenced this pull request Aug 3, 2020
This was missed in #439 and noticed in #508.
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Aug 3, 2020
Changes:

- docker-library/python@a0cb03f: Remove 3.9-rc/alpine3.11
- docker-library/python@e7f98c0: Add missing 3.9-rc/buster/slim
- docker-library/python@5d71a7c: Merge pull request docker-library/python#508 from infosiftr/no-a-files
- docker-library/python@7a3801a: Fix ldconfig ordering
- docker-library/python@0bba31b: Also remove "wininst-*" on Python versions lower than 3.9
- docker-library/python@ffd659a: Adjust installation order and purge "libpythonXX.a" files
VenusPR pushed a commit to VenusPR/Python_Richard that referenced this pull request Mar 9, 2023
ProActiveSpirit pushed a commit to ProActiveSpirit/python that referenced this pull request Mar 1, 2024
Preston-Adams pushed a commit to Preston-Adams/python-field that referenced this pull request Aug 18, 2024
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.

Utility of the static linked library in the image if --enable-shared is active Removing Win386 executables from images
4 participants