implement central deploy lock and use in tar plugin
This commit is contained in:
1 parent
2ece0e1bf8
commit
4f8c1b64c9
5 files changed
+45
-40
No files matched your search
@@ -820,3 +820,30 @@ merge_dedupe_list() {
|
|||||||
local merged_list="$(tr "$delimiter" $'\n' <<< "$input_lists" | sort | uniq | xargs)"
|
local merged_list="$(tr "$delimiter" $'\n' <<< "$input_lists" | sort | uniq | xargs)"
|
||||||
echo "$merged_list"
|
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
|
||||||
|
}
|
||||||
+13
-29
@@ -2,26 +2,10 @@
|
|||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
|
||||||
tar_build_cmd() {
|
tar_build() {
|
||||||
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() {
|
|
||||||
declare desc="builds apps from tarball via command line"
|
declare desc="builds apps from tarball via command line"
|
||||||
local cmd="tar:build-locked"
|
local APP="$1"; verify_app_name "$APP"
|
||||||
local APP="$2"
|
shift 1
|
||||||
|
|
||||||
verify_app_name "$2"
|
|
||||||
shift 2
|
|
||||||
|
|
||||||
# clean up after ourselves
|
# clean up after ourselves
|
||||||
local TAR_BUILD_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_tar.XXXX")
|
local TAR_BUILD_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_tar.XXXX")
|
||||||
@@ -49,16 +33,6 @@ tar_build_locked_cmd() {
|
|||||||
fi
|
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() {
|
tar_in_cmd() {
|
||||||
declare desc="deploys app from tarball on STDIN via command line"
|
declare desc="deploys app from tarball on STDIN via command line"
|
||||||
local cmd="tar:in"
|
local cmd="tar:in"
|
||||||
@@ -68,3 +42,13 @@ tar_in_cmd() {
|
|||||||
tee "$DOKKU_ROOT/$APP/src.tar" | wc -c
|
tee "$DOKKU_ROOT/$APP/src.tar" | wc -c
|
||||||
plugn trigger receive-app "$APP"
|
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
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/tar/functions"
|
||||||
|
|
||||||
tar_receive_app() {
|
tar_receive_app() {
|
||||||
declare desc="tar receive-app plugin trigger"
|
declare desc="tar receive-app plugin trigger"
|
||||||
@@ -11,7 +12,10 @@ tar_receive_app() {
|
|||||||
if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
|
if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
dokku tar:build "$APP"
|
acquire_app_deploy_lock "$APP"
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
tar_build "$@"
|
||||||
|
release_app_deploy_lock "$APP"
|
||||||
fi
|
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