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
--- 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 $*