From 50958fc44814a55d43182c615675b805271df29e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 13 Mar 2024 06:22:29 -0400 Subject: [PATCH] refactor: remove git:unlock command This is no longer necessary with improvements elsewhere in Dokku. --- docs/appendices/0.34.0-migration-guide.md | 1 + docs/deployment/methods/git.md | 1 - plugins/common/functions | 3 +- plugins/git/help-functions | 1 - plugins/git/internal-functions | 74 +++++------------------ tests/unit/git_6.bats | 30 --------- 6 files changed, 17 insertions(+), 93 deletions(-) delete mode 100644 tests/unit/git_6.bats diff --git a/docs/appendices/0.34.0-migration-guide.md b/docs/appendices/0.34.0-migration-guide.md index b2811ce51..43461200f 100644 --- a/docs/appendices/0.34.0-migration-guide.md +++ b/docs/appendices/0.34.0-migration-guide.md @@ -3,6 +3,7 @@ ## Removals - The `disable-chown` property of the `scheduler-docker-local` plugin has been removed. Mounted paths will no longer have file permissions changed during the pre-deploy phase. Files baked into the container image for herokuish builds will always be owned by the correct user. +- The `git:unlock` command has been removed. It was previously used to "unlock" a temporary directory that already existed. The directory the `git:unlock` command used to cleanup is now properly removed on exit of the `git:from-image` command. ## Changes diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index 9126a3d62..1bfd498a4 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -16,7 +16,6 @@ git:public-key # Outputs the dokku public dep git:report [] [] # Displays a git report for one or more apps git:set () # Set or clear a git property for an app git:status # Show the working tree status for an app -git:unlock [--force] # Removes previous git clone folder for new deployment ``` Git-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`. A Git-based deployment currently supports building applications via: diff --git a/plugins/common/functions b/plugins/common/functions index 95474e144..b47c74a81 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -997,13 +997,14 @@ suppress_output() { declare desc="suppress all output from a given command unless there is an error" local TMP_COMMAND_OUTPUT TMP_COMMAND_OUTPUT=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") - trap "rm -rf '$TMP_COMMAND_OUTPUT' >/dev/null" RETURN "$@" >"$TMP_COMMAND_OUTPUT" 2>&1 || { local exit_code="$?" cat "$TMP_COMMAND_OUTPUT" + rm -rf "$TMP_COMMAND_OUTPUT" >/dev/null return "$exit_code" } + rm -rf "$TMP_COMMAND_OUTPUT" >/dev/null return 0 } diff --git a/plugins/git/help-functions b/plugins/git/help-functions index 49b34ad41..c0fd67da8 100755 --- a/plugins/git/help-functions +++ b/plugins/git/help-functions @@ -38,7 +38,6 @@ fn-help-content() { git:public-key, Outputs the dokku public deploy key git:report [] [], Displays a git report for one or more apps git:set (), Set or clear a git property for an app - git:unlock [--force], Removes previous git clone folder for new deployment git:status , show the working tree status for an app help_content } diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 307669888..dab338d52 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -196,20 +196,6 @@ cmd-git-sync() { verify_app_name "$APP" - local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" - - if [[ -d "$APP_CLONE_ROOT" ]]; then - if has_tty eq 0; then - cmd-git-unlock "$APP" - if [[ -d "$APP_CLONE_ROOT" ]]; then - dokku_log_fail "Failed to delete existing clone folder" - exit 15 - fi - else - dokku_log_fail "Run 'git:unlock' to remove the existing temporary clone" - fi - fi - if [[ -z "$GIT_REMOTE" ]]; then dokku_log_fail "Missing GIT_REMOTE parameter" return @@ -234,41 +220,6 @@ cmd-git-sync() { fi } -cmd-git-unlock() { - declare desc="removes the clone folder for an app" - local cmd="git:unlock" - [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" FLAG - - for arg in "$@"; do - if [[ "$arg" == "--force" ]]; then - FLAG="--force" - continue - fi - - ARGS+=("$arg") - done - - local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" - - if [[ -d "$APP_CLONE_ROOT" ]]; then - if [[ "$FLAG" == "--force" ]]; then - fn-git-remove-clone-folder "$APP_CLONE_ROOT" - else - read -rp "Are you sure that want to delete clone folder (y/n)?" choice - case "$choice" in - y | Y) - fn-git-remove-clone-folder "$APP_CLONE_ROOT" - ;; - n | N) echo "no" ;; - *) echo "please answer with yes or no" ;; - esac - fi - else - dokku_log_info1 "No clone folder exists app already unlocked" - fi -} - cmd-git-public-key() { declare desc="outputs the dokku public deploy key" local cmd="git:public-key" @@ -399,7 +350,6 @@ EOF fn-git-clone() { declare desc="creates an app from remote git repo" declare APP="$1" GIT_REMOTE="$2" GIT_REF="$3" - local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" local APP_ROOT="$DOKKU_ROOT/$APP" [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" @@ -411,20 +361,24 @@ fn-git-clone() { GIT_REF="$(fn-git-deploy-branch "$APP")" fi - trap "rm -rf '$APP_CLONE_ROOT' > /dev/null" RETURN INT TERM EXIT + local TMP_IS_REF_DIR=$(mktemp -d "/tmp/dokku-ref-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") + trap "rm -rf '$TMP_IS_REF_DIR' >/dev/null" RETURN INT TERM EXIT is_ref=true - if GIT_TERMINAL_PROMPT=0 git clone --depth 1 -n --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" 2>/dev/null; then + if GIT_TERMINAL_PROMPT=0 git clone --depth 1 -n --branch "$GIT_REF" "$GIT_REMOTE" "$TMP_IS_REF_DIR" 2>/dev/null; then is_ref=false fi - rm -rf "$APP_CLONE_ROOT" + rm -rf "$TMP_IS_REF_DIR" + + local TMP_CLONE_DIR=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") + trap "rm -rf '$TMP_CLONE_DIR' >/dev/null" RETURN INT TERM EXIT if [[ "$is_ref" == "true" ]]; then - GIT_TERMINAL_PROMPT=0 suppress_output git clone -n "$GIT_REMOTE" "$APP_CLONE_ROOT" - fn-git-cmd "$APP_CLONE_ROOT" checkout -qq "$GIT_REF" + GIT_TERMINAL_PROMPT=0 suppress_output git clone -n "$GIT_REMOTE" "$TMP_WORK_DIR" + fn-git-cmd "$TMP_CLONE_DIR" checkout -qq "$GIT_REF" else - GIT_TERMINAL_PROMPT=0 suppress_output git clone -n --branch "$GIT_REF" "$GIT_REMOTE" "$APP_CLONE_ROOT" - if fn-git-cmd "$APP_CLONE_ROOT" show-ref --verify "refs/heads/$GIT_REF" &>/dev/null; then + GIT_TERMINAL_PROMPT=0 suppress_output git clone -n --branch "$GIT_REF" "$GIT_REMOTE" "$TMP_CLONE_DIR" + if fn-git-cmd "$TMP_CLONE_DIR" show-ref --verify "refs/heads/$GIT_REF" &>/dev/null; then dokku_log_verbose "Detected branch, setting deploy-branch to $GIT_REF" fn-plugin-property-write "git" "$APP" "deploy-branch" "$GIT_REF" fi @@ -433,13 +387,13 @@ fn-git-clone() { DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" if [[ "$GIT_REF" != "$DOKKU_DEPLOY_BRANCH" ]]; then if [[ "$is_ref" == "true" ]]; then - fn-git-cmd "$APP_CLONE_ROOT" branch -qq -D "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true + fn-git-cmd "$TMP_CLONE_DIR" branch -qq -D "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true fi - fn-git-cmd "$APP_CLONE_ROOT" checkout -qq -b "$DOKKU_DEPLOY_BRANCH" + fn-git-cmd "$TMP_CLONE_DIR" checkout -qq -b "$DOKKU_DEPLOY_BRANCH" fi - rsync -a "$APP_CLONE_ROOT/.git/" "$APP_ROOT" + rsync -a "$TMP_CLONE_DIR/.git/" "$APP_ROOT" fn-git-create-hook "$APP" fn-git-cmd "$APP_ROOT" config --add core.bare true } diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats deleted file mode 100644 index ab706a575..000000000 --- a/tests/unit/git_6.bats +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -setup() { - global_setup - touch /home/dokku/.ssh/known_hosts - chown dokku:dokku /home/dokku/.ssh/known_hosts - mkdir -p "$DOKKU_LIB_ROOT/data/git/$TEST_APP" - chown dokku:dokku "$DOKKU_LIB_ROOT/data/git/$TEST_APP" -} - -teardown() { - rm -f /home/dokku/.ssh/id_rsa.pub || true - global_teardown -} - -@test "(git) git:unlock [success]" { - run /bin/bash -c "dokku git:unlock $TEST_APP --force" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(git) git:unlock [missing arg]" { - run /bin/bash -c "dokku git:unlock" - echo "output: $output" - echo "status: $status" - assert_failure -}