From 5b730bf89f7f10753efce341da5e2d798d08a1a6 Mon Sep 17 00:00:00 2001
From: andryyy <andre.peters@debinux.de>
Date: Sat, 25 May 2019 22:29:25 +0200
Subject: [PATCH] [Update] Prefetch images, big thanks to everyone in #2637!

---
 update.sh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/update.sh b/update.sh
index 67645b55..b3e4043a 100755
--- a/update.sh
+++ b/update.sh
@@ -9,6 +9,9 @@ fi
 # Exit on error and pipefail
 set -o pipefail
 
+# Setting high dc timeout
+export COMPOSE_HTTP_TIMEOUT=300
+
 # Add /opt/bin to PATH
 PATH=$PATH:/opt/bin
 
@@ -292,6 +295,18 @@ if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
   exit 0
 fi
 
+echo -e "\e[32mPrefetching images...\e[0m"
+while read image; do
+  RET_C=0
+  until docker pull ${image}; do
+    RET_C=$((RET_C + 1))
+    echo -e "\e[33m\nError pulling $image, retrying...\e[0m"
+    [ ${RET_C} -gt 3 ] && { echo -e "\e[31m\nToo many failed retries, exiting\e[0m"; exit 1; }
+    sleep 1
+  done
+done < <(git show origin/${BRANCH}:docker-compose.yml | grep "image:" | awk '{ gsub("image:","", $3); print $2 }')
+
+
 echo -e "Stopping mailcow... "
 sleep 2
 docker-compose down