From c96d139f548ab3970ec5d44095f95b1021eccf6e Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 28 Jan 2015 16:18:57 -0800 Subject: [PATCH] use flock when (re)building/deploying --- plugins/git/commands | 20 +++++++++++++++++--- plugins/ps/commands | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/git/commands b/plugins/git/commands index bfe9fff0c..621c59202 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -25,7 +25,7 @@ case "$1" in # Only run this script for the master branch. You can remove this # if block if you wish to run it for others as well. if [[ $refname = "refs/heads/master" ]] ; then - git_archive_all $APP $newrev | dokku receive $APP | sed -u "s/^/"$'\e[1G'"/" + dokku git-build $APP $newrev else echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master." echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\/}:master'" @@ -40,8 +40,22 @@ case "$1" in pluginhook git-post-pull $APP ;; - git-rebuild) - APP="$2"; REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master") + git-build) + APP="$2"; APP_BUILD_LOCK="$DOKKU_ROOT/$APP/.build.lock" + APP_BUILD_LOCK_MSG="$APP is currently being deployed or locked. Waiting..." + [[ $(flock -n "$APP_BUILD_LOCK" true &>/dev/null ; echo $?) -ne 0 ]] && echo "$APP_BUILD_LOCK_MSG" + + shift 1 + flock -o "$APP_BUILD_LOCK" dokku git-build-locked "$@" + ;; + + git-build-locked) + APP="$2" + if [[ $# -ge 3 ]];then + REF="$3" + else + REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master") + fi git_archive_all $APP $REF | dokku receive $APP | sed -u "s/^/"$'\e[1G'"/" ;; diff --git a/plugins/ps/commands b/plugins/ps/commands index d57539a43..b1f43478e 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -61,7 +61,7 @@ case "$1" in [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - dokku git-rebuild $APP + dokku git-build $APP ;; ps:rebuildall)