Skip to content

Commit 1427848

Browse files
committed
use --no-cache-dir flag to pip in dockerfiles to save space
using the "--no-cache-dir" flag in pip install, make sure downloaded packages by pip don't cache on the system. This is a best practice that makes sure to fetch from a repo instead of using a local cached one. Further, in the case of Docker Containers, by restricting caching, we can reduce image size. In terms of stats, it depends upon the number of python packages multiplied by their respective size. e.g for heavy packages with a lot of dependencies it reduces a lot by don't cache pip packages. Further, more detailed information can be found at https://medium.com/sciforce/strategies-of-docker-images-optimization-2ca9cc5719b6 Signed-off-by: Pratik Raj <[email protected]>
1 parent 992cb71 commit 1427848

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM fedora:33
22
RUN dnf install -y git podman buildah python3-libselinux python3-pip
3-
RUN pip3 install ansible==2.10.5 jmespath
3+
RUN pip3 install --no-cache-dir ansible==2.10.5 jmespath
44
RUN mkdir -p /playbooks
55
COPY roles/ /playbooks/roles/
66
COPY filter_plugins/ /playbooks/filter_plugins/

Dockerfiles/ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ RUN export ARCH=$(case $(arch) in x86_64) echo -n amd64 ;; aarch64) echo -n arm6
1313
mkdir /project/output && \
1414
dnf install --setopt=install_weak_deps=False -y git-core ansible python3-pip mlocate jq skopeo && \
1515
dnf clean all && \
16-
pip3 install operator-courier
16+
pip3 install --no-cache-dir operator-courier
1717
ADD ./run_tests.py /run_tests.py
1818
CMD ["/run_tests.py"]

upstream/roles/install_iib/templates/Dockerfile-workers.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ RUN sed -i -e 's|^#mount_program|mount_program|g' /etc/containers/storage.conf
7575
COPY docker/libpod.conf /usr/share/containers/libpod.conf
7676

7777
COPY . .
78-
RUN pip3 install -r requirements.txt --no-deps --require-hashes
79-
RUN pip3 install . --no-deps
78+
RUN pip3 install --no-cache-dir -r requirements.txt --no-deps --require-hashes && \
79+
pip3 install --no-cache-dir . --no-deps
8080
CMD ["/bin/celery-3", "-A", "iib.workers.tasks", "worker", "--loglevel=info"]

0 commit comments

Comments
 (0)