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

Slim down docker images #864

Merged
merged 1 commit into from
Aug 23, 2024
Merged

Slim down docker images #864

merged 1 commit into from
Aug 23, 2024

Conversation

squeaky-pl
Copy link
Contributor

@squeaky-pl squeaky-pl commented Aug 22, 2024

I was revising the Docker image to realize that we have quite a number of packages that are not needed. Most of them used to be build time dependencies of Python packages that can be now installed from binary wheels.

This:

  • Removes dependencies we don't use, so there's less of security updates needed
  • Makes the images smaller ( 1.12GB -> 896MB )
  • Makes the builds faster

@@ -11,7 +11,6 @@ jedi==0.18.2
boto==2.49.0
boto3==1.19.4
botocore==1.22.9
cchardet==2.1.7
Copy link
Contributor Author

@squeaky-pl squeaky-pl Aug 22, 2024

Choose a reason for hiding this comment

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

cchardet is a faster version of chardet. We don't often need to detect charset on the fly and if we need to we can just use chardet in Python. cchardet Requires a C++ compiler to build and it used to be an optional dependency of requests. It is also abandoned - see the drama here and everybody moved away from it since it does not work on Python 3.10.

Comment on lines +6 to +11
ENV \
TZ="Etc/GMT" \
LANG="en_US.UTF-8" \
LC_ALL="en_US.UTF-8" \
DEBIAN_FRONTEND=noninteractive \
PATH="/opt/venv/bin:$PATH"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just made one layer from all the env vars.

vim \
libffi-dev \
&& locale-gen en_US.UTF-8 \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We used to install language-pack-en, that just includes all the English variants around the world, but we only need en_US.UTF-8

gettext-base \
language-pack-en \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

that was substituted with locale-gen en_US.UTF-8

@squeaky-pl squeaky-pl marked this pull request as ready for review August 22, 2024 15:51
COPY --chown=sync-engine:sync-engine ./ ./
RUN python3 -m pip install pip==24.0 virtualenv==20.25.1 && \
python3 -m virtualenv /opt/venv && \
/opt/venv/bin/python3 -m pip install --no-deps -r requirements/prod.txt -r requirements/test.txt && \
/opt/venv/bin/python3 -m pip install --no-cache --no-deps -r requirements/prod.txt -r requirements/test.txt && \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to store wheels in the image since they will be only used once for install and it increases image size.

Comment on lines +21 to +23
gpg \
gpg-agent \
dirmngr \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those were previously installed from recommended, we need those for some things devops uses in the upstream image.

@squeaky-pl squeaky-pl requested a review from drewler August 23, 2024 07:45
@squeaky-pl squeaky-pl merged commit 97afb2d into master Aug 23, 2024
3 checks passed
@squeaky-pl squeaky-pl deleted the slim-down-docker branch August 23, 2024 08:38
@squeaky-pl squeaky-pl mentioned this pull request Aug 26, 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.

2 participants