Files
dokku/plugins/git/git-from-image
T
Jose Diaz-Gonzalez 7955e8ee06 fix: keep the git source-image property in sync with failed deploys
The source-image property was written before the deploy lock was taken
and was not restored when a deploy failed, so after a rejected
git:from-image or git:load-image it named an image that was not
deployed, and later builds extracted app.json, Procfile, and CHECKS
from it. Deploys from other sources also built while the old image was
still set.

Entry points now pass the desired value via DOKKU_GIT_SOURCE_IMAGE and
git_receive_app applies it while holding the deploy lock, restoring the
previous value on failure. git:sync clears the property under the lock
when it fetches new code.

Closes #9117
2026-10-11 05:08:32 -04:00

51 lines
1.9 KiB
Bash
Executable File

#!/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
trigger-git-git-from-image() {
declare desc="updates a repository from a docker image"
declare trigger="git-from-image"
declare APP="$1" DOCKER_IMAGE="$2" BUILD_DIR="$3" USER_NAME="${4:-Dokku}" USER_EMAIL="${4:-automated@dokku.sh}"
local TMP_WORK_DIR=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_WORK_DIR' >/dev/null" RETURN INT TERM EXIT
dokku_log_info1 "Generating build context"
if [[ -n "$BUILD_DIR" ]]; then
if [[ ! -d "$BUILD_DIR" ]]; then
dokku_log_fail "Invalid BUILD_DIR specified for docker build context"
fi
dokku_log_verbose "Syncing build directory context"
rsync -a "$BUILD_DIR/" "$TMP_WORK_DIR"
fi
touch "$TMP_WORK_DIR/Dockerfile"
echo "FROM $DOCKER_IMAGE" >>"$TMP_WORK_DIR/Dockerfile"
echo "LABEL com.dokku.docker-image-labeler/alternate-tags=[\\\"$DOCKER_IMAGE\\\"]" >>"$TMP_WORK_DIR/Dockerfile"
local DOCKER_CONFIG
DOCKER_CONFIG="$(fn-registry-docker-config-dir "$APP")"
[[ -n "$DOCKER_CONFIG" ]] && export DOCKER_CONFIG
if [[ "$("$DOCKER_BIN" image ls -q "$DOCKER_IMAGE" 2>/dev/null)" == "" ]]; then
dokku_log_info1 "Pulling image"
if ! "$DOCKER_BIN" image pull "$DOCKER_IMAGE"; then
dokku_log_fail "Failed to pull image: $DOCKER_IMAGE"
fi
elif [[ "$DOKKU_APPS_FORCE_DELETE" == "1" ]]; then
dokku_log_info1 "Force pulling image"
if ! "$DOCKER_BIN" image pull "$DOCKER_IMAGE"; then
dokku_log_fail "Failed to pull image: $DOCKER_IMAGE"
fi
else
dokku_log_info1 "Image exists on host, skipping pull"
fi
DOKKU_GIT_SOURCE_IMAGE="$DOCKER_IMAGE" plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL"
}
trigger-git-git-from-image "$@"