From 171dad8e88a803a5f2ceccd08cb7756d82ff5256 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 25 Nov 2022 17:38:15 -0500 Subject: [PATCH] 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 --- plugins/git/git-from-image | 4 ++++ plugins/nginx-vhosts/core-post-extract | 33 +++++++++++++++++++++----- plugins/ps/triggers.go | 19 +++++++++------ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/plugins/git/git-from-image b/plugins/git/git-from-image index e5094a9f7..6300ee02d 100755 --- a/plugins/git/git-from-image +++ b/plugins/git/git-from-image @@ -26,6 +26,10 @@ trigger-git-git-from-image() { echo "FROM $DOCKER_IMAGE" >>"$TMP_WORK_DIR/Dockerfile" echo "LABEL com.dokku.docker-image-labeler/alternate-tags=[\\\"$DOCKER_IMAGE\\\"]" >>"$TMP_WORK_DIR/Dockerfile" + dokku_log_info1 "Pulling image" + "$DOCKER_BIN" image pull "$DOCKER_IMAGE" + + export DOKKU_BUILDING_FROM_IMAGE="$DOCKER_IMAGE" plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL" } diff --git a/plugins/nginx-vhosts/core-post-extract b/plugins/nginx-vhosts/core-post-extract index 65aff7517..07b47f51d 100755 --- a/plugins/nginx-vhosts/core-post-extract +++ b/plugins/nginx-vhosts/core-post-extract @@ -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 "$@" diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index c88713589..844213cae 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -59,7 +59,6 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { } existingProcfile := getProcfilePath(appName) - files, err := filepath.Glob(fmt.Sprintf("%s.*", existingProcfile)) if err != nil { return err @@ -70,14 +69,20 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { } } - repoProcfilePath := path.Join(sourceWorkDir, procfilePath) processSpecificProcfile := fmt.Sprintf("%s.%s", existingProcfile, os.Getenv("DOKKU_PID")) - if !common.FileExists(repoProcfilePath) { - return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile)) - } + if os.Getenv("DOKKU_BUILDING_FROM_IMAGE") == "" { + repoProcfilePath := path.Join(sourceWorkDir, procfilePath) + if !common.FileExists(repoProcfilePath) { + return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile)) + } - if err := copy.Copy(repoProcfilePath, processSpecificProcfile); err != nil { - return fmt.Errorf("Unable to extract Procfile: %v", err.Error()) + if err := copy.Copy(repoProcfilePath, processSpecificProcfile); err != nil { + return fmt.Errorf("Unable to extract Procfile: %v", err.Error()) + } + } else { + if err := common.CopyFromImage(appName, os.Getenv("DOKKU_BUILDING_FROM_IMAGE"), procfilePath, processSpecificProcfile); err != nil { + return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile)) + } } b, err := sh.Command("procfile-util", "check", "-P", processSpecificProcfile).CombinedOutput()