Fix boot2docker with /User mapping.

Fixes #1856

Based on #1858 from @nyaxt.
This commit is contained in:
Joe Beda 2014-10-17 13:56:16 -07:00
parent e04fabdd09
commit e48cbb2296

View File

@ -371,42 +371,38 @@ function kube::build::run_build_command() {
docker rm "${KUBE_BUILD_CONTAINER_NAME}" >/dev/null 2>&1 || true docker rm "${KUBE_BUILD_CONTAINER_NAME}" >/dev/null 2>&1 || true
} }
# Test if the output directory is remote (and can only be accessed through
# docker) or if it is "local" and we can access the output without going through
# docker.
function kube::build::is_output_remote() {
rm -f "${LOCAL_OUTPUT_BUILD}/test_for_remote"
kube::build::run_build_command touch "${REMOTE_OUTPUT_DIR}/test_for_remote"
[[ ! -e "${LOCAL_OUTPUT_BUILD}/test_for_remote" ]]
}
# If the Docker server is remote, copy the results back out. # If the Docker server is remote, copy the results back out.
function kube::build::copy_output() { function kube::build::copy_output() {
if kube::build::is_osx; then if kube::build::is_output_remote; then
# Docker 1.3 on OS X handles this properly, so bail. # When we are on the Mac with boot2docker (or to a remote Docker in any
docker_version=$(docker version 2> /dev/null | sed -n 1p | awk '{ print $3 }') # other situation) we need to copy the results back out. Ideally we would
# TODO: this will start breaking with Docker 1.4, but at that point we should # leave the container around and use 'docker cp' to copy the results out.
# just delete this whole function and force people to upgrade. # However, that doesn't work for mounted volumes currently
if [[ "$docker_version" == "1.3."* ]]; then # (https://github.com/dotcloud/docker/issues/1992). And it is just plain
return # broken (https://github.com/dotcloud/docker/issues/6483).
fi
# When we are on the Mac with boot2docker we need to copy the results back
# out. Ideally we would leave the container around and use 'docker cp' to
# copy the results out. However, that doesn't work for mounted volumes
# currently (https://github.com/dotcloud/docker/issues/1992). And it is
# just plain broken (https://github.com/dotcloud/docker/issues/6483).
# #
# The easiest thing I (jbeda) could figure out was to launch another # The easiest thing I (jbeda) could figure out was to launch another
# container pointed at the same volume, tar the output directory and ship # container pointed at the same volume, tar the output directory and ship
# that tar over stdou. # that tar over stdout.
local -ra docker_cmd=(
docker run -a stdout "--name=${KUBE_BUILD_CONTAINER_NAME}"
"${DOCKER_MOUNT_ARGS[@]}" "${KUBE_BUILD_IMAGE}")
# Kill any leftover container
docker rm "${KUBE_BUILD_CONTAINER_NAME}" >/dev/null 2>&1 || true
echo "+++ Syncing back _output directory from boot2docker VM" echo "+++ Syncing back _output directory from boot2docker VM"
rm -rf "${LOCAL_OUTPUT_BUILD}" rm -rf "${LOCAL_OUTPUT_BUILD}"
mkdir -p "${LOCAL_OUTPUT_BUILD}" mkdir -p "${LOCAL_OUTPUT_BUILD}"
"${docker_cmd[@]}" sh -c "tar c -C ${REMOTE_OUTPUT_DIR} . ; sleep 1" \
| tar xv -C "${LOCAL_OUTPUT_BUILD}"
# Remove the container after we run. '--rm' might be appropriate but it # The '</dev/null' here makes us run docker in a "non-interactive" mode. Not
# appears that sometimes it fails. See # doing this corrupts the output stream.
# https://github.com/docker/docker/issues/3968 kube::build::run_build_command sh -c "tar c -C ${REMOTE_OUTPUT_DIR} . ; sleep 1" </dev/null \
docker rm "${KUBE_BUILD_CONTAINER_NAME}" >/dev/null 2>&1 || true | tar xv -C "${LOCAL_OUTPUT_BUILD}"
# I (jbeda) also tried getting rsync working using 'docker run' as the # I (jbeda) also tried getting rsync working using 'docker run' as the
# 'remote shell'. This mostly worked but there was a hang when # 'remote shell'. This mostly worked but there was a hang when
@ -415,6 +411,8 @@ function kube::build::copy_output() {
# local DOCKER="docker run -i --rm --name=${KUBE_BUILD_CONTAINER_NAME} ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" # local DOCKER="docker run -i --rm --name=${KUBE_BUILD_CONTAINER_NAME} ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}"
# DOCKER+=" bash -c 'shift ; exec \"\$@\"' --" # DOCKER+=" bash -c 'shift ; exec \"\$@\"' --"
# rsync --blocking-io -av -e "${DOCKER}" foo:${REMOTE_OUTPUT_DIR}/ ${LOCAL_OUTPUT_BUILD} # rsync --blocking-io -av -e "${DOCKER}" foo:${REMOTE_OUTPUT_DIR}/ ${LOCAL_OUTPUT_BUILD}
else
echo "+++ Output directory is local. No need to copy results out."
fi fi
} }