这是indexloc提供的服务,不要输入任何密码
Skip to content

Lock deploys immediately upon starting a deploy process #6223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/common/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/git/git-from-archive
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 "$@"
5 changes: 4 additions & 1 deletion plugins/git/git-from-image
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
48 changes: 47 additions & 1 deletion plugins/git/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,28 @@ 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")
if ! fn-in-array "$ARCHIVE_TYPE" "${ARCHIVE_TYPE[@]}"; then
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"
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/git_5.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading