Skip to content
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

(perf): Convert Python base image to python:3.11-slim #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lasith-kg
Copy link

@lasith-kg lasith-kg commented Oct 27, 2024

The current Dockerfile assumes the base Debain Python image (python:3.11) which produces a final image that is approximately 1.0 GB in size.

docker build . -t tests:debian
docker image ls | grep "tests:debian"
tests:debian             latest        bbd315631e3e   46 seconds ago   1.09GB

Since GitHub Actions has to build this image at runtime, I propose we use the Slim (python:3.11-slim) image instead. This change produces a final Docker image that is approximately 231 MB in size.

docker build . -t tests:debian-slim
docker image ls | grep "tests:debian-slim"
tests:debian-slim        latest        40f097c44a36   2 seconds ago       231MB

We could get further size reductions if we were to use the python:3.11-alpine image. However, I believe that sticking to a a Debian-based image prevents compatibility issues when using Python libraries with C extensions. I am open to using the alpine Docker image if you are confident that the current dependencies play nice with the Alpine Linux platform. I was able to successfully build and test an Alpine Docker image.

docker build . -t tests:alpine
docker image ls | grep "tests:alpine"
tests:alpine             latest        b6d56e866048   15 minutes ago   139MB
docker run --entrypoint python tests:alpine unit-tests.py
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK

@lasith-kg lasith-kg force-pushed the lasith-kg/dockerfile-size-reduction branch from b4a04e3 to d29a274 Compare October 28, 2024 00:58
@lasith-kg lasith-kg changed the title (perf): Convert Python base image to python:3.11-alpine (perf): Convert Python base image to python:3.11-slim Oct 28, 2024
@cuchi
Copy link
Owner

cuchi commented Nov 27, 2024

Hey! Thanks for that, I'll take a look later today.

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.

2 participants