From 97d2fe49d87b4084aa008d14bcd2507024751287 Mon Sep 17 00:00:00 2001 From: Pratik raj Date: Sat, 25 Jul 2020 13:02:39 +0530 Subject: [PATCH] optimize size and time using "--no-cache-dir" Using "--no-cache-dir" flag in pip install ,make sure dowloaded packages by pip don't cached on system . This is a best practise which make sure to fetch ftom repo instead of using local cached one . Further , in case of Docker Containers , by restricing 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 --- 1.9-alpine3-onbuild/Dockerfile | 4 ++-- 1.9-alpine3/Dockerfile | 4 ++-- 1.9-debian8-onbuild/Dockerfile | 6 +++--- 1.9-debian8/Dockerfile | 6 +++--- alpine3-onbuild/Dockerfile | 4 ++-- alpine3/Dockerfile | 6 +++--- centos7/Dockerfile | 2 +- debian8-onbuild/Dockerfile | 6 +++--- debian8/Dockerfile | 8 ++++---- debian9-onbuild/Dockerfile | 4 ++-- debian9/Dockerfile | 4 ++-- master-centos7-onbuild/Dockerfile | 4 ++-- master-centos7/Dockerfile | 6 +++--- master-debian8-onbuild/Dockerfile | 4 ++-- master-debian8/Dockerfile | 4 ++-- master-debian9-onbuild/Dockerfile | 8 ++++---- master-debian9/Dockerfile | 8 ++++---- master-ubuntu16.04-onbuild/Dockerfile | 8 ++++---- master-ubuntu16.04/Dockerfile | 8 ++++---- master-ubuntu18.04-onbuild/Dockerfile | 8 ++++---- master-ubuntu18.04/Dockerfile | 8 ++++---- mini-alpine3/install-ansible.sh | 4 ++-- ubuntu14.04/Dockerfile | 2 +- ubuntu16.04/Dockerfile | 2 +- ubuntu18.04/Dockerfile | 2 +- 25 files changed, 65 insertions(+), 65 deletions(-) diff --git a/1.9-alpine3-onbuild/Dockerfile b/1.9-alpine3-onbuild/Dockerfile index edea781..0207fab 100644 --- a/1.9-alpine3-onbuild/Dockerfile +++ b/1.9-alpine3-onbuild/Dockerfile @@ -20,11 +20,11 @@ RUN echo "===> Installing sudo to emulate normal OS behavior..." && \ apk --update add python py-pip openssl ca-certificates && \ apk --update add --virtual build-dependencies \ python-dev libffi-dev openssl-dev build-base && \ - pip install --upgrade pip pycrypto cffi && \ + pip install --no-cache-dir --upgrade pip pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible==1.9.4 && \ + pip install --no-cache-dir ansible==1.9.4 && \ \ \ echo "===> Removing package list..." && \ diff --git a/1.9-alpine3/Dockerfile b/1.9-alpine3/Dockerfile index 1bfdbbe..2d0ea3b 100644 --- a/1.9-alpine3/Dockerfile +++ b/1.9-alpine3/Dockerfile @@ -20,11 +20,11 @@ RUN echo "===> Installing sudo to emulate normal OS behavior..." && \ apk --update add python py-pip openssl ca-certificates && \ apk --update add --virtual build-dependencies \ python-dev libffi-dev openssl-dev build-base && \ - pip install --upgrade pip pycrypto cffi && \ + pip install --no-cache-dir --upgrade pip pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible==1.9.4 && \ + pip install --no-cache-dir ansible==1.9.4 && \ \ \ echo "===> Installing handy tools (not absolutely required)..." && \ diff --git a/1.9-debian8-onbuild/Dockerfile b/1.9-debian8-onbuild/Dockerfile index 0ff07cc..c90c5ed 100644 --- a/1.9-debian8-onbuild/Dockerfile +++ b/1.9-debian8-onbuild/Dockerfile @@ -19,12 +19,12 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ python python-yaml sudo \ curl gcc python-pip python-dev libffi-dev libssl-dev && \ apt-get -y --purge remove python-cffi && \ - pip install --upgrade setuptools && \ - pip install --upgrade pycrypto cffi && \ + pip install --no-cache-dir --upgrade setuptools && \ + pip install --no-cache-dir --upgrade pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible==1.9.4 && \ + pip install --no-cache-dir ansible==1.9.4 && \ \ \ echo "===> Removing unused APT resources..." && \ diff --git a/1.9-debian8/Dockerfile b/1.9-debian8/Dockerfile index 5561b5b..d04c547 100644 --- a/1.9-debian8/Dockerfile +++ b/1.9-debian8/Dockerfile @@ -19,12 +19,12 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ python python-yaml sudo \ curl gcc python-pip python-dev libffi-dev libssl-dev && \ apt-get -y --purge remove python-cffi && \ - pip install --upgrade setuptools && \ - pip install --upgrade pycrypto cffi && \ + pip install --no-cache-dir --upgrade setuptools && \ + pip install --no-cache-dir --upgrade pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible==1.9.4 && \ + pip install --no-cache-dir ansible==1.9.4 && \ \ \ echo "===> Installing handy tools (not absolutely required)..." && \ diff --git a/alpine3-onbuild/Dockerfile b/alpine3-onbuild/Dockerfile index 1f9a151..06da4e9 100644 --- a/alpine3-onbuild/Dockerfile +++ b/alpine3-onbuild/Dockerfile @@ -20,11 +20,11 @@ RUN echo "===> Installing sudo to emulate normal OS behavior..." && \ apk --update add python py-pip openssl ca-certificates && \ apk --update add --virtual build-dependencies \ python-dev libffi-dev openssl-dev build-base && \ - pip install --upgrade pip pycrypto cffi && \ + pip install --no-cache-dir --upgrade pip pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible && \ + pip install --no-cache-dir ansible && \ \ \ echo "===> Removing package list..." && \ diff --git a/alpine3/Dockerfile b/alpine3/Dockerfile index dc711c9..fad1808 100644 --- a/alpine3/Dockerfile +++ b/alpine3/Dockerfile @@ -20,15 +20,15 @@ RUN echo "===> Installing sudo to emulate normal OS behavior..." && \ apk --update add python py-pip openssl ca-certificates && \ apk --update add --virtual build-dependencies \ python-dev libffi-dev openssl-dev build-base && \ - pip install --upgrade pip cffi && \ + pip install --no-cache-dir --upgrade pip cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible && \ + pip install --no-cache-dir ansible && \ \ \ echo "===> Installing handy tools (not absolutely required)..." && \ - pip install --upgrade pycrypto pywinrm && \ + pip install --no-cache-dir --upgrade pycrypto pywinrm && \ apk --update add sshpass openssh-client rsync && \ \ \ diff --git a/centos7/Dockerfile b/centos7/Dockerfile index 1595de5..d99dca4 100644 --- a/centos7/Dockerfile +++ b/centos7/Dockerfile @@ -52,7 +52,7 @@ RUN echo "===> Enabling systemd..." && \ \ echo "===> Installing handy tools (not absolutely required)..." && \ yum -y install python-pip && \ - pip install --upgrade pywinrm && \ + pip install --no-cache-dir --upgrade pywinrm && \ yum -y install sshpass openssh-clients && \ \ \ diff --git a/debian8-onbuild/Dockerfile b/debian8-onbuild/Dockerfile index d13d80c..7d895d4 100644 --- a/debian8-onbuild/Dockerfile +++ b/debian8-onbuild/Dockerfile @@ -19,12 +19,12 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ python python-yaml sudo \ curl gcc python-pip python-dev libffi-dev libssl-dev && \ apt-get -y --purge remove python-cffi && \ - pip install --upgrade setuptools && \ - pip install --upgrade pycrypto cffi && \ + pip install --no-cache-dir --upgrade setuptools && \ + pip install --no-cache-dir --upgrade pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible && \ + pip install --no-cache-dir ansible && \ \ \ echo "===> Removing unused APT resources..." && \ diff --git a/debian8/Dockerfile b/debian8/Dockerfile index 170aaa5..18266ab 100644 --- a/debian8/Dockerfile +++ b/debian8/Dockerfile @@ -19,9 +19,9 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ python python-yaml sudo \ curl gcc python-pip python-dev libffi-dev libssl-dev && \ apt-get -y --purge remove python-cffi && \ - pip install --upgrade setuptools && \ - pip install --upgrade pycrypto && \ - pip install --upgrade cffi pywinrm && \ + pip install --no-cache-dir --upgrade setuptools && \ + pip install --no-cache-dir --upgrade pycrypto && \ + pip install --no-cache-dir --upgrade cffi pywinrm && \ \ \ echo "===> Fix strange bug under Jessie: cannot import name IncompleteRead" && \ @@ -29,7 +29,7 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible && \ + pip install --no-cache-dir ansible && \ \ \ \ diff --git a/debian9-onbuild/Dockerfile b/debian9-onbuild/Dockerfile index f8476b4..0de0c3b 100644 --- a/debian9-onbuild/Dockerfile +++ b/debian9-onbuild/Dockerfile @@ -19,11 +19,11 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ python python-yaml sudo \ curl gcc python-pip python-dev libffi-dev libssl-dev && \ apt-get -y --purge remove python-cffi && \ - pip install --upgrade pycrypto cffi && \ + pip install --no-cache-dir --upgrade pycrypto cffi && \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible && \ + pip install --no-cache-dir ansible && \ \ \ echo "===> Removing unused APT resources..." && \ diff --git a/debian9/Dockerfile b/debian9/Dockerfile index 803646c..ebf6a30 100644 --- a/debian9/Dockerfile +++ b/debian9/Dockerfile @@ -19,12 +19,12 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ python python-yaml sudo \ curl gcc python-pip python-dev libffi-dev libssl-dev && \ apt-get -y --purge remove python-cffi && \ - pip install --upgrade pycrypto cffi pywinrm && \ + pip install --no-cache-dir --upgrade pycrypto cffi pywinrm && \ \ \ \ echo "===> Installing Ansible..." && \ - pip install ansible && \ + pip install --no-cache-dir ansible && \ \ \ \ diff --git a/master-centos7-onbuild/Dockerfile b/master-centos7-onbuild/Dockerfile index c64e4ab..39fd954 100644 --- a/master-centos7-onbuild/Dockerfile +++ b/master-centos7-onbuild/Dockerfile @@ -50,8 +50,8 @@ RUN echo "===> Enabling systemd..." && \ libffi-devel openssl-devel \ libxml2 libxml2-devel libxslt libxslt-devel \ git sudo curl && \ - pip install --upgrade pip && \ - pip install --upgrade \ + pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade \ pyyaml jinja2 pycrypto paramiko httplib2 && \ \ \ diff --git a/master-centos7/Dockerfile b/master-centos7/Dockerfile index 67b5191..641eadd 100644 --- a/master-centos7/Dockerfile +++ b/master-centos7/Dockerfile @@ -50,10 +50,10 @@ RUN echo "===> Enabling systemd..." && \ libffi-devel openssl-devel \ libxml2 libxml2-devel libxslt libxslt-devel \ git sudo curl && \ - pip install --upgrade pip && \ - pip install --upgrade \ + pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade \ pyyaml jinja2 pycrypto paramiko httplib2 && \ - pip install --upgrade pywinrm && \ + pip install --no-cache-dir --upgrade pywinrm && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-debian8-onbuild/Dockerfile b/master-debian8-onbuild/Dockerfile index 79b8ec9..60c168e 100644 --- a/master-debian8-onbuild/Dockerfile +++ b/master-debian8-onbuild/Dockerfile @@ -27,8 +27,8 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ echo "===> Fix strange bug under Jessie: cannot import name IncompleteRead" && \ easy_install -U pip && \ \ - pip install --upgrade cffi pywinrm && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ + pip install --no-cache-dir --upgrade cffi pywinrm && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-debian8/Dockerfile b/master-debian8/Dockerfile index d600520..5d78839 100644 --- a/master-debian8/Dockerfile +++ b/master-debian8/Dockerfile @@ -27,8 +27,8 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ echo "===> Fix strange bug under Jessie: cannot import name IncompleteRead" && \ easy_install -U pip && \ \ - pip install --upgrade cffi pywinrm && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ + pip install --no-cache-dir --upgrade cffi pywinrm && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-debian9-onbuild/Dockerfile b/master-debian9-onbuild/Dockerfile index 8df6c5f..59a58f9 100644 --- a/master-debian9-onbuild/Dockerfile +++ b/master-debian9-onbuild/Dockerfile @@ -23,10 +23,10 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ git sudo curl && \ echo "--> Upgrading pip..." && \ # @see https://github.com/pypa/pip/issues/5240#issuecomment-383129401 && \ - python -m pip install --upgrade pip && \ - pip install --upgrade setuptools wheel && \ - pip install --upgrade cffi && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ + python -m pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade setuptools wheel && \ + pip install --no-cache-dir --upgrade cffi && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-debian9/Dockerfile b/master-debian9/Dockerfile index 1ba99fa..e0d860f 100644 --- a/master-debian9/Dockerfile +++ b/master-debian9/Dockerfile @@ -23,10 +23,10 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ git sudo curl && \ echo "--> Upgrading pip..." && \ # @see https://github.com/pypa/pip/issues/5240#issuecomment-383129401 && \ - python -m pip install --upgrade pip && \ - pip install --upgrade setuptools wheel && \ - pip install --upgrade cffi pywinrm && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ + python -m pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade setuptools wheel && \ + pip install --no-cache-dir --upgrade cffi pywinrm && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-ubuntu16.04-onbuild/Dockerfile b/master-ubuntu16.04-onbuild/Dockerfile index bf981e5..3f48b3d 100644 --- a/master-ubuntu16.04-onbuild/Dockerfile +++ b/master-ubuntu16.04-onbuild/Dockerfile @@ -23,10 +23,10 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ git && \ echo "--> Upgrading pip..." && \ # @see https://github.com/pypa/pip/issues/5240#issuecomment-383129401 && \ - python -m pip install --upgrade pip && \ - pip install --upgrade setuptools wheel && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ - pip install --upgrade pywinrm && \ + python -m pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade setuptools wheel && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ + pip install --no-cache-dir --upgrade pywinrm && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-ubuntu16.04/Dockerfile b/master-ubuntu16.04/Dockerfile index ab15d84..c9e849f 100644 --- a/master-ubuntu16.04/Dockerfile +++ b/master-ubuntu16.04/Dockerfile @@ -23,10 +23,10 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ git && \ echo "--> Upgrading pip..." && \ # @see https://github.com/pypa/pip/issues/5240#issuecomment-383129401 && \ - python -m pip install --upgrade pip && \ - pip install --upgrade setuptools wheel && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ - pip install --upgrade pywinrm && \ + python -m pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade setuptools wheel && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ + pip install --no-cache-dir --upgrade pywinrm && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-ubuntu18.04-onbuild/Dockerfile b/master-ubuntu18.04-onbuild/Dockerfile index 6343f67..f73a2d3 100644 --- a/master-ubuntu18.04-onbuild/Dockerfile +++ b/master-ubuntu18.04-onbuild/Dockerfile @@ -23,10 +23,10 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ git && \ echo "--> Upgrading pip..." && \ # @see https://github.com/pypa/pip/issues/5240#issuecomment-383129401 && \ - python -m pip install --upgrade pip && \ - pip install --upgrade setuptools wheel && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ - pip install --upgrade pywinrm && \ + python -m pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade setuptools wheel && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ + pip install --no-cache-dir --upgrade pywinrm && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/master-ubuntu18.04/Dockerfile b/master-ubuntu18.04/Dockerfile index 7d36f22..8f96ece 100644 --- a/master-ubuntu18.04/Dockerfile +++ b/master-ubuntu18.04/Dockerfile @@ -23,10 +23,10 @@ RUN echo "===> Adding Ansible's prerequisites..." && \ git && \ echo "--> Upgrading pip..." && \ # @see https://github.com/pypa/pip/issues/5240#issuecomment-383129401 && \ - python -m pip install --upgrade pip && \ - pip install --upgrade setuptools wheel && \ - pip install --upgrade pyyaml jinja2 pycrypto && \ - pip install --upgrade pywinrm && \ + python -m pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade setuptools wheel && \ + pip install --no-cache-dir --upgrade pyyaml jinja2 pycrypto && \ + pip install --no-cache-dir --upgrade pywinrm && \ \ \ echo "===> Downloading Ansible's source tree..." && \ diff --git a/mini-alpine3/install-ansible.sh b/mini-alpine3/install-ansible.sh index 98dede0..a24b072 100755 --- a/mini-alpine3/install-ansible.sh +++ b/mini-alpine3/install-ansible.sh @@ -13,12 +13,12 @@ cat ___APK_INSTALL_LIST | \ cat ___PIP_INSTALL_LIST | \ while read ITEM; do - pip install --upgrade $ITEM + pip install --no-cache-dir --upgrade $ITEM done echo "===> Installing Ansible..." -pip install ansible +pip install --no-cache-dir ansible echo "===> Adding hosts for convenience..." && \ diff --git a/ubuntu14.04/Dockerfile b/ubuntu14.04/Dockerfile index 63a5cc2..746ebfc 100644 --- a/ubuntu14.04/Dockerfile +++ b/ubuntu14.04/Dockerfile @@ -25,7 +25,7 @@ RUN echo "===> Adding Ansible's PPA..." && \ \ echo "===> Installing handy tools (not absolutely required)..." && \ #apt-get install -y python-pip && \ - #pip install --upgrade pywinrm && \ + #pip install --no-cache-dir --upgrade pywinrm && \ apt-get install -y sshpass openssh-client && \ \ \ diff --git a/ubuntu16.04/Dockerfile b/ubuntu16.04/Dockerfile index 759c77a..4e832cf 100644 --- a/ubuntu16.04/Dockerfile +++ b/ubuntu16.04/Dockerfile @@ -25,7 +25,7 @@ RUN echo "===> Adding Ansible's PPA..." && \ \ echo "===> Installing handy tools (not absolutely required)..." && \ apt-get install -y python-pip && \ - pip install --upgrade pycrypto pywinrm && \ + pip install --no-cache-dir --upgrade pycrypto pywinrm && \ apt-get install -y sshpass openssh-client && \ \ \ diff --git a/ubuntu18.04/Dockerfile b/ubuntu18.04/Dockerfile index ab78c34..4425bd3 100644 --- a/ubuntu18.04/Dockerfile +++ b/ubuntu18.04/Dockerfile @@ -26,7 +26,7 @@ RUN echo "===> Adding Ansible's PPA..." && \ \ echo "===> Installing handy tools (not absolutely required)..." && \ apt-get install -y python-pip && \ - pip install --upgrade pycrypto pywinrm && \ + pip install --no-cache-dir --upgrade pycrypto pywinrm && \ apt-get install -y sshpass openssh-client && \ \ \