build.sh: Use DOCKER to allow local command overrides
authorW. Trevor King <wking@tremily.us>
Mon, 27 Jan 2014 05:55:21 +0000 (21:55 -0800)
committerW. Trevor King <wking@tremily.us>
Tue, 28 Jan 2014 18:49:36 +0000 (10:49 -0800)
On Debian, the binary is installed as docker.io [1] to avoid confusion
with the existing window manager docker package [2].

While you can override DOCKER, it would be nice if we just worked out
of the box for everyone.  Use 'command -v' [3] and the temporary
DOCKER_IO to setup the following chain:

1. If DOCKER is already set (e.g., by the user) use it.
2. Fall back to docker.io, if we find it in the PATH.
3. Fall back to docker.

The logic is that if docker.io exists, it's almost certainly what we
want.  If docker exists in the path, it's more ambiguous.

[1]: http://packages.debian.org/unstable/docker.io
[2]: http://packages.debian.org/unstable/docker
[3]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html

build.sh

index 88dc3c171c07f02b5d04ea8aae4eebc8dc2db39a..b2a822d33186f7ba8e5f317d6f207b75bb21208e 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -36,6 +36,9 @@ PORTAGE_URL="${PORTAGE_URL:-${MIRROR}snapshots/}"
 PORTAGE="${PORTAGE:-portage-${DATE}.tar.xz}"
 PORTAGE_SIG="${PORTAGE_SIG:-${PORTAGE}.gpgsig}"
 
+DOCKER_IO=$(command -v docker.io)
+DOCKER="${DOCKER:-${DOCKER_IO:-docker}}"
+
 REPOS="${REPOS:-
        portage
        gentoo-portage
@@ -69,7 +72,7 @@ if [ -z "${REALPATH}" ]; then
        fi
 fi
 
-STAGE3_IMAGES=$(docker images "${NAMESPACE}/gentoo")
+STAGE3_IMAGES=$("${DOCKER}" images "${NAMESPACE}/gentoo")
 STAGE3_MATCHES=$(echo "${STAGE3_IMAGES}" | grep "${DATE}")
 if [ -z "${STAGE3_MATCHES}" ]; then
        # import stage3 image from Gentoo mirrors
@@ -88,12 +91,12 @@ if [ -z "${STAGE3_MATCHES}" ]; then
                die "${SHA512_FAILED}"
        fi
 
-       docker import - "${NAMESPACE}/gentoo:${DATE}" < "downloads/${STAGE3}" || die "failed to import"
+       "${DOCKER}" import - "${NAMESPACE}/gentoo:${DATE}" < "downloads/${STAGE3}" || die "failed to import"
 fi
 
-docker tag -f "${NAMESPACE}/gentoo:${DATE}" "${NAMESPACE}/gentoo:latest" || die "failed to tag"
+"${DOCKER}" tag -f "${NAMESPACE}/gentoo:${DATE}" "${NAMESPACE}/gentoo:latest" || die "failed to tag"
 
-PORTAGE_IMAGES=$(docker images "${NAMESPACE}/portage-import")
+PORTAGE_IMAGES=$("${DOCKER}" images "${NAMESPACE}/portage-import")
 PORTAGE_MATCHES=$(echo "${PORTAGE_IMAGES}" | grep "${DATE}")
 if [ -z "${PORTAGE_MATCHES}" ]; then
        # import portage image from Gentoo mirrors
@@ -106,19 +109,19 @@ if [ -z "${PORTAGE_MATCHES}" ]; then
 
        gpg --verify "downloads/${PORTAGE_SIG}" "downloads/${PORTAGE}" || die "insecure digests"
 
-       docker import - "${NAMESPACE}/portage-import:${DATE}" < "downloads/${PORTAGE}" || die "failed to import"
+       "${DOCKER}" import - "${NAMESPACE}/portage-import:${DATE}" < "downloads/${PORTAGE}" || die "failed to import"
 fi
 
-docker tag -f "${NAMESPACE}/portage-import:${DATE}" "${NAMESPACE}/portage-import:latest" || die "failed to tag"
+"${DOCKER}" tag -f "${NAMESPACE}/portage-import:${DATE}" "${NAMESPACE}/portage-import:latest" || die "failed to tag"
 
 # extract Busybox for the portage image
 THIS_DIR=$(dirname $($REALPATH $0))
 CONTAINER="${NAMESPACE}-gentoo-${DATE}-extract-busybox"
-docker run -name "${CONTAINER}" -v "${THIS_DIR}/portage/":/tmp "${NAMESPACE}/gentoo:${DATE}" cp /bin/busybox /tmp/
-docker rm "${CONTAINER}"
+"${DOCKER}" run -name "${CONTAINER}" -v "${THIS_DIR}/portage/":/tmp "${NAMESPACE}/gentoo:${DATE}" cp /bin/busybox /tmp/
+"${DOCKER}" rm "${CONTAINER}"
 
 for REPO in ${REPOS}; do
-       REPO_IMAGES=$(docker images "${NAMESPACE}/${REPO}")
+       REPO_IMAGES=$("${DOCKER}" images "${NAMESPACE}/${REPO}")
        REPO_MATCHES=$(echo "${REPO_IMAGES}" | grep "${DATE}")
        if [ -z "${REPO_MATCHES}" ]; then
                env -i \
@@ -131,7 +134,7 @@ for REPO in ${REPOS}; do
                                ${MAINTAINER}
                                ' \
                                < "${REPO}/Dockerfile.template" > "${REPO}/Dockerfile"
-               docker build -t "${NAMESPACE}/${REPO}:${DATE}" "${REPO}" || die "failed to build"
+               "${DOCKER}" build -t "${NAMESPACE}/${REPO}:${DATE}" "${REPO}" || die "failed to build"
        fi
-       docker tag -f "${NAMESPACE}/${REPO}:${DATE}" "${NAMESPACE}/${REPO}:latest" || die "failed to tag"
+       "${DOCKER}" tag -f "${NAMESPACE}/${REPO}:${DATE}" "${NAMESPACE}/${REPO}:latest" || die "failed to tag"
 done