fix: clean up stale extracted files on deploy
A failed deploy could leave a non-empty extraction directory behind, such as the scheduler-k3s `kustomization` directory, which caused every following deploy to fail. Leftovers from previous deploys are now fully removed, removing a directory such as `config/kustomize` from the repository now removes the stored copy, and openresty includes now persist across restarts.
This commit is contained in:
12 files changed
+315
-41
No files matched your search
@@ -4,25 +4,34 @@ source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
fn-openresty-vhosts-promote-includes-dir() {
|
||||
declare desc="moves the process-specific includes dir into place or removes the stored one"
|
||||
declare APP="$1" INCLUDES_NAME="$2"
|
||||
local includes_dir="${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/$INCLUDES_NAME"
|
||||
|
||||
if [[ -d "$includes_dir.$DOKKU_PID" ]]; then
|
||||
rm -rf "$includes_dir"
|
||||
mv "$includes_dir.$DOKKU_PID" "$includes_dir"
|
||||
elif [[ -f "$includes_dir.$DOKKU_PID.missing" ]]; then
|
||||
rm -f "$includes_dir.$DOKKU_PID.missing"
|
||||
rm -rf "$includes_dir"
|
||||
fi
|
||||
}
|
||||
|
||||
trigger-openresty-vhosts-core-post-deploy() {
|
||||
declare desc="openresty-vhosts core-post-deploy plugin trigger"
|
||||
declare trigger="core-post-deploy"
|
||||
declare APP="$1"
|
||||
local tls_internal
|
||||
|
||||
fn-openresty-vhosts-promote-includes-dir "$APP" "openresty-http-includes"
|
||||
fn-openresty-vhosts-promote-includes-dir "$APP" "openresty-location-includes"
|
||||
|
||||
if [[ "$(plugn trigger proxy-type "$APP")" != "openresty" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
dokku_log_info1 "Routing app via openresty"
|
||||
if [[ -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing" ]]; then
|
||||
rm -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing"
|
||||
rm -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes"
|
||||
fi
|
||||
if [[ -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing" ]]; then
|
||||
rm -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing"
|
||||
rm -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes"
|
||||
fi
|
||||
}
|
||||
|
||||
trigger-openresty-vhosts-core-post-deploy "$@"
|
||||
@@ -45,18 +45,15 @@ fn-openresty-vhosts-copy-from-image() {
|
||||
local CONF_PATH="openresty/http-includes"
|
||||
local LOCATION_CONF_PATH="openresty/http-location-includes"
|
||||
|
||||
mkdir -p "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP"
|
||||
find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 -name 'openresty-http-includes.*' -type d -exec rm -r {} +
|
||||
copy_dir_from_image "$IMAGE_NAME" "$CONF_PATH" "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID" 2>/dev/null || true
|
||||
fn-openresty-vhosts-sanitize-extracted-includes "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID"
|
||||
if [[ ! -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID" ]]; then
|
||||
if [[ ! -d "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID" ]]; then
|
||||
touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing"
|
||||
fi
|
||||
|
||||
find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 -name 'openresty-location-includes.*' -type d -exec rm -r {} +
|
||||
copy_dir_from_image "$IMAGE_NAME" "$LOCATION_CONF_PATH" "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" 2>/dev/null || true
|
||||
fn-openresty-vhosts-sanitize-extracted-includes "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID"
|
||||
if [[ ! -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" ]]; then
|
||||
if [[ ! -d "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" ]]; then
|
||||
touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing"
|
||||
fi
|
||||
}
|
||||
@@ -66,25 +63,21 @@ fn-openresty-vhosts-copy-from-directory() {
|
||||
local CONF_PATH="openresty/http-includes"
|
||||
local LOCATION_CONF_PATH="openresty/http-location-includes"
|
||||
|
||||
pushd "$SOURCECODE_WORK_DIR" >/dev/null
|
||||
if [[ -d "$CONF_PATH" ]]; then
|
||||
pushd "$SOURCECODE_WORK_DIR" >/dev/null
|
||||
find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 -name 'openresty-http-includes.*' -type d -exec rm -r {} +
|
||||
mkdir -p "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID/"
|
||||
fn-openresty-vhosts-copy-includes-from-source "$CONF_PATH" "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID"
|
||||
popd &>/dev/null || pushd "/tmp" >/dev/null
|
||||
else
|
||||
touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing"
|
||||
fi
|
||||
|
||||
if [[ -d "$LOCATION_CONF_PATH" ]]; then
|
||||
pushd "$SOURCECODE_WORK_DIR" >/dev/null
|
||||
find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 -name 'openresty-location-includes.*' -type d -exec rm -r {} +
|
||||
mkdir -p "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID/"
|
||||
fn-openresty-vhosts-copy-includes-from-source "$LOCATION_CONF_PATH" "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID"
|
||||
popd &>/dev/null || pushd "/tmp" >/dev/null
|
||||
else
|
||||
touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing"
|
||||
fi
|
||||
popd &>/dev/null || pushd "/tmp" >/dev/null
|
||||
}
|
||||
|
||||
trigger-openresty-vhosts-core-post-extract() {
|
||||
@@ -94,6 +87,7 @@ trigger-openresty-vhosts-core-post-extract() {
|
||||
local app_source_image
|
||||
|
||||
mkdir -p "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP"
|
||||
find "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/" -maxdepth 1 \( -name 'openresty-http-includes.*' -o -name 'openresty-location-includes.*' \) -exec rm -rf {} +
|
||||
|
||||
app_source_image="$(plugn trigger git-get-property "$APP" "source-image")"
|
||||
if [[ -n "$app_source_image" ]]; then
|
||||
|
||||
@@ -221,7 +221,7 @@ fn-openresty-get-http-includes-dir() {
|
||||
declare desc="get any include dir if available"
|
||||
declare APP="$1"
|
||||
|
||||
if [[ -d "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing" ]]; then
|
||||
if [[ -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -236,7 +236,7 @@ fn-openresty-get-location-includes-dir() {
|
||||
declare desc="get any include dir if available"
|
||||
declare APP="$1"
|
||||
|
||||
if [[ -d "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing" ]]; then
|
||||
if [[ -f "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID.missing" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
Reference in new issue
Block a user