implement central deploy lock and use in tar plugin
This commit is contained in:
@@ -820,3 +820,30 @@ merge_dedupe_list() {
|
||||
local merged_list="$(tr "$delimiter" $'\n' <<< "$input_lists" | sort | uniq | xargs)"
|
||||
echo "$merged_list"
|
||||
}
|
||||
|
||||
acquire_app_deploy_lock() {
|
||||
declare desc="acquire advisory lock for use in git/tar deploys"
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
local APP_DEPLOY_LOCK_FD="200"
|
||||
local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
|
||||
local APP_DEPLOY_LOCK_MSG="$APP is currently being deployed. Waiting..."
|
||||
local SHOW_MSG=true
|
||||
|
||||
eval "exec $APP_DEPLOY_LOCK_FD>$APP_DEPLOY_LOCK_FILE"
|
||||
while [[ $(flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null ; echo $?) -ne 0 ]]; do
|
||||
if [[ "$SHOW_MSG" == "true" ]]; then
|
||||
echo "$APP_DEPLOY_LOCK_MSG"
|
||||
SHOW_MSG=false
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
release_app_deploy_lock() {
|
||||
declare desc="release advisory lock used in git/tar deploys"
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
local APP_DEPLOY_LOCK_FD="200"
|
||||
local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
|
||||
|
||||
flock -u "$APP_DEPLOY_LOCK_FD" && rm -f "$APP_DEPLOY_LOCK_FILE" &> /dev/null
|
||||
}
|
||||
|
||||
@@ -2,26 +2,10 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
tar_build_cmd() {
|
||||
declare desc="calls tar:build-locked via command line"
|
||||
local cmd="tar:build"
|
||||
|
||||
verify_app_name "$2"
|
||||
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" tar_build_locked_cmd "tar:build-locked" "$@"
|
||||
}
|
||||
|
||||
tar_build_locked_cmd() {
|
||||
tar_build() {
|
||||
declare desc="builds apps from tarball via command line"
|
||||
local cmd="tar:build-locked"
|
||||
local APP="$2"
|
||||
|
||||
verify_app_name "$2"
|
||||
shift 2
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
shift 1
|
||||
|
||||
# clean up after ourselves
|
||||
local TAR_BUILD_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_tar.XXXX")
|
||||
@@ -49,16 +33,6 @@ tar_build_locked_cmd() {
|
||||
fi
|
||||
}
|
||||
|
||||
tar_from_cmd() {
|
||||
declare desc="deploys app from tarball at URL via command line"
|
||||
local cmd="tar:from"
|
||||
verify_app_name "$2"
|
||||
local APP=$2
|
||||
local URL=$3
|
||||
shift 3
|
||||
curl -# --insecure -L "$URL" | tar_in_cmd "tar:in" "$APP" "$@"
|
||||
}
|
||||
|
||||
tar_in_cmd() {
|
||||
declare desc="deploys app from tarball on STDIN via command line"
|
||||
local cmd="tar:in"
|
||||
@@ -68,3 +42,13 @@ tar_in_cmd() {
|
||||
tee "$DOKKU_ROOT/$APP/src.tar" | wc -c
|
||||
plugn trigger receive-app "$APP"
|
||||
}
|
||||
|
||||
tar_from_cmd() {
|
||||
declare desc="deploys app from tarball at URL via command line"
|
||||
local cmd="tar:from"
|
||||
verify_app_name "$2"
|
||||
local APP=$2
|
||||
local URL=$3
|
||||
shift 3
|
||||
curl -# --insecure -L "$URL" | tar_in_cmd "tar:in" "$APP" "$@"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/tar/functions"
|
||||
|
||||
tar_receive_app() {
|
||||
declare desc="tar receive-app plugin trigger"
|
||||
@@ -11,7 +12,10 @@ tar_receive_app() {
|
||||
if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
|
||||
true
|
||||
else
|
||||
dokku tar:build "$APP"
|
||||
acquire_app_deploy_lock "$APP"
|
||||
# shellcheck disable=SC2086
|
||||
tar_build "$@"
|
||||
release_app_deploy_lock "$APP"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_AVAILABLE_PATH/tar/functions"
|
||||
|
||||
tar_build_cmd "$@"
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_AVAILABLE_PATH/tar/functions"
|
||||
|
||||
tar_build_locked_cmd "$@"
|
||||
Reference in New Issue
Block a user