这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <git_url>
sudo dokku plugin:install <git_url> [--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
Expand Down
24 changes: 10 additions & 14 deletions plugins/plugin/commands
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
*)
Expand All @@ -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)
Expand All @@ -67,9 +63,9 @@ case "$1" in
help | plugin:help)
cat<<EOF
plugin, Print active plugins
plugin:install [--core|git-url], Optionally download git-url & run install trigger for active plugins (or only core ones)
plugin:install [--core|git-url [--committish tag|branch|commit|--name custom-plugin-name]], Optionally download git-url (with custom tag/committish) & run install trigger for active plugins (or only core ones)
plugin:install-dependencies [--core], Run install-dependencies trigger for active plugins (or only core ones)
plugin:update [git-url], Optionally download git-url & run update trigger for active plugins
plugin:update [name [committish]], Optionally update named plugin from git (with custom tag/committish) & run update trigger for active plugins
plugin:enable <name>, Enable a previously disabled plugin
plugin:disable <name>, Disable an installed plugin (third-party only)
plugin:uninstall <name>, Uninstall a plugin (third-party only)
Expand Down
34 changes: 30 additions & 4 deletions plugins/plugin/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
36 changes: 34 additions & 2 deletions tests/unit/40_plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down