feat: add method for pulling files when deploying from built images

This allows us to be backwards compatible when executing git:from-image.

The nice thing about this pattern is we can also extend it to other parts of the deployment as well, such asn nginx-vhosts fetching
This commit is contained in:
Jose Diaz-Gonzalez
2022-11-25 17:38:15 -05:00
parent 0857e51c43
commit 171dad8e88
3 changed files with 43 additions and 13 deletions

View File

@@ -4,13 +4,20 @@ source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
trigger-nginx-vhosts-core-post-extract() {
declare desc="nginx-vhosts post-extract plugin trigger"
declare trigger="post-extract"
declare APP="$1" SOURCECODE_WORK_DIR="$2"
local CONF_SIGIL_PATH="$(fn-nginx-computed-nginx-conf-sigil-path "$APP")"
fn-nginx-vhosts-copy-from-image() {
declare APP="$1" IMAGE_NAME="$2" CONF_SIGIL_PATH="$3"
pushd "$TMP_WORK_DIR" >/dev/null
rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil."*
copy_from_image "$IMAGE_NAME" "$CONF_SIGIL_PATH" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID" 2>/dev/null || true
if [[ ! -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID" ]]; then
touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID.missing"
fi
}
fn-nginx-vhosts-copy-from-directory() {
declare APP="$1" SOURCECODE_WORK_DIR="$2" CONF_SIGIL_PATH="$3"
pushd "$SOURCECODE_WORK_DIR" >/dev/null
mkdir -p "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP"
if [[ -z "$CONF_SIGIL_PATH" ]]; then
@@ -28,4 +35,18 @@ trigger-nginx-vhosts-core-post-extract() {
popd &>/dev/null || pushd "/tmp" >/dev/null
}
trigger-nginx-vhosts-core-post-extract() {
declare desc="nginx-vhosts post-extract plugin trigger"
declare trigger="post-extract"
declare APP="$1" SOURCECODE_WORK_DIR="$2"
local CONF_SIGIL_PATH="$(fn-nginx-computed-nginx-conf-sigil-path "$APP")"
if [[ -n "$DOKKU_BUILDING_FROM_IMAGE" ]]; then
fn-nginx-vhosts-copy-from-image "$APP" "$DOKKU_BUILDING_FROM_IMAGE" "$CONF_SIGIL_PATH"
else
fn-nginx-vhosts-copy-from-directory "$APP" "$SOURCECODE_WORK_DIR" "$CONF_SIGIL_PATH"
fi
}
trigger-nginx-vhosts-core-post-extract "$@"