use flock when (re)building/deploying

This commit is contained in:
Michael Hobbs
2015-01-28 16:18:57 -08:00
parent ef369eb02f
commit c96d139f54
2 changed files with 18 additions and 4 deletions

View File

@@ -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 <dokku> ${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'"/"
;;

View File

@@ -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)