Skip to content

add LDFLAGS for optimizing image size #483

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 2 commits into from
May 19, 2020

Conversation

autoferrit
Copy link
Contributor

This is based on #448 by @lubo

I ran this locally with the change and it worked out well. I build the 3.8-alpine3.11 image (tagging it as just py3 here) and the image size went from 107MB to 78.9MB, a reduction in size of ~26%

❯ docker images
REPOSITORY TAG              IMAGE ID            CREATED             SIZE
py3        latest           95f26289fc0e        4 minutes ago       78.9MB
python     3.8-alpine3.11   6c32e2504283        2 weeks ago         107MB

@autoferrit autoferrit mentioned this pull request May 13, 2020
@yosifkit
Copy link
Member

For future reference, this saves ~20 MB on every Alpine based image.

We want to leave the debuggability in the regular Debian images, but we should add this to the slim images which gets similar 20-30 MB savings. Do you want to update the PR to include them?

diff --git a/Dockerfile-slim.template b/Dockerfile-slim.template
index 3d0c359..457f865 100644
--- a/Dockerfile-slim.template
+++ b/Dockerfile-slim.template
@@ -65,6 +65,7 @@ RUN set -ex \
                --with-system-ffi \
                --without-ensurepip \
        && make -j "$(nproc)" \
+               LDFLAGS="-Wl,--strip-all" \
 # setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916
                PROFILE_TASK='-m test.regrtest --pgo \
                        test_array \

@autoferrit
Copy link
Contributor Author

Done

Copy link
Member

@yosifkit yosifkit left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

@yosifkit yosifkit requested a review from tianon May 15, 2020 20:23
@tianon
Copy link
Member

tianon commented May 19, 2020

(Rebased to remove unrelated version bumps -- I plan to merge once CI says we're green 👍)

Thanks!

@tianon
Copy link
Member

tianon commented May 19, 2020

Those last two jobs look stuck -- I'm merging anyhow. 👍

@tianon tianon merged commit f83ecbf into docker-library:master May 19, 2020
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request May 19, 2020
Changes:

- docker-library/python@f83ecbf: Merge pull request docker-library/python#483 from autoferrit/master
- docker-library/python@6a981eb: also should apply to slim images.
- docker-library/python@7dc395a: add LDFLAGS for optimizing image size
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.

3 participants