[docker] use `--no-cache-dir` flag to `pip` in dockerfiles to save space 39/116539/1 honolulu
authorPratik raj <rajpratik71@gmail.com>
Wed, 30 Dec 2020 05:11:52 +0000 (10:41 +0530)
committerPratik raj <rajpratik71@gmail.com>
Wed, 30 Dec 2020 05:11:52 +0000 (10:41 +0530)
using "--no-cache-dir" flag in pip install ,make sure downloaded packages
by pip don't cached on system . This is a best practice which make sure
to fetch from repo instead of using local cached one . Further , in case
of Docker Containers , by restricting caching , we can reduce image size.
In term 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 reduce a lot by don't caching pip packages.

Further , more detail information can be found at

https://medium.com/sciforce/strategies-of-docker-images-optimization-2ca9cc5719b6

Issue-ID: MULTICLOUD-1279
Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
Change-Id: If01ac9167727423f65788bdf6abfd8ee0e1546cc

fcaps/docker/Dockerfile
lenovo/docker/Dockerfile
newton/docker/Dockerfile
ocata/docker/Dockerfile
ocata/vagrant/test/Dockerfile
pike/docker/Dockerfile
pike/vagrant/test/Dockerfile
starlingx/docker/Dockerfile
windriver/docker/Dockerfile

index 06654e9..3b252d6 100644 (file)
@@ -27,8 +27,8 @@ RUN apk update && \
     unzip -q -o -B multicloud-openstack-fcaps.zip && \
     chmod +x /opt/fcaps/*.sh && \
     rm -f multicloud-openstack-fcaps.zip && \
-    pip3 install -r /opt/fcaps/requirements.txt && \
-    pip3 install -r /opt/fcaps/uwsgi-requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/fcaps/requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/fcaps/uwsgi-requirements.txt && \
     apk del wget unzip gcc make libc-dev libffi-dev openssl-dev pcre-dev && \
     mkdir -p /var/log/onap/multicloud/fcaps && \
     chown onap:onap /var/log/onap -R && \
index c4489ce..8d0a5e8 100644 (file)
@@ -41,7 +41,7 @@ RUN apt-get update && \
     unzip -q -o -B multicloud-openstack-lenovo.zip && \
     chmod +x /opt/lenovo/*.sh &&\
     rm -f multicloud-openstack-lenovo.zip &&\
-    pip install -r /opt/lenovo/requirements.txt &&\
+    pip install --no-cache-dir -r /opt/lenovo/requirements.txt &&\
     apt-get --purge remove -y wget unzip gcc libssl-dev && \
     apt-get -y autoremove && \
     mkdir -p /var/log/onap/multicloud/openstack/lenovo && \
index 3a7d309..6c477b0 100644 (file)
@@ -39,7 +39,7 @@ RUN apt-get update && \
     unzip -q -o -B multicloud-openstack-newton.zip && \
     chmod +x /opt/newton/*.sh && \
     rm -f multicloud-openstack-newton.zip && \
-    pip install -r /opt/newton/requirements.txt
+    pip install --no-cache-dir -r /opt/newton/requirements.txt
 
 WORKDIR /opt/newton
 CMD /bin/sh -c /opt/newton/run.sh
index c4fa139..ebf2d17 100644 (file)
@@ -40,7 +40,7 @@ RUN apt-get update && \
     wget -O /opt/multicloud-openstack-ocata.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=staging&g=org.onap.multicloud.openstack&a=multicloud-openstack-ocata&e=zip&v=1.4.0" && \
     unzip -q -o -B /opt/multicloud-openstack-ocata.zip -d /opt/ && \
     rm -f /opt/multicloud-openstack-ocata.zip && \
-    pip install -r /opt/ocata/requirements.txt && \
+    pip install --no-cache-dir -r /opt/ocata/requirements.txt && \
     apt-get --purge remove -y wget unzip gcc libssl-dev && \
     apt-get -y autoremove && \
     mkdir -p /var/log/onap/multicloud/openstack/ocata && \
index 10e17ca..c3bfaaf 100644 (file)
@@ -31,7 +31,7 @@ RUN apt-get update && \
     unzip -q -o -B multicloud-openstack-ocata.zip && \
     chmod +x /opt/ocata/*.sh && \
     rm -f multicloud-openstack-ocata.zip && \
-    pip install -r /opt/ocata/requirements.txt
+    pip install --no-cache-dir -r /opt/ocata/requirements.txt
 
 ADD extsys.py /opt/ocata/lib/share/common/msapi/extsys.py
 
index af7ded7..8e29acc 100644 (file)
@@ -40,8 +40,8 @@ RUN apt-get update && \
     cd /opt/ && \
     unzip -q -o -B /opt/multicloud-openstack-pike.zip -d /opt/ && \
     rm -f /opt/multicloud-openstack-pike.zip && \
-    pip3 install -r /opt/pike/requirements.txt && \
-    pip3 install -r /opt/pike/uwsgi-requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/pike/requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/pike/uwsgi-requirements.txt && \
     apt-get --purge remove -y wget unzip gcc libssl-dev && \
     mkdir -p /var/log/onap/multicloud/openstack/pike && \
     chown onap:onap /var/log/onap -R && \
index 292cb26..a1154dc 100644 (file)
@@ -39,8 +39,8 @@ RUN apt-get update && \
     cd /opt/ && \
     unzip -q -o -B /opt/multicloud-openstack-pike.zip -d /opt/ && \
     rm -f /opt/multicloud-openstack-pike.zip && \
-    pip3 install -r /opt/pike/requirements.txt && \
-    pip3 install -r /opt/pike/uwsgi-requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/pike/requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/pike/uwsgi-requirements.txt && \
     apt-get --purge remove -y wget unzip gcc libssl-dev && \
     mkdir -p /var/log/onap/multicloud/openstack/pike && \
     chown onap:onap /var/log/onap -R && \
index 4e63529..16b39bc 100644 (file)
@@ -40,8 +40,8 @@ RUN apk update && \
     cd /opt/ && \
     unzip -q -o -B /opt/multicloud-openstack-starlingx.zip -d /opt/ && \
     rm -f /opt/multicloud-openstack-starlingx.zip && \
-    pip3 install -r /opt/starlingx/requirements.txt && \
-    pip3 install -r /opt/starlingx/uwsgi-requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/starlingx/requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/starlingx/uwsgi-requirements.txt && \
     apk del wget unzip gcc make libc-dev libffi-dev openssl-dev pcre-dev && \
     mkdir -p /var/log/onap/multicloud/openstack/starlingx && \
     chown onap:onap /var/log/onap -R && \
index 4bde9d5..e25bd41 100644 (file)
@@ -26,8 +26,8 @@ RUN apk update && \
     unzip -q -o -B multicloud-openstack-windriver.zip && \
     chmod +x /opt/windriver/*.sh && \
     rm -f multicloud-openstack-windriver.zip && \
-    pip3 install -r /opt/windriver/requirements.txt && \
-    pip3 install -r /opt/windriver/uwsgi-requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/windriver/requirements.txt && \
+    pip3 install --no-cache-dir -r /opt/windriver/uwsgi-requirements.txt && \
     apk del wget unzip gcc make libc-dev libffi-dev openssl-dev pcre-dev && \
     mkdir -p /var/log/onap/multicloud/openstack/windriver && \
     chown onap:onap /var/log/onap -R && \