fix: keep track of the source image when building an app via git:from-image
This change fixes issues with ps:rebuild not working as expected - essentially ignoring files in the repo - as well as adds tests. Closes #5518
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
@@ -33,7 +34,7 @@ trigger-git-git-from-image() {
|
||||
dokku_log_info1 "Image exists on host, skipping pull"
|
||||
fi
|
||||
|
||||
export DOKKU_BUILDING_FROM_IMAGE="$DOCKER_IMAGE"
|
||||
fn-plugin-property-write "git" "$APP" "source-image" "$DOCKER_IMAGE"
|
||||
plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL"
|
||||
}
|
||||
|
||||
|
||||
@@ -256,6 +256,7 @@ cmd-git-report-single() {
|
||||
"--git-keep-git-dir: $(fn-plugin-property-get "git" "$APP" "keep-git-dir" "false")"
|
||||
"--git-rev-env-var: $(fn-plugin-property-get "git" "$APP" "rev-env-var" "GIT_REV")"
|
||||
"--git-sha: $(fn-git-cmd "$APP_ROOT" rev-parse --short HEAD 2>/dev/null || false)"
|
||||
"--git-source-image: $(fn-git-source-image "$APP")"
|
||||
"--git-last-updated-at: $(fn-git-last-updated-at "$APP")"
|
||||
)
|
||||
|
||||
@@ -544,6 +545,13 @@ fn-git-setup-build-dir-submodules() {
|
||||
fi
|
||||
}
|
||||
|
||||
fn-git-source-image() {
|
||||
declare desc="retrieve the source-image for a given application"
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "git" "$APP" "source-image" ""
|
||||
}
|
||||
|
||||
fn-git-use-worktree() {
|
||||
declare desc="detects whether to use git worktree"
|
||||
local GIT_VERSION MAJOR_VERSION MINOR_VERSION
|
||||
|
||||
@@ -9,13 +9,13 @@ cmd-git-set() {
|
||||
declare cmd="git:set"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1" KEY="$2" VALUE="$3"
|
||||
local VALID_KEYS=("deploy-branch" "keep-git-dir" "rev-env-var")
|
||||
local VALID_KEYS=("deploy-branch" "keep-git-dir" "rev-env-var" "source-image")
|
||||
[[ "$APP" == "--global" ]] || verify_app_name "$APP"
|
||||
|
||||
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
|
||||
|
||||
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
|
||||
dokku_log_fail "Invalid key specified, valid keys include: deploy-branch, keep-git-dir, rev-env-var"
|
||||
dokku_log_fail "Invalid key specified, valid keys include: deploy-branch, keep-git-dir, rev-env-var, source-image"
|
||||
fi
|
||||
|
||||
if [[ -n "$VALUE" ]]; then
|
||||
|
||||
@@ -41,9 +41,11 @@ trigger-nginx-vhosts-core-post-extract() {
|
||||
declare trigger="post-extract"
|
||||
declare APP="$1" SOURCECODE_WORK_DIR="$2"
|
||||
local CONF_SIGIL_PATH="$(fn-nginx-computed-nginx-conf-sigil-path "$APP")"
|
||||
local app_source_image
|
||||
|
||||
if [[ -n "$DOKKU_BUILDING_FROM_IMAGE" ]]; then
|
||||
fn-nginx-vhosts-copy-from-image "$APP" "$DOKKU_BUILDING_FROM_IMAGE" "$CONF_SIGIL_PATH"
|
||||
app_source_image="$(plugn trigger git-get-property "$APP" "source-image")"
|
||||
if [[ -n "$app_source_image" ]]; then
|
||||
fn-nginx-vhosts-copy-from-image "$APP" "$app_source_image" "$CONF_SIGIL_PATH"
|
||||
else
|
||||
fn-nginx-vhosts-copy-from-directory "$APP" "$SOURCECODE_WORK_DIR" "$CONF_SIGIL_PATH"
|
||||
fi
|
||||
|
||||
@@ -74,7 +74,10 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
}
|
||||
|
||||
processSpecificProcfile := fmt.Sprintf("%s.%s", existingProcfile, os.Getenv("DOKKU_PID"))
|
||||
if os.Getenv("DOKKU_BUILDING_FROM_IMAGE") == "" {
|
||||
b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...)
|
||||
appSourceImage := strings.TrimSpace(string(b[:]))
|
||||
|
||||
if appSourceImage == "" {
|
||||
repoProcfilePath := path.Join(sourceWorkDir, procfilePath)
|
||||
if !common.FileExists(repoProcfilePath) {
|
||||
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile))
|
||||
@@ -84,13 +87,12 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
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 {
|
||||
if err := common.CopyFromImage(appName, appSourceImage, procfilePath, processSpecificProcfile); err != nil {
|
||||
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile))
|
||||
}
|
||||
}
|
||||
|
||||
b, err := sh.Command("procfile-util", "check", "-P", processSpecificProcfile).CombinedOutput()
|
||||
if err != nil {
|
||||
if b, err := sh.Command("procfile-util", "check", "-P", processSpecificProcfile).CombinedOutput(); err != nil {
|
||||
return fmt.Errorf(strings.TrimSpace(string(b[:])))
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user