diff --git a/plugins/openresty-vhosts/core-post-deploy b/plugins/openresty-vhosts/core-post-deploy index c8ad3ea0c..b33a6dffa 100755 --- a/plugins/openresty-vhosts/core-post-deploy +++ b/plugins/openresty-vhosts/core-post-deploy @@ -19,6 +19,10 @@ trigger-openresty-vhosts-core-post-deploy() { 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 "$@" diff --git a/plugins/openresty-vhosts/core-post-extract b/plugins/openresty-vhosts/core-post-extract index 8c5f7568b..5842dc01e 100755 --- a/plugins/openresty-vhosts/core-post-extract +++ b/plugins/openresty-vhosts/core-post-extract @@ -5,7 +5,9 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x fn-openresty-vhosts-copy-from-image() { - declare APP="$1" IMAGE_NAME="$2" CONF_PATH="$3" + declare APP="$1" IMAGE_NAME="$2" + 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 {} + @@ -13,42 +15,53 @@ fn-openresty-vhosts-copy-from-image() { if [[ ! -f "${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" || true + if [[ ! -f "${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 } fn-openresty-vhosts-copy-from-directory() { - declare APP="$1" SOURCECODE_WORK_DIR="$2" CONF_PATH="$3" + declare APP="$1" SOURCECODE_WORK_DIR="$2" + local CONF_PATH="openresty/http-includes" + local LOCATION_CONF_PATH="openresty/http-location-includes" - pushd "$SOURCECODE_WORK_DIR" >/dev/null - mkdir -p "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP" - - if [[ -z "$CONF_PATH" ]]; then + 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/" + cp -f "$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" - return fi - if [[ ! -d "$CONF_PATH" ]]; then - touch "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID.missing" - return + 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/" + cp -f "$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 - - 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/" - cp -f "$CONF_PATH"/* "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-http-includes.$DOKKU_PID/" - popd &>/dev/null || pushd "/tmp" >/dev/null } trigger-openresty-vhosts-core-post-extract() { declare desc="openresty-vhosts post-extract plugin trigger" declare trigger="post-extract" declare APP="$1" SOURCECODE_WORK_DIR="$2" - local CONF_PATH="openresty-http-includes" local app_source_image + mkdir -p "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP" + app_source_image="$(plugn trigger git-get-property "$APP" "source-image")" if [[ -n "$app_source_image" ]]; then - fn-openresty-vhosts-copy-from-image "$APP" "$app_source_image" "$CONF_PATH" + fn-openresty-vhosts-copy-from-image "$APP" "$app_source_image" else - fn-openresty-vhosts-copy-from-directory "$APP" "$SOURCECODE_WORK_DIR" "$CONF_PATH" + fn-openresty-vhosts-copy-from-directory "$APP" "$SOURCECODE_WORK_DIR" fi } diff --git a/plugins/openresty-vhosts/docker-args-process-deploy b/plugins/openresty-vhosts/docker-args-process-deploy index 07889dddf..4a507bf72 100755 --- a/plugins/openresty-vhosts/docker-args-process-deploy +++ b/plugins/openresty-vhosts/docker-args-process-deploy @@ -48,6 +48,24 @@ trigger-openresty-vhosts-docker-args-process-deploy() { popd &>/dev/null || pushd "/tmp" >/dev/null fi + include_dir="$(fn-openresty-get-location-includes-dir "$APP")" + if [[ -d "$include_dir" ]]; then + pushd "$include_dir" >/dev/null + for filename in *; do + if [[ ! -f "$include_dir/$filename" ]]; then + continue + fi + + if [[ $filename != *.conf ]]; then + continue + fi + + DATA="$(base64 -w 0 <"$include_dir/$filename")" + output="$output '--label=openresty.include-location-http-$filename=$DATA'" + done + popd &>/dev/null || pushd "/tmp" >/dev/null + fi + is_app_listening="false" local APP_PORT_MAP="$(plugn trigger ports-get "$APP")" while IFS= read -r port_map; do diff --git a/plugins/openresty-vhosts/internal-functions b/plugins/openresty-vhosts/internal-functions index ce8538db1..a1c5246df 100755 --- a/plugins/openresty-vhosts/internal-functions +++ b/plugins/openresty-vhosts/internal-functions @@ -70,6 +70,21 @@ fn-openresty-get-http-includes-dir() { fi } +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 + return + fi + + if [[ -d "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" ]]; then + echo "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes.$DOKKU_PID" + elif [[ -d "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes" ]]; then + echo "${DOKKU_LIB_ROOT}/data/openresty-vhosts/app-$APP/openresty-location-includes" + fi +} + fn-openresty-hsts-include-subdomains() { declare APP="$1" fn-plugin-property-get-default "openresty" "$APP" "hsts-include-subdomains" "true" diff --git a/tests/unit/openresty.bats b/tests/unit/openresty.bats index 15b399e65..d949d0ae1 100644 --- a/tests/unit/openresty.bats +++ b/tests/unit/openresty.bats @@ -182,8 +182,12 @@ add_openresty_include() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" - mkdir -p "$APP_REPO_DIR/openresty-http-includes" - touch "$APP_REPO_DIR/openresty-http-includes/example.conf" - echo "# force the character set to utf-8" >>"$APP_REPO_DIR/openresty-http-includes/example.conf" - echo "charset UTF-8;" >>"$APP_REPO_DIR/openresty-http-includes/example.conf" + mkdir -p "$APP_REPO_DIR/openresty/http-includes" + touch "$APP_REPO_DIR/openresty/http-includes/example.conf" + echo "# force the character set to utf-8" >>"$APP_REPO_DIR/openresty/http-includes/example.conf" + echo "charset UTF-8;" >>"$APP_REPO_DIR/openresty/http-includes/example.conf" + + mkdir -p "$APP_REPO_DIR/openresty/http-location-includes" + touch "$APP_REPO_DIR/openresty/http-location-includes/example.conf" + echo "# location-block" >>"$APP_REPO_DIR/openresty/http-location-includes/example.conf" }