diff --git a/plugins/common/functions b/plugins/common/functions index 73beec9c1ed..2b7581f3e46 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -909,6 +909,10 @@ acquire_app_deploy_lock() { local LOCK_WAITING_MSG="$APP currently has a deploy lock in place. Waiting..." local LOCK_FAILED_MSG="$APP currently has a deploy lock in place. Exiting..." + if [[ -n "$DOKKU_LOCK_ACQUIRED" ]]; then + return + fi + acquire_advisory_lock "$APP_DEPLOY_LOCK_FILE" "$LOCK_TYPE" "$LOCK_WAITING_MSG" "$LOCK_FAILED_MSG" } @@ -952,6 +956,10 @@ release_advisory_lock() { local LOCK_FILE="$1" local LOCK_FD="200" + if [[ ! -f "$LOCK_FILE" ]]; then + return + fi + flock -u "$LOCK_FD" && rm -f "$LOCK_FILE" &>/dev/null } diff --git a/plugins/git/git-from-archive b/plugins/git/git-from-archive index fe1f71e0bcb..b048d38112a 100755 --- a/plugins/git/git-from-archive +++ b/plugins/git/git-from-archive @@ -33,6 +33,8 @@ trigger-git-git-from-archive() { elif [[ "$ARCHIVE_TYPE" == "zip" ]]; then dokku_log_verbose "Extracting zipball" unzip -d "$TMP_WORK_DIR_3" "$TMP_WORK_DIR_2/src.zip" + else + dokku_log_fail "Unsupported archive type: $ARCHIVE_TYPE" fi chmod -R u+r "$TMP_WORK_DIR_3" @@ -51,7 +53,10 @@ trigger-git-git-from-archive() { popd &>/dev/null || pushd "/tmp" >/dev/null fi - plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL" + if ! plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL"; then + dokku_log_warn "Failed to update git repository from archive" + return 1 + fi } trigger-git-git-from-archive "$@" diff --git a/plugins/git/git-from-image b/plugins/git/git-from-image index 8977a810a54..c6e3e67405b 100755 --- a/plugins/git/git-from-image +++ b/plugins/git/git-from-image @@ -34,7 +34,10 @@ trigger-git-git-from-image() { fi fn-plugin-property-write "git" "$APP" "source-image" "$DOCKER_IMAGE" - plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL" + if ! plugn trigger git-from-directory "$APP" "$TMP_WORK_DIR" "$USER_NAME" "$USER_EMAIL"; then + dokku_log_warn "Failed to update git repository from image" + return 1 + fi } trigger-git-git-from-image "$@" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 0cd95675062..5ea58c27d57 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -45,6 +45,18 @@ cmd-git-from-archive() { USER_EMAIL="${ARGS[3]}" verify_app_name "$APP" + + local exit_code=0 + acquire_app_deploy_lock "$APP" "exclusive" + export DOKKU_LOCK_ACQUIRED=1 + fn-git-from-archive "$APP" "$ARCHIVE_URL" "$ARCHIVE_TYPE" "$USER_NAME" "$USER_EMAIL" || exit_code="$?" + release_app_deploy_lock "$APP" + return "$exit_code" +} + +fn-git-from-archive() { + declare APP="$1" ARCHIVE_URL="$2" ARCHIVE_TYPE="$3" USER_NAME="$4" USER_EMAIL="$5" + [[ -z "$ARCHIVE_URL" ]] && dokku_log_fail "Please specify an archive url or -- to fetch the archive from stdin" local VALID_ARCHIVE_TYPES=("tar" "tar.gz" "zip") @@ -52,7 +64,9 @@ cmd-git-from-archive() { dokku_log_fail "Invalid archive type specified, valid archive types include: tar, tar.gz, zip" fi - plugn trigger git-from-archive "$APP" "$ARCHIVE_URL" "$ARCHIVE_TYPE" "$USER_NAME" "$USER_EMAIL" + if ! plugn trigger git-from-archive "$APP" "$ARCHIVE_URL" "$ARCHIVE_TYPE" "$USER_NAME" "$USER_EMAIL"; then + return 1 + fi plugn trigger deploy-source-set "$APP" "$ARCHIVE_TYPE" "$ARCHIVE_URL" } @@ -124,6 +138,16 @@ cmd-git-load-image() { [[ -z "$DOCKER_IMAGE" ]] && dokku_log_fail "Please specify a docker image" [[ ! -t 0 ]] || dokku_log_fail "Expecting tar archive containing docker image on STDIN" + local exit_code=0 + acquire_app_deploy_lock "$APP" "exclusive" + export DOKKU_LOCK_ACQUIRED=1 + fn-git-load-image "$APP" "$DOCKER_IMAGE" "$BUILD_DIR" "$USER_NAME" "$USER_EMAIL" || exit_code="$?" + release_app_deploy_lock "$APP" + return "$exit_code" +} + +fn-git-load-image() { + declare APP="$1" DOCKER_IMAGE="$2" BUILD_DIR="$3" USER_NAME="$4" USER_EMAIL="$5" cat | docker load if ! verify_image "$DOCKER_IMAGE"; then @@ -168,6 +192,17 @@ cmd-git-from-image() { verify_app_name "$APP" [[ -z "$DOCKER_IMAGE" ]] && dokku_log_fail "Please specify a docker image" + local exit_code=0 + acquire_app_deploy_lock "$APP" "exclusive" + export DOKKU_LOCK_ACQUIRED=1 + fn-git-from-image "$APP" "$DOCKER_IMAGE" "$BUILD_DIR" "$USER_NAME" "$USER_EMAIL" || exit_code="$?" + release_app_deploy_lock "$APP" + return "$exit_code" +} + +fn-git-from-image() { + declare APP="$1" DOCKER_IMAGE="$2" BUILD_DIR="$3" USER_NAME="$4" USER_EMAIL="$5" + if ! plugn trigger git-from-image "$APP" "$DOCKER_IMAGE" "$BUILD_DIR" "$USER_NAME" "$USER_EMAIL"; then return 1 fi @@ -207,6 +242,17 @@ cmd-git-sync() { return fi + local exit_code=0 + acquire_app_deploy_lock "$APP" "exclusive" + export DOKKU_LOCK_ACQUIRED=1 + fn-git-sync "$APP" "$GIT_REMOTE" "$GIT_REF" "$FLAG" || exit_code="$?" + release_app_deploy_lock "$APP" + return "$exit_code" +} + +fn-git-sync() { + declare APP="$1" GIT_REMOTE="$2" GIT_REF="$3" FLAG="$4" + local APP_ROOT="$DOKKU_ROOT/$APP" DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" CURRENT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)" diff --git a/tests/unit/git_5.bats b/tests/unit/git_5.bats index be7ef97bd68..6771c04c960 100644 --- a/tests/unit/git_5.bats +++ b/tests/unit/git_5.bats @@ -23,7 +23,7 @@ teardown() { } @test "(git) git:from-archive [invalid archive type]" { - run /bin/bash -c "dokku git:from-archive --archive-type tarball $TEST_APP http://example.com/src.tar" + run /bin/bash -c "dokku git:from-archive --archive-type tar $TEST_APP http://example.com/src.tar" echo "output: $output" echo "status: $status" assert_failure