diff options
author | Christophe Lyon <christophe.lyon@linaro.org> | 2019-09-11 07:59:28 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-09-11 08:59:48 +0000 |
commit | 2b6a0349c5ee1cc3cecd500318b811215b75c5ef (patch) | |
tree | 9d5706602e16aefa906d4bd85a60bff9347cd018 /start-container-docker.sh | |
parent | 499973365157b6de534bb1bf103a7f5fac21ca23 (diff) |
start-container-docker.sh: Create workspace lock only when ...
... bind-mounting $WORKSPACE.
Change-Id: I49d9081892e986f4dc437cef39fef337f3054ee6
Diffstat (limited to 'start-container-docker.sh')
-rwxr-xr-x | start-container-docker.sh | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/start-container-docker.sh b/start-container-docker.sh index d489d2aa..3a214425 100755 --- a/start-container-docker.sh +++ b/start-container-docker.sh @@ -244,10 +244,15 @@ if $SSH $session_host test -f "/.dockerenv" \ docker_root=$($DOCKER info | grep "Docker Root Dir:" | cut -d: -f 2) fi +bind_mounted_workspace=false bind_mounts_opt=() for bind_mount in "${bind_mounts[@]}"; do dir="${bind_mount%%:*}" + if [ x"$dir" = x"$WORKSPACE" ]; then + bind_mounted_workspace=true + fi + # Make sure all bind-mount /home/* directories exist. # If a host bind-mount dir doesn't exist, then docker creates it on # the host with root:root owner, which can't be removed by cleanup job. @@ -339,14 +344,14 @@ fi # aborted by jenkins, but processes could have survived. Otherwise old # build can start writing to files of the current build. cleanup_lock=false -if [ x"$WORKSPACE" != x"" ]; then +if $bind_mounted_workspace; then prev_container=$($SSH $session_host flock "$WORKSPACE/.lock" cat "$WORKSPACE/.lock" || true) if [ x"$prev_container" != x"" ]; then echo "NOTE: Removing previous container for $WORKSPACE" $DOCKER rm -vf "$prev_container" || echo "WARNING: Could not remove $prev_container" fi - $SSH $session_host bash -c "\"flock $WORKSPACE/.lock echo $session_name > $WORKSPACE/.lock\"" + $SSH $session_host bash -c "\"mkdir -p $WORKSPACE && flock $WORKSPACE/.lock echo $session_name > $WORKSPACE/.lock\"" cleanup_lock=true fi |