Merge pull request #1826 from dokku/1531_mh-plugin-update

implement plugn update
This commit is contained in:
Jose Diaz-Gonzalez
2016-01-05 14:17:53 -05:00
4 changed files with 75 additions and 21 deletions

View File

@@ -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

View File

@@ -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<<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)

View File

@@ -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"
}

View File

@@ -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