optimize size and time using "--no-cache-dir" 61/108861/1
authorPratik Raj <rajpratik71@gmail.com>
Sat, 6 Jun 2020 16:16:26 +0000 (21:46 +0530)
committerPratik Raj <rajpratik71@gmail.com>
Sat, 6 Jun 2020 16:23:42 +0000 (21:53 +0530)
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

Issue-ID: MULTICLOUD-1080

Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
Change-Id: Ib79fae7e69eb669e39bc3eb52373668367460ba2

kud/hosting_providers/containerized/installer.sh
kud/hosting_providers/vagrant/installer.sh
kud/hosting_providers/vagrant/setup.sh
kud/tests/_common_test.sh
kud/tests/cFW/postinstall.sh
tox.ini

index fe9d1e9..5e46d96 100755 (executable)
@@ -33,7 +33,7 @@ function _install_ansible {
     local version=$(grep "ansible_version" ${kud_playbooks}/kud-vars.yml |
         awk -F ': ' '{print $2}')
     mkdir -p /etc/ansible/
-    pip install ansible==$version
+    pip install --no-cache-dir ansible==$version
 }
 
 # install_k8s() - Install Kubernetes using kubespray tool
@@ -56,7 +56,7 @@ function install_kubespray {
     rm $tarball
 
     pushd $dest_folder/kubespray-$version/
-    pip install -r ./requirements.txt
+    pip install --no-cache-dir -r ./requirements.txt
     make mitogen
     popd
     rm -f $kud_inventory_folder/group_vars/all.yml 2> /dev/null
index 7b8b28d..27ab7fc 100755 (executable)
@@ -41,7 +41,7 @@ function _install_go {
 # _install_pip() - Install Python Package Manager
 function _install_pip {
     if $(pip --version &>/dev/null); then
-        sudo -E pip install --upgrade pip
+        sudo -E pip install --no-cache-dir --upgrade pip
     else
         sudo apt-get install -y python-dev
         curl -sL https://bootstrap.pypa.io/get-pip.py | sudo python
@@ -56,7 +56,7 @@ function _install_ansible {
     _install_pip
     local version=$(grep "ansible_version" ${kud_playbooks}/kud-vars.yml | awk -F ': ' '{print $2}')
     sudo mkdir -p /etc/ansible/
-    sudo -E pip install ansible==$version
+    sudo -E pip install --no-cache-dir ansible==$version
 }
 
 # _install_docker() - Download and install docker-engine
@@ -123,7 +123,7 @@ function install_k8s {
     rm $tarball
 
     pushd $dest_folder/kubespray-$version/
-    sudo -E pip install -r ./requirements.txt
+    sudo -E pip install --no-cache-dir -r ./requirements.txt
     make mitogen
     popd
     rm -f $kud_inventory_folder/group_vars/all.yml 2> /dev/null
@@ -175,7 +175,7 @@ function install_plugin {
     echo "Installing multicloud/k8s plugin"
     _install_go
     _install_docker
-    sudo -E pip install docker-compose
+    sudo -E pip install --no-cache-dir docker-compose
 
     sudo mkdir -p /opt/{kubeconfig,consul/config}
     sudo cp $HOME/.kube/config /opt/kubeconfig/kud
index 9c65ccd..00b6e86 100755 (executable)
@@ -178,9 +178,9 @@ ${INSTALLER_CMD} "${packages[@]}"
 if ! which pip; then
     curl -sL https://bootstrap.pypa.io/get-pip.py | sudo python
 else
-    sudo -H -E pip install --upgrade pip
+    sudo -H -E pip install --no-cache-dir --upgrade pip
 fi
-sudo -H -E pip install tox
+sudo -H -E pip install --no-cache-dir tox
 if [[ ${http_proxy+x} ]]; then
     vagrant plugin install vagrant-proxyconf
 fi
index 32781e1..0ca606b 100755 (executable)
@@ -36,7 +36,7 @@ function install_ipcalc {
 function install_ovn_deps {
     if ! $(yq --version &>/dev/null); then
         install_deps # jq needed as it's dependency of yq
-        sudo -E pip install yq
+        sudo -E pip install --no-cache-dir yq
     fi
     if ! $(ovn-nbctl --version &>/dev/null); then
         function ovn_ubuntu_deps {
index 5a1d504..ec2cba4 100755 (executable)
@@ -57,8 +57,8 @@ function install_docker_compose {
     if ! which pip; then
         curl -sL https://bootstrap.pypa.io/get-pip.py | python
     fi
-    pip install --upgrade pip
-    pip install docker-compose
+    pip install --no-cache-dir --upgrade pip
+    pip install --no-cache-dir docker-compose
 }
 
 echo 'vm.nr_hugepages = 1024' >> /etc/sysctl.conf
diff --git a/tox.ini b/tox.ini
index 5cebea8..7c66248 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -15,7 +15,7 @@ envlist = bashate
 [testenv]
 passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
 usedevelop = False
-install_command = pip install {opts} {packages}
+install_command = pip install --no-cache-dir {opts} {packages}
 
 [testenv:bashate]
 deps =