refactor: set deploy-source and metadata at deploy time

This ensures the value is correct, where previously it was computed based on a file - and therefore did not distinguish between git:from-archive and git:from-image.

Closes #4464
This commit is contained in:
Jose Diaz-Gonzalez
2021-10-09 23:37:53 -04:00
parent cd7b8afccb
commit c0b6942392
12 changed files with 112 additions and 77 deletions

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
trigger-git-deploy-source() {
declare desc="git deploy-source plugin trigger"
declare trigger="deploy-source"
declare APP="$1"
local STDIN
STDIN=$(cat)
# bail if another source is detected
if [[ -n "$STDIN" ]]; then
echo "$STDIN"
return
fi
if [[ -d "$DOKKU_ROOT/$APP/refs" ]]; then
echo "git"
fi
}
trigger-git-deploy-source "$@"

View File

@@ -93,14 +93,17 @@ cmd-git-hook() {
if [[ $refname == "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then
# broken out into plugin so we might support other methods to receive an app
git_receive_app "$APP" "$newrev"
plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
else
if [[ $(find "$PLUGIN_PATH"/enabled/*/receive-branch 2>/dev/null | wc -l) != 1 ]]; then
# shellcheck disable=SC2086
plugn trigger receive-branch $APP $newrev $refname
plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then
echo $'\e[1G\e[K'"-----> Set ${refname/refs\/heads\//} to DOKKU_DEPLOY_BRANCH."
fn-plugin-property-write "git" "$app" "deploy-branch" "${refname/refs\/heads\//}"
git_receive_app "$APP" "$newrev"
plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
else
echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to ${DOKKU_DEPLOY_BRANCH}."
echo $'\e[1G\e[K'"-----> for example, try 'git push <dokku> ${refname/refs\/heads\//}:${DOKKU_DEPLOY_BRANCH}'"

View File

@@ -53,6 +53,7 @@ cmd-git-from-archive() {
fi
plugn trigger git-from-archive "$APP" "$ARCHIVE_URL" "$ARCHIVE_TYPE" "$USER_NAME" "$USER_EMAIL"
plugn trigger deploy-source-set "$APP" "$ARCHIVE_TYPE" "$ARCHIVE_URL"
}
cmd-git-auth() {
@@ -110,6 +111,7 @@ cmd-git-from-image() {
[[ -z "$DOCKER_IMAGE" ]] && dokku_log_fail "Please specify a docker image"
plugn trigger git-from-image "$APP" "$DOCKER_IMAGE" "$BUILD_DIR" "$USER_NAME" "$USER_EMAIL"
plugn trigger deploy-source-set "$APP" "docker-image" "$DOCKER_IMAGE"
}
cmd-git-sync() {
@@ -165,6 +167,7 @@ cmd-git-sync() {
else
plugn trigger receive-app "$APP"
fi
plugn trigger deploy-source-set "$APP" "git-sync" "${GIT_REMOTE}#${GIT_REF}"
fi
}