fix: hold the deploy lock across git-from-directory and harden the advisory lock
git-from-directory updated the deploy branch before taking the deploy lock and rolled it back after releasing it. The lock is now held for the whole update, build, and rollback, and the rollback only moves the branch if it still points at the commit that was created. A failed lock attempt and apps:lock both truncated the lock file, dropping the build id of the in-progress deploy that builds:cancel and builds:output read. Releasing the lock unlocked before removing the file, so a waiter could end up holding a lock on a deleted file while another deploy locked a new one. The file is now removed before unlocking, and acquiring retries when the locked file is no longer the one at the lock path.
This commit is contained in:
8 files changed
+312
-56
No files matched your search
+24
-16
@@ -150,28 +150,36 @@ git_receive_app() {
|
||||
if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then
|
||||
true
|
||||
else
|
||||
local exit_code=0 has_source_image=false source_image previous_source_image
|
||||
local exit_code=0
|
||||
acquire_app_deploy_lock "$APP" "exclusive"
|
||||
|
||||
# DOKKU_GIT_SOURCE_IMAGE is only applied while the deploy lock is held. An
|
||||
# empty value clears the property, while an unset variable leaves it as-is.
|
||||
if [[ -n "${DOKKU_GIT_SOURCE_IMAGE+x}" ]]; then
|
||||
has_source_image=true
|
||||
source_image="$DOKKU_GIT_SOURCE_IMAGE"
|
||||
unset DOKKU_GIT_SOURCE_IMAGE
|
||||
previous_source_image="$(fn-git-source-image "$APP")"
|
||||
fn-plugin-property-write "git" "$APP" "source-image" "$source_image"
|
||||
fi
|
||||
|
||||
(git_build "$APP" "$REV") || exit_code="$?"
|
||||
if [[ "$exit_code" -ne 0 ]] && [[ "$has_source_image" == "true" ]]; then
|
||||
fn-plugin-property-write "git" "$APP" "source-image" "$previous_source_image"
|
||||
fi
|
||||
fn-git-build-with-lock-held "$APP" "$REV" || exit_code="$?"
|
||||
release_app_deploy_lock "$APP" "$exit_code"
|
||||
return "$exit_code"
|
||||
fi
|
||||
}
|
||||
|
||||
fn-git-build-with-lock-held() {
|
||||
declare desc="builds an app at a revision, expecting the caller to hold the app deploy lock"
|
||||
declare APP="$1" REV="$2"
|
||||
local exit_code=0 has_source_image=false source_image previous_source_image
|
||||
|
||||
# DOKKU_GIT_SOURCE_IMAGE is only applied while the deploy lock is held. An
|
||||
# empty value clears the property, while an unset variable leaves it as-is.
|
||||
if [[ -n "${DOKKU_GIT_SOURCE_IMAGE+x}" ]]; then
|
||||
has_source_image=true
|
||||
source_image="$DOKKU_GIT_SOURCE_IMAGE"
|
||||
unset DOKKU_GIT_SOURCE_IMAGE
|
||||
previous_source_image="$(fn-git-source-image "$APP")"
|
||||
fn-plugin-property-write "git" "$APP" "source-image" "$source_image"
|
||||
fi
|
||||
|
||||
(git_build "$APP" "$REV") || exit_code="$?"
|
||||
if [[ "$exit_code" -ne 0 ]] && [[ "$has_source_image" == "true" ]]; then
|
||||
fn-plugin-property-write "git" "$APP" "source-image" "$previous_source_image"
|
||||
fi
|
||||
return "$exit_code"
|
||||
}
|
||||
|
||||
cmd-git-upload-pack() {
|
||||
declare desc="executes git-upload-pack"
|
||||
declare cmd="git-upload-pack"
|
||||
|
||||
Reference in new issue
Block a user