Merge pull request #218 from bassamtabbara/build-concurrent

build: support concurrent runs of build/run
This commit is contained in:
Bassam Tabbara
2016-11-17 22:14:05 -08:00
committed by GitHub
3 changed files with 33 additions and 39 deletions
+7 -6
View File
@@ -17,13 +17,14 @@
scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${scriptdir}/common.sh"
if [[ $(docker ps -f name=${container_name} | grep -w ${container_name}) ]]; then
docker stop ${container_name}
docker rm ${container_name}
fi
# this should only clean up leaked containers during rsync
for c in $(docker ps -a -q --filter=ancestor=${container_image}); do
echo removing container ${c}
docker stop ${c}
docker rm ${c}
done
if [[ $(docker volume ls | grep ${container_volume}) ]]; then
echo removing volume ${container_volume}
docker volume rm ${container_volume}
fi
echo SUCCESS
+20 -12
View File
@@ -18,8 +18,7 @@ source_repo=github.com/rook/rook
container_version=$(cat ${scriptdir}/cross-image/version)
container_image=quay.io/rook/cross-build:${container_version}
container_name=cross-build
container_volume=${container_name}-volume
container_volume=cross-build-volume
rsync_port=10873
function ver() {
@@ -51,11 +50,20 @@ function wait_for_rsync() {
exit 1
}
function start_and_wait_for_rsyncd() {
function cleanup_container() {
id=$1
docker stop ${id} &> /dev/null || true
docker rm ${id} &> /dev/null || true
}
function run_rsync() {
source=$1
dest=$2
# run the container as an rsyncd daemon so that we can copy the
# source tree to the container volume.
docker run \
--name "${container_name}" \
id=$(docker run \
-d \
-e OWNER=root \
-e GROUP=root \
@@ -64,13 +72,11 @@ function start_and_wait_for_rsyncd() {
--entrypoint /bin/bash \
-v ${container_volume}:/volume \
${container_image} \
/build/rsyncd.sh &> /dev/null
/build/rsyncd.sh)
# wait for rsync to come up
wait_for_rsync
}
wait_for_rsync || cleanup_container ${id}
function run_rsync() {
rsync \
--archive \
--delete \
@@ -80,6 +86,8 @@ function run_rsync() {
--filter='- /.vscode/' \
--filter='- /bin/' \
--filter='- /release/' \
${1} \
${2}
}
${source} \
${dest} || cleanup_container ${id}
cleanup_container ${id}
}
+6 -21
View File
@@ -35,11 +35,6 @@ fi
USER_ARGS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g )"
BUILDER_HOME=/home/rook
cleanup() {
docker stop ${container_name} &> /dev/null || true
docker rm ${container_name} &> /dev/null || true
}
# mount arguments
MOUNT_OPTS="\
-v ${scriptdir}/../bin:${BUILDER_HOME}/go/src/${source_repo}/bin \
@@ -67,18 +62,16 @@ if [ "`uname -s`" != "Linux" ]; then
# /src/github.com/rook/rook (rsync'd from host <source>)
#
# create a new volume to hold our go workspace
# create a new volume to hold our go workspace. NOTE: while concurrent
# runs of the build container are supported they will share the same volume
# and we will be rsyncing to it at different times. This could lead to
# undefined behavior but this should be a rare case on non-linux envs.
if [[ ! $(docker volume ls | grep ${container_volume}) ]]; then
echo ==== Syncing sources for first time. This could take a few seconds.
echo ==== Creating docker volume "${container_volume}" and syncing sources
echo ==== for first time. This could take a few seconds.
docker volume create --name ${container_volume} &> /dev/null
fi
trap "cleanup" EXIT
cleanup
# start rsyncd inside the container so that we can rsync files into it
start_and_wait_for_rsyncd
# now copy the source tree to the container volume
run_rsync ${scriptdir}/.. rsync://localhost:${rsync_port}/volume/src/${source_repo}
@@ -128,12 +121,8 @@ if [ -z "${DISABLE_NESTED_DOCKER}" ]; then
-v /var/run/docker.sock:/var/run/docker.sock"
fi
trap "cleanup" EXIT
cleanup
docker run \
--rm \
--name "${container_name}" \
-e GOPATH="${BUILDER_HOME}/go" \
-e WORKDIR="${BUILDER_HOME}/go/.work" \
-e GO_PKG_DIR="" \
@@ -154,10 +143,6 @@ docker run \
# copy some folders back to the source. We avoid a bind mount here
# due to https://github.com/rook/rook/issues/93
if [ "`uname -s`" != "Linux" ]; then
start_and_wait_for_rsyncd
run_rsync rsync://localhost:${rsync_port}/volume/src/${source_repo}/vendor ${scriptdir}/..
run_rsync rsync://localhost:${rsync_port}/volume/src/${source_repo}/tools ${scriptdir}/..
fi