Bug 1290531 - Move docker validation from build.sh to Python; r=dustin
authorGregory Szorc <gps@mozilla.com>
Fri, 29 Jul 2016 12:58:39 -0700
changeset 307532 95aeafbfec097edaa2ce746811cb1d1de63a7d40
parent 307531 4509921b0cfd298f27e5164d8ee6361fb2ae2eb2
child 307533 a1f4555494b7aa5ebc6dcdae45315e1ac2ab0bb4
push id30514
push usercbook@mozilla.com
push dateTue, 02 Aug 2016 15:04:11 +0000
treeherdermozilla-central@ea6e87bbd03e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdustin
bugs1290531
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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 $*