Bug 1290531 - Move docker validation from build.sh to Python; r?dustin draft
authorGregory Szorc <gps@mozilla.com>
Fri, 29 Jul 2016 12:58:39 -0700
changeset 395033 c2c37d6888c4acfb0a0204118cbb42d58efd5088
parent 395032 ec5be7ea360563e940edbfe919986c83712164bd
child 395034 d56e5fb1b16db4f8e6d9943f8e66314d1ac9cdb0
push id24705
push userbmo:gps@mozilla.com
push dateMon, 01 Aug 2016 18:26:57 +0000
reviewersdustin
bugs1290531
milestone50.0a1
Bug 1290531 - Move docker validation from build.sh to Python; r?dustin Now that we have a mach command and Python code for doing Docker image building, we can start moving code from build.sh to Python. We start with searching for and validating the `docker` binary works. MozReview-Commit-ID: 2DCc3b8UyZ3
taskcluster/taskgraph/docker.py
testing/docker/build.sh
--- a/taskcluster/taskgraph/docker.py
+++ b/taskcluster/taskgraph/docker.py
@@ -6,16 +6,17 @@
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import json
 import os
 import subprocess
 import tarfile
 import urllib2
+import which
 
 from taskgraph.util import docker
 
 GECKO = os.path.realpath(os.path.join(__file__, '..', '..', '..'))
 IMAGE_DIR = os.path.join(GECKO, 'testing', 'docker')
 INDEX_URL = 'https://index.taskcluster.net/v1/task/docker.images.v1.{}.{}.hash.{}'
 ARTIFACT_URL = 'https://queue.taskcluster.net/v1/task/{}/artifacts/{}'
 
@@ -64,12 +65,21 @@ def load_image_by_task_id(task_id):
     print("Try: docker run -ti --rm {} bash".format(name))
 
 
 def build_image(name):
     """Build a Docker image of specified name.
 
     Output from image building process will be printed to stdout.
     """
+    docker_bin = which.which('docker')
+
+    # Verify that Docker is working.
+    try:
+        subprocess.check_output([docker_bin, '--version'])
+    except subprocess.CalledProcessError:
+        raise Exception('Docker server is unresponsive. Run `docker ps` and '
+                        'check that Docker is running')
+
     args = [os.path.join(IMAGE_DIR, 'build.sh'), name]
     res = subprocess.call(args, cwd=IMAGE_DIR)
     if res:
         raise Exception('error building image')
--- a/testing/docker/build.sh
+++ b/testing/docker/build.sh
@@ -79,26 +79,9 @@ build() {
     echo "However, the image can be run locally. To prepare to "
     echo "push to a user account on a docker registry, tag the image "
     echo "by running 'docker tag $tag [REGISTRYHOST/][USERNAME/]NAME[:TAG]"
     echo "prior to running 'docker push'."
     echo "*****************************************************************"
   fi
 }
 
-if ! which docker > /dev/null; then
-  echo "Docker must be installed read installation instructions at docker.com"
-  echo
-  usage
-  exit 1
-fi
-
-# TODO: In the future we should check minimum docker version it does matter.
-if ! docker version > /dev/null;
-then
-  echo "Docker server is unresponsive run 'docker ps' and check that docker is"
-  echo "running"
-  echo
-  usage
-  exit 1
-fi
-
 build $*