use central deploy lock in git plugin
This commit is contained in:
@@ -824,19 +824,25 @@ merge_dedupe_list() {
|
|||||||
acquire_app_deploy_lock() {
|
acquire_app_deploy_lock() {
|
||||||
declare desc="acquire advisory lock for use in git/tar deploys"
|
declare desc="acquire advisory lock for use in git/tar deploys"
|
||||||
local APP="$1"; verify_app_name "$APP"
|
local APP="$1"; verify_app_name "$APP"
|
||||||
|
local LOCK_TYPE="${2:-waiting}"
|
||||||
local APP_DEPLOY_LOCK_FD="200"
|
local APP_DEPLOY_LOCK_FD="200"
|
||||||
local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
|
local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
|
||||||
local APP_DEPLOY_LOCK_MSG="$APP is currently being deployed. Waiting..."
|
local LOCK_WAITING_MSG="$APP is currently being deployed. Waiting..."
|
||||||
|
local LOCK_FAILED_MSG="$APP is currently being deployed. Exiting..."
|
||||||
local SHOW_MSG=true
|
local SHOW_MSG=true
|
||||||
|
|
||||||
eval "exec $APP_DEPLOY_LOCK_FD>$APP_DEPLOY_LOCK_FILE"
|
eval "exec $APP_DEPLOY_LOCK_FD>$APP_DEPLOY_LOCK_FILE"
|
||||||
while [[ $(flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null ; echo $?) -ne 0 ]]; do
|
if [[ "$LOCK_TYPE" == "waiting" ]]; then
|
||||||
if [[ "$SHOW_MSG" == "true" ]]; then
|
while [[ $(flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null ; echo $?) -ne 0 ]]; do
|
||||||
echo "$APP_DEPLOY_LOCK_MSG"
|
if [[ "$SHOW_MSG" == "true" ]]; then
|
||||||
SHOW_MSG=false
|
echo "$LOCK_WAITING_MSG"
|
||||||
fi
|
SHOW_MSG=false
|
||||||
sleep 1
|
fi
|
||||||
done
|
sleep 1
|
||||||
|
done
|
||||||
|
else
|
||||||
|
flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null || dokku_log_fail "$LOCK_FAILED_MSG"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
release_app_deploy_lock() {
|
release_app_deploy_lock() {
|
||||||
|
|||||||
@@ -11,14 +11,6 @@ case "$1" in
|
|||||||
git_upload_pack_cmd "$@"
|
git_upload_pack_cmd "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
git-build)
|
|
||||||
git_build_cmd "$@"
|
|
||||||
;;
|
|
||||||
|
|
||||||
git-build-locked)
|
|
||||||
git_build_locked_cmd "$@"
|
|
||||||
;;
|
|
||||||
|
|
||||||
git-*)
|
git-*)
|
||||||
git_glob_cmd "$@"
|
git_glob_cmd "$@"
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ git_build_app_repo() {
|
|||||||
local GIT_BUILD_APP_REPO_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_git.XXXX")
|
local GIT_BUILD_APP_REPO_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_git.XXXX")
|
||||||
trap 'rm -rf "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" > /dev/null' RETURN INT TERM EXIT
|
trap 'rm -rf "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" > /dev/null' RETURN INT TERM EXIT
|
||||||
|
|
||||||
|
|
||||||
# git clone - this method creates a new git repository and adds the primary
|
# git clone - this method creates a new git repository and adds the primary
|
||||||
# repo as a remote, then does a fetch depth=1 to avoid cloning
|
# repo as a remote, then does a fetch depth=1 to avoid cloning
|
||||||
# the entire repo
|
# the entire repo
|
||||||
@@ -67,6 +66,19 @@ git_hook_cmd() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git_build() {
|
||||||
|
declare desc="setup and call git_build_app_repo"
|
||||||
|
local APP="$1"
|
||||||
|
if [[ $# -ge 2 ]]; then
|
||||||
|
local REF="$2"
|
||||||
|
else
|
||||||
|
local REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
git_build_app_repo $APP $REF
|
||||||
|
}
|
||||||
|
|
||||||
git_upload_pack_cmd() {
|
git_upload_pack_cmd() {
|
||||||
declare desc="executes git-upload-pack"
|
declare desc="executes git-upload-pack"
|
||||||
local cmd="git-upload-pack"
|
local cmd="git-upload-pack"
|
||||||
@@ -76,30 +88,6 @@ git_upload_pack_cmd() {
|
|||||||
plugn trigger git-post-pull "$APP"
|
plugn trigger git-post-pull "$APP"
|
||||||
}
|
}
|
||||||
|
|
||||||
git_build_cmd() {
|
|
||||||
declare desc="lock git-build"
|
|
||||||
local cmd="git-build"
|
|
||||||
local APP="$2"; local APP_BUILD_LOCK="$DOKKU_ROOT/$APP/.build.lock"
|
|
||||||
local 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_cmd() {
|
|
||||||
declare desc="setup and call git_build_app_repo"
|
|
||||||
local cmd="git-build-locked"
|
|
||||||
local APP="$2"
|
|
||||||
if [[ $# -ge 3 ]]; then
|
|
||||||
local REF="$3"
|
|
||||||
else
|
|
||||||
local REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master")
|
|
||||||
fi
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
git_build_app_repo $APP $REF
|
|
||||||
}
|
|
||||||
|
|
||||||
git_glob_cmd() {
|
git_glob_cmd() {
|
||||||
declare desc="catch-all for any other git-* commands"
|
declare desc="catch-all for any other git-* commands"
|
||||||
local cmd="git-*"
|
local cmd="git-*"
|
||||||
|
|||||||
@@ -7,14 +7,15 @@ git_receive_app() {
|
|||||||
declare desc="git receive-app plugin trigger"
|
declare desc="git receive-app plugin trigger"
|
||||||
local trigger="git_receive_app"
|
local trigger="git_receive_app"
|
||||||
local APP="$1"; local REV="$2"
|
local APP="$1"; local REV="$2"
|
||||||
local cmd="git-build"
|
|
||||||
|
|
||||||
# Don't trigger git build if there is no git repository.
|
# Don't trigger git build if there is no git repository.
|
||||||
if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then
|
if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
acquire_app_deploy_lock "$APP" "exclusive"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
git_build_cmd $cmd $APP $REV
|
git_build $APP $REV
|
||||||
|
release_app_deploy_lock "$APP"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user