diff --git a/docs/plugins.md b/docs/plugins.md index f3e91578810..b8e4b12740e 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -16,7 +16,7 @@ Let's take a quick look at the current dokku nginx plugin that's shipped with do # This command requires `root` permissions as the `install` and `install-dependencies` # plugin triggers may utilize commands such as `apt-get`. For non-core plugins, please # inspect those plugins before running the following command as `root` user. -sudo dokku plugin:install +sudo dokku plugin:install [--committish tag/branch/commit|--name custom-plugin-name] # previous versions (0.3.x and below) of dokku require a manual process to install plugins cd /var/lib/dokku/plugins diff --git a/plugins/plugin/commands b/plugins/plugin/commands index c74fffe0242..f335b8a7de9 100755 --- a/plugins/plugin/commands +++ b/plugins/plugin/commands @@ -16,8 +16,8 @@ case "$1" in PLUGIN_PATH="$PLUGIN_CORE_PATH" plugn trigger install ;; https:*|git:*|ssh:*) - PLUGIN_GIT_URL="$2" - download_and_enable_plugin "$PLUGIN_GIT_URL" "$3" + shift + download_and_enable_plugin "$@" plugn trigger install ;; *) @@ -34,16 +34,12 @@ case "$1" in ;; plugin:update) - case "$2" in - https:*|git:*) - PLUGIN_GIT_URL="$2" - download_and_enable_plugin "$PLUGIN_GIT_URL" "$3" - plugn trigger update - ;; - *) - plugn trigger update - ;; - esac + if [[ -n "$2" ]]; then + PLUGIN="$2" + PLUGIN_COMMITTISH="$3" + plugn update "$PLUGIN" "$PLUGIN_COMMITTISH" + fi + plugn trigger update ;; plugin:disable) @@ -67,9 +63,9 @@ case "$1" in help | plugin:help) cat<, Enable a previously disabled plugin plugin:disable , Disable an installed plugin (third-party only) plugin:uninstall , Uninstall a plugin (third-party only) diff --git a/plugins/plugin/functions b/plugins/plugin/functions index 8ccb5a6ef0d..b5f345fd519 100755 --- a/plugins/plugin/functions +++ b/plugins/plugin/functions @@ -27,18 +27,44 @@ download_plugin() { download_and_enable_plugin() { local PLUGIN_GIT_URL="$1" - local CUSTOM_NAME="$2" + shift + while getopts ":-:" opt "$@"; do + case "$opt" in + -) + case "$OPTARG" in + committish) + val="${!OPTIND}"; OPTIND=$(( OPTIND + 1 )) + local PLUGIN_COMMITTISH="$val" + ;; + name) + val="${!OPTIND}"; OPTIND=$(( OPTIND + 1 )) + local CUSTOM_NAME="$val" + ;; + esac + ;; + esac + done local PLUGIN_NAME=${CUSTOM_NAME:-$(plugin_name "$PLUGIN_GIT_URL")} dokku_log_info1_quiet "Cloning plugin repo $PLUGIN_GIT_URL to $PLUGIN_AVAILABLE_PATH/$PLUGIN_NAME" download_plugin "$PLUGIN_GIT_URL" "$PLUGIN_NAME" enable_plugin "$PLUGIN_NAME" + if [[ -n "$PLUGIN_COMMITTISH" ]];then + update_plugin "$PLUGIN_NAME" "$PLUGIN_COMMITTISH" + fi +} + +update_plugin() { + local PLUGIN="$1" + local PLUGIN_COMMITTISH="$2" + [[ ! -e $PLUGIN_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Plugin ($PLUGIN) is not currently installed" + plugn update "$@" } uninstall_plugin() { - local PLUGIN_NAME="$1" + local PLUGIN="$1" [[ -e $PLUGIN_CORE_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Cannot uninstall a core plugin" - [[ ! -e $PLUGIN_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Plugin does not exist" - plugn uninstall $PLUGIN_NAME + [[ ! -e $PLUGIN_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Plugin ($PLUGIN) is not currently installed" + plugn uninstall $PLUGIN dokku_log_info1_quiet "Plugin $PLUGIN uninstalled" } diff --git a/tests/unit/40_plugin.bats b/tests/unit/40_plugin.bats index 68da9f2c132..d811116b2a6 100644 --- a/tests/unit/40_plugin.bats +++ b/tests/unit/40_plugin.bats @@ -12,8 +12,13 @@ teardown() { remove_test_plugin || true } -@test "(plugin) plugin:install, plugin:disable, plugin:uninstall" { - run bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO" +@test "(plugin) plugin:install, plugin:disable, plugin:update plugin:uninstall" { + run bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO --name $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin:update $TEST_PLUGIN_NAME" echo "output: "$output echo "status: "$status assert_success @@ -49,6 +54,33 @@ teardown() { assert_failure } +@test "(plugin) plugin:install plugin:update (with tag)" { + run bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO --committish v0.2.0 --name $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin | grep enabled | grep $TEST_PLUGIN_NAME | grep 0.2.0" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin:update $TEST_PLUGIN_NAME v0.3.0" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin | grep enabled | grep $TEST_PLUGIN_NAME | grep 0.2.0" + echo "output: "$output + echo "status: "$status + assert_failure + + run bash -c "dokku plugin | grep enabled | grep $TEST_PLUGIN_NAME | grep 0.3.0" + echo "output: "$output + echo "status: "$status + assert_success +} + @test "(plugin) plugin:install, plugin:disable, plugin:uninstall as non-root user failure" { run bash -c "sudo -E -u nobody dokku plugin:install $TEST_PLUGIN_GIT_REPO" echo "output: "$output