From 63ec1a4287387ce67ba9a0e21309a6bc2550fce3 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 26 Jan 2014 21:55:21 -0800 Subject: [PATCH] build.sh: Use DOCKER to allow local command overrides 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 | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/build.sh b/build.sh index 88dc3c1..b2a822d 100755 --- 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 -- 2.26.2