From bfb1f049952898ce3e06d596aec56db694ad7796 Mon Sep 17 00:00:00 2001
From: Tamas Gal <tgal@km3net.de>
Date: Tue, 13 Nov 2018 17:57:29 +0100
Subject: [PATCH] Try to download existing images to save build time

---
 publish_images.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/publish_images.py b/publish_images.py
index c32156b..3f35b94 100755
--- a/publish_images.py
+++ b/publish_images.py
@@ -14,6 +14,16 @@ def main():
     for idx, fname in enumerate(dockerfiles):
         progress = "({}/{})".format(idx + 1, n_files)
 
+        print('-' * 79)
+        print("{} Checking for existing '{}'".format(progress, fname))
+        pull_cmd = ("docker pull {0}/{1}".format(REGISTRY_URL, fname))
+        child = sp.Popen(
+            pull_cmd, shell=True, stdout=sys.stdout, stderr=sp.PIPE)
+        child.communicate()
+        if child.returncode > 0:
+            print("  -> no image found for '{}', starting from scratch.".
+                  format(fname))
+
         print('-' * 79)
         print("{} Building '{}'".format(progress, fname))
         build_cmd = ("docker build --pull -t {0}/{1} -f {1} . ".format(
@@ -28,5 +38,6 @@ def main():
             push_cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
         child.communicate()
 
+
 if __name__ == '__main__':
     main()
-- 
GitLab