From 5f12245d6c8c2ed75778bff79e2f9693dcf101ca Mon Sep 17 00:00:00 2001 From: Joe Beda Date: Fri, 10 Oct 2014 13:33:11 -0700 Subject: [PATCH] Make 'build' commands work with non-interactive shells. Tested that both './build/release.sh < /dev/null' and './build/shell.sh' work. --- build/common.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/build/common.sh b/build/common.sh index 6fdff99596b..caf92cdfef3 100644 --- a/build/common.sh +++ b/build/common.sh @@ -343,10 +343,23 @@ function kube::build::run_build_command() { kube::build::prepare_output + local -a docker_run_opts=( + "--name=${KUBE_BUILD_CONTAINER_NAME}" + "${DOCKER_MOUNT_ARGS[@]}" + ) + + # If we have stdin we can run interactive. This allows things like 'shell.sh' + # to work. However, if we run this way and don't have stdin, then it ends up + # running in a daemon-ish mode. So if we don't have a stdin, we explicitly + # attach stderr/stdout but don't bother asking for a tty. + if [[ -t 0 ]]; then + docker_run_opts+=(--interactive --tty) + else + docker_run_opts+=(--attach=stdout --attach=stderr) + fi + local -ra docker_cmd=( - docker run "--name=${KUBE_BUILD_CONTAINER_NAME}" - --interactive --tty - "${DOCKER_MOUNT_ARGS[@]}" "${KUBE_BUILD_IMAGE}") + docker run "${docker_run_opts[@]}" "${KUBE_BUILD_IMAGE}") # Remove the container if it is left over from some previous aborted run docker rm "${KUBE_BUILD_CONTAINER_NAME}" >/dev/null 2>&1 || true