fix: exit non-zero when git:from-image deploys fail to start the app

Also ensure the repository doesn't get updated to an invalid state in those failure cases.

Closes #5538
This commit is contained in:
Jose Diaz-Gonzalez
2022-12-27 02:37:18 -05:00
parent 32af26d7a1
commit fd2c540cd5
4 changed files with 102 additions and 3 deletions

View File

@@ -18,9 +18,14 @@ trigger-git-git-from-directory() {
# shellcheck disable=SC2086
trap "rm -rf '$TMP_WORK_DIR' '$TMP_WORK_DIR_2' >/dev/null" RETURN INT TERM EXIT
dokku_log_info1 "Updating git repository with specified build context"
local has_code=true
local git_objects="$(fn-git-cmd "$APP_ROOT" count-objects 2>/dev/null || true)"
if [[ -z "$git_objects" ]] || [[ "$git_objects" == "0 objects, 0 kilobytes" ]]; then
local has_code=false
fi
dokku_log_info1 "Updating git repository with specified build context"
if [[ "$has_code" == "false" ]]; then
# setup new repo
cp -rT "$SOURCECODE_WORK_DIR" "$TMP_WORK_DIR"
suppress_output fn-git-cmd "$TMP_WORK_DIR" init
@@ -44,7 +49,7 @@ trigger-git-git-from-directory() {
if suppress_output fn-git-cmd "$TMP_WORK_DIR" diff-index --quiet HEAD --; then
dokku_log_warn "No changes detected, skipping git commit"
dokku_log_warn "Call 'ps:rebuild' on app to rebuild the app from existing source"
return
return 1
fi
suppress_output fn-git-cmd "$TMP_WORK_DIR" commit -m "Automated commit @ $(date +%s)"
@@ -54,7 +59,18 @@ trigger-git-git-from-directory() {
fi
rm -rf "$TMP_WORK_DIR" "$TMP_WORK_DIR_2" >/dev/null
git_receive_app "$APP" "$REV"
if git_receive_app "$APP" "$REV"; then
return
else
local exit_code=$?
local DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
if [[ "$has_code" == "false" ]]; then
fn-git-cmd "$APP_ROOT" update-ref -d HEAD
else
fn-git-cmd "$APP_ROOT" update-ref "refs/heads/$DOKKU_DEPLOY_BRANCH" "$DOKKU_DEPLOY_BRANCH^"
fi
return "$exit_code"
fi
}
trigger-git-git-from-directory "$@"