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
58 lines
2.6 KiB
Bash
Executable File
58 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
trigger-git-git-from-archive() {
|
|
declare desc="updates a repository from an archive"
|
|
declare trigger="git-from-archive"
|
|
declare APP="$1" ARCHIVE_URL="$2" ARCHIVE_TYPE="$3" USER_NAME="${4:-Dokku}" USER_EMAIL="${4:-automated@dokku.sh}"
|
|
|
|
local TMP_WORK_DIR=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
local TMP_WORK_DIR_2=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
local TMP_WORK_DIR_3=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
trap "rm -rf '$TMP_WORK_DIR' '$TMP_WORK_DIR_2' '$TMP_WORK_DIR_3' >/dev/null" RETURN INT TERM EXIT
|
|
|
|
if [[ "$ARCHIVE_URL" == "--" ]]; then
|
|
dokku_log_info1 "Fetching $ARCHIVE_TYPE file from stdin"
|
|
tee "$TMP_WORK_DIR_2/src.$ARCHIVE_TYPE" | wc -c
|
|
else
|
|
dokku_log_info1 "Downloading $ARCHIVE_TYPE file from $ARCHIVE_URL"
|
|
curl -# -L "$ARCHIVE_URL" -o "$TMP_WORK_DIR_2/src.$ARCHIVE_TYPE"
|
|
fi
|
|
|
|
dokku_log_info1 "Generating build context"
|
|
if [[ "$ARCHIVE_TYPE" == "tar" ]]; then
|
|
local COMMON_PREFIX=$(tar -tf "$TMP_WORK_DIR_2/src.tar" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D')
|
|
local BOGUS_PARTS=$(echo "$COMMON_PREFIX " | awk 'BEGIN{FS="/"} {print NF-1}')
|
|
dokku_log_verbose "Striping $BOGUS_PARTS worth of directories from tarball"
|
|
fn-archive-extract-tar "$TMP_WORK_DIR_2/src.tar" "$TMP_WORK_DIR_3" "tar" "$BOGUS_PARTS"
|
|
elif [[ "$ARCHIVE_TYPE" == "tar.gz" ]]; then
|
|
dokku_log_verbose "Extracting gzipped tarball"
|
|
fn-archive-extract-tar "$TMP_WORK_DIR_2/src.tar.gz" "$TMP_WORK_DIR_3" "tar.gz" 0
|
|
elif [[ "$ARCHIVE_TYPE" == "zip" ]]; then
|
|
dokku_log_verbose "Extracting zipball"
|
|
fn-archive-extract-zip "$TMP_WORK_DIR_2/src.zip" "$TMP_WORK_DIR_3"
|
|
fi
|
|
|
|
chmod -R u+r "$TMP_WORK_DIR_3"
|
|
|
|
# drop any top-level folder components that resulted from the folder extraction
|
|
if [[ "$(find "$TMP_WORK_DIR_3" -maxdepth 1 -printf %y)" == "dd" ]]; then
|
|
dokku_log_verbose "Stripping top-level archive folder components"
|
|
local subpath="$(find "$TMP_WORK_DIR_3" -mindepth 1 -maxdepth 1 -type d)"
|
|
pushd "$subpath" >/dev/null
|
|
find . -mindepth 1 -maxdepth 1 -exec mv {} "$TMP_WORK_DIR" \;
|
|
popd &>/dev/null || pushd "/tmp" >/dev/null
|
|
else
|
|
dokku_log_verbose "Moving unarchived files and folders into place"
|
|
pushd "$TMP_WORK_DIR_3" >/dev/null
|
|
find . -mindepth 1 -maxdepth 1 -exec mv {} "$TMP_WORK_DIR" \;
|
|
popd &>/dev/null || pushd "/tmp" >/dev/null
|
|
fi
|
|
|
|
DOKKU_GIT_SOURCE_IMAGE="" plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL"
|
|
}
|
|
|
|
trigger-git-git-from-archive "$@"
|