From 8095df79f674912a05390d9f58171d98212e19fa Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 9 Sep 2015 18:27:42 -0700 Subject: [PATCH] implement core plugin mgmt using plugn. add tests. --- Makefile | 14 +++--- dokku | 12 +++-- plugins/00_dokku-standard/commands | 4 +- plugins/20_events/commands | 2 +- plugins/20_events/hook | 2 +- plugins/20_events/install | 2 +- plugins/WARNING | 2 - plugins/apps/commands | 2 +- plugins/apps/post-delete | 2 +- plugins/apps/pre-delete | 2 +- plugins/build-env/pre-build-buildpack | 4 +- plugins/certs/commands | 4 +- plugins/certs/functions | 2 +- plugins/checks/check-deploy | 4 +- plugins/config/commands | 4 +- plugins/config/docker-args-deploy | 4 +- plugins/config/functions | 2 +- plugins/docker-options/commands | 2 +- plugins/domains/commands | 6 +-- plugins/domains/functions | 2 +- plugins/enter/commands | 2 +- plugins/git/commands | 2 +- plugins/git/receive-app | 2 +- plugins/nginx-vhosts/bind-external-ip | 2 +- plugins/nginx-vhosts/commands | 8 +-- plugins/nginx-vhosts/post-deploy | 4 +- plugins/nginx-vhosts/post-domains-update | 2 +- plugins/plugin/commands | 64 ++++++++++++++++-------- plugins/plugin/functions | 41 +++++++++++++++ plugins/ps/commands | 4 +- plugins/ps/functions | 2 +- plugins/ps/pre-deploy | 4 +- plugins/tags/commands | 4 +- plugins/tags/functions | 2 +- plugins/tar/commands | 2 +- plugins/tar/receive-app | 2 +- tests/unit/core_ports.bats | 4 +- tests/unit/plugin.bats | 45 +++++++++++++++++ tests/unit/test_helper.bash | 7 ++- 39 files changed, 199 insertions(+), 82 deletions(-) delete mode 100644 plugins/WARNING create mode 100755 plugins/plugin/functions create mode 100644 tests/unit/plugin.bats diff --git a/Makefile b/Makefile index 675c3bbb9..cb805223f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,6 @@ PREBUILT_STACK_URL ?= gliderlabs/herokuish:latest DOKKU_LIB_ROOT ?= /var/lib/dokku PLUGINS_PATH ?= ${DOKKU_LIB_ROOT}/plugins CORE_PLUGINS_PATH ?= ${DOKKU_LIB_ROOT}/core-plugins -DISABLED_PLUGINS_PATH ?= ${DOKKU_LIB_ROOT}/disabled-plugins # If the first argument is "vagrant-dokku"... ifeq (vagrant-dokku,$(firstword $(MAKECMDGOALS))) @@ -47,18 +46,21 @@ packer: copyfiles: cp dokku /usr/local/bin/dokku - mkdir -p ${CORE_PLUGINS_PATH} ${PLUGINS_PATH} ${DISABLED_PLUGINS_PATH} + mkdir -p ${CORE_PLUGINS_PATH} ${PLUGINS_PATH} rm -rf ${CORE_PLUGINS_PATH}/* + test -d ${CORE_PLUGINS_PATH}/enabled || PLUGIN_PATH=${CORE_PLUGINS_PATH} plugn init test -d ${PLUGINS_PATH}/enabled || PLUGIN_PATH=${PLUGINS_PATH} plugn init find plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read plugin; do \ + rm -Rf ${CORE_PLUGINS_PATH}/available/$$plugin && \ rm -Rf ${PLUGINS_PATH}/available/$$plugin && \ - rm -Rf ${CORE_PLUGINS_PATH}/$$plugin && \ + rm -rf ${CORE_PLUGINS_PATH}/$$plugin && \ rm -rf ${PLUGINS_PATH}/$$plugin && \ - cp -R plugins/$$plugin ${CORE_PLUGINS_PATH} && \ - ln -s ${CORE_PLUGINS_PATH}/$$plugin ${PLUGINS_PATH}/available; \ + cp -R plugins/$$plugin ${CORE_PLUGINS_PATH}/available && \ + ln -s ${CORE_PLUGINS_PATH}/available/$$plugin ${PLUGINS_PATH}/available; \ + PLUGIN_PATH=${CORE_PLUGINS_PATH} plugn enable $$plugin ;\ PLUGIN_PATH=${PLUGINS_PATH} plugn enable $$plugin ;\ done - chown dokku:dokku -R ${PLUGINS_PATH} ${CORE_PLUGINS_PATH} ${DISABLED_PLUGINS_PATH} + chown dokku:dokku -R ${PLUGINS_PATH} ${CORE_PLUGINS_PATH} $(MAKE) addman addman: diff --git a/dokku b/dokku index c90d694b2..fa1265d8d 100755 --- a/dokku +++ b/dokku @@ -8,8 +8,12 @@ export DOKKU_ROOT=${DOKKU_ROOT:=~dokku} export DOKKU_LIB_ROOT=${DOKKU_LIB_PATH:="/var/lib/dokku"} export PLUGIN_PATH=${PLUGIN_PATH:="$DOKKU_LIB_ROOT/plugins"} +export PLUGIN_AVAILABLE_PATH=${PLUGIN_AVAILABLE_PATH:="$PLUGIN_PATH/available"} +export PLUGIN_ENABLED_PATH=${PLUGIN_ENABLED_PATH:="$PLUGIN_PATH/enabled"} export PLUGIN_CORE_PATH=${PLUGIN_CORE_PATH:="$DOKKU_LIB_ROOT/core-plugins"} -export PLUGIN_DISABLED_PATH=${PLUGIN_DISABLED_PATH:="$DOKKU_LIB_ROOT/disabled-plugins"} +export PLUGIN_CORE_AVAILABLE_PATH=${PLUGIN_CORE_AVAILABLE_PATH:="$PLUGIN_CORE_PATH/available"} +export PLUGIN_CORE_ENABLED_PATH=${PLUGIN_CORE_ENABLED_PATH:="$PLUGIN_CORE_PATH/enabled"} + export DOKKU_API_VERSION=1 export DOKKU_NOT_IMPLEMENTED_EXIT=10 export DOKKU_VALID_EXIT=0 @@ -17,7 +21,7 @@ export DOKKU_VALID_EXIT=0 export DOKKU_LOGS_DIR=${DOKKU_LOGS_DIR:="/var/log/dokku"} export DOKKU_EVENTS_LOGFILE=${DOKKU_EVENTS_LOGFILE:="$DOKKU_LOGS_DIR/events.log"} -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" [[ -f $DOKKU_ROOT/dokkurc ]] && source $DOKKU_ROOT/dokkurc [[ -d $DOKKU_ROOT/.dokkurc ]] && for f in $DOKKU_ROOT/.dokkurc/*; do source $f; done @@ -37,7 +41,7 @@ if [[ "${args[0]}" =~ ^--.* ]]; then fi ! has_tty && DOKKU_QUIET_OUTPUT=1 -if [[ $(id -un) != "dokku" && $1 != plugin:install* && $1 != "plugin:update" ]]; then +if [[ $(id -un) != "dokku" && $1 != plugin:*install* && $1 != "plugin:update" ]]; then sudo -u dokku -E -H $0 "$@" exit fi @@ -219,7 +223,7 @@ EOF *) implemented=0 - for script in $PLUGIN_PATH/enabled/*/commands; do + for script in $PLUGIN_ENABLED_PATH/*/commands; do set +e; $script "$@" ; exit_code=$? ; set -e if [[ "$exit_code" -eq "$DOKKU_NOT_IMPLEMENTED_EXIT" ]]; then continue diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 0175fe9f1..70e9ddc74 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" case "$1" in build) diff --git a/plugins/20_events/commands b/plugins/20_events/commands index 4c5b7dea8..7d9d502d6 100755 --- a/plugins/20_events/commands +++ b/plugins/20_events/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" PLUGIN_DIR="$(dirname $0)" diff --git a/plugins/20_events/hook b/plugins/20_events/hook index 96237195d..e9a05dd21 100755 --- a/plugins/20_events/hook +++ b/plugins/20_events/hook @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" [[ ! "$DOKKU_EVENTS" ]] || dokku_log_plugn_trigger_call "$(basename $0)" "$@" diff --git a/plugins/20_events/install b/plugins/20_events/install index 8e90f3409..deed941d4 100755 --- a/plugins/20_events/install +++ b/plugins/20_events/install @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" DOKKU_RSYSLOG_FILTER=/etc/rsyslog.d/99-dokku.conf DOKKU_LOGROTATE_FILE=/etc/logrotate.d/dokku diff --git a/plugins/WARNING b/plugins/WARNING deleted file mode 100644 index d3eee9aac..000000000 --- a/plugins/WARNING +++ /dev/null @@ -1,2 +0,0 @@ - -Please note that the hooks in Dokku are experimental and are likely to change quite a bit. \ No newline at end of file diff --git a/plugins/apps/commands b/plugins/apps/commands index 5e5ab8f98..9c79b2e55 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" case "$1" in apps) diff --git a/plugins/apps/post-delete b/plugins/apps/post-delete index 11051a912..91fe06e20 100755 --- a/plugins/apps/post-delete +++ b/plugins/apps/post-delete @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" APP="$1"; IMAGE_REPO=$(get_app_image_repo $APP) [[ -n $APP ]] && rm -rf "$DOKKU_ROOT/$APP" > /dev/null diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index e9727d6b6..376baa94b 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG); CACHE_DIR="$DOKKU_ROOT/$APP/cache" verify_app_name "$APP" diff --git a/plugins/build-env/pre-build-buildpack b/plugins/build-env/pre-build-buildpack index 6916ae0a7..2ca012bb1 100755 --- a/plugins/build-env/pre-build-buildpack +++ b/plugins/build-env/pre-build-buildpack @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" APP="$1"; IMAGE=$(get_app_image_name $APP); BUILD_ENV="" verify_app_name "$APP" diff --git a/plugins/certs/commands b/plugins/certs/commands index b74849cd3..4f96949d7 100755 --- a/plugins/certs/commands +++ b/plugins/certs/commands @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/certs/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/certs/functions" is_tar_import() { [[ -t 0 ]] && return 1 diff --git a/plugins/certs/functions b/plugins/certs/functions index 532087bb1..1e852846b 100755 --- a/plugins/certs/functions +++ b/plugins/certs/functions @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" # returns 'global', 'app', 'false' # if both are configured, app trumps global diff --git a/plugins/checks/check-deploy b/plugins/checks/check-deploy index 3b8ab3c9a..1cb990bb2 100755 --- a/plugins/checks/check-deploy +++ b/plugins/checks/check-deploy @@ -35,8 +35,8 @@ # set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" APP="$1"; DOKKU_APP_CONTAINER_ID="$2"; DOKKU_APP_CONTAINER_TYPE="$3"; DOKKU_APP_LISTEN_PORT="$4"; DOKKU_APP_LISTEN_IP="$5" if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT" ]]; then diff --git a/plugins/config/commands b/plugins/config/commands index 96955ae2b..f42f3e2d6 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" case "$1" in config) diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 2348d820a..6d7b161c4 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" STDIN=$(cat); APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE" diff --git a/plugins/config/functions b/plugins/config/functions index dd69b50bb..51debd179 100644 --- a/plugins/config/functions +++ b/plugins/config/functions @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" config_export() { local CONFIG_TYPE="$1" diff --git a/plugins/docker-options/commands b/plugins/docker-options/commands index ac4069fb8..e2e434de7 100755 --- a/plugins/docker-options/commands +++ b/plugins/docker-options/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" PHASES=(build deploy run) diff --git a/plugins/domains/commands b/plugins/domains/commands index f6863c60f..4156e423b 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" -source "$PLUGIN_PATH/available/domains/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/domains/functions" RE_IPV4="([0-9]{1,3}[\.]){3}[0-9]{1,3}" diff --git a/plugins/domains/functions b/plugins/domains/functions index 74c1a6ea1..2a69c42a0 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" get_app_domains() { local APP=$1; verify_app_name $APP diff --git a/plugins/enter/commands b/plugins/enter/commands index 1dcceaf3d..b8e0bdbdc 100755 --- a/plugins/enter/commands +++ b/plugins/enter/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" case "$1" in enter) diff --git a/plugins/git/commands b/plugins/git/commands index ced23cef3..910df652d 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" git_build_app_repo() { verify_app_name "$1" diff --git a/plugins/git/receive-app b/plugins/git/receive-app index da534d709..79dbfeae6 100755 --- a/plugins/git/receive-app +++ b/plugins/git/receive-app @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" APP="$1"; REV="$2" diff --git a/plugins/nginx-vhosts/bind-external-ip b/plugins/nginx-vhosts/bind-external-ip index 01f1f57b1..2fca6e4a5 100755 --- a/plugins/nginx-vhosts/bind-external-ip +++ b/plugins/nginx-vhosts/bind-external-ip @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" APP="$1" NO_VHOST=$(config_get $APP NO_VHOST || true) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 21b14b985..7c0711287 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/certs/functions" -source "$PLUGIN_PATH/available/config/functions" -source "$PLUGIN_PATH/available/domains/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/certs/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/domains/functions" validate_nginx () { set +e diff --git a/plugins/nginx-vhosts/post-deploy b/plugins/nginx-vhosts/post-deploy index e29efb5c2..6d6a2325e 100755 --- a/plugins/nginx-vhosts/post-deploy +++ b/plugins/nginx-vhosts/post-deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" APP="$1" if [[ -f "$DOKKU_ROOT/$APP/IP.web.1" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]]; then diff --git a/plugins/nginx-vhosts/post-domains-update b/plugins/nginx-vhosts/post-domains-update index edb88b6f8..20abd9d5e 100755 --- a/plugins/nginx-vhosts/post-domains-update +++ b/plugins/nginx-vhosts/post-domains-update @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" APP="$1" diff --git a/plugins/plugin/commands b/plugins/plugin/commands index 213111c8e..8541d9294 100755 --- a/plugins/plugin/commands +++ b/plugins/plugin/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/plugin/functions" case "$1" in plugin) @@ -8,10 +9,20 @@ case "$1" in ;; plugin:install) - if [[ $2 == "--core" ]]; then - export PLUGIN_PATH="$PLUGIN_CORE_PATH" - fi - plugn trigger install + case "$2" in + --core) + [[ "$#" -gt 2 ]] && dokku_log_info1_quiet "Cannot install additional core plugins, running core plugin install trigger" + PLUGIN_PATH="$PLUGIN_CORE_PATH" plugn trigger install + ;; + https:*|git:*) + PLUGIN_GIT_URL="$2" + download_and_enable_plugin $PLUGIN_GIT_URL + plugn trigger install + ;; + *) + plugn trigger install + ;; + esac ;; plugin:install-dependencies) @@ -22,34 +33,45 @@ case "$1" in ;; plugin:update) - plugn trigger update + case "$2" in + https:*|git:*) + PLUGIN_GIT_URL="$2" + download_and_enable_plugin $PLUGIN_GIT_URL + plugn trigger update + ;; + *) + plugn trigger update + ;; + esac ;; - plugins:disable) + plugin:disable) + [[ -z $2 ]] && dokku_log_fail "Please specify a plugin to disable" PLUGIN="$2" - [[ -e $PLUGIN_CORE_PATH/$PLUGIN ]] && echo "Cannot disable a core plugin" && exit 1 - [[ -e $PLUGIN_DISABLED_PATH/$PLUGIN ]] && echo "Plugin already disabled" && exit 1 - [[ ! -e $PLUGIN_PATH/$PLUGIN ]] && echo "Plugin does not exist" && exit 1 - mv "$PLUGIN_PATH/$PLUGIN" "$PLUGIN_DISABLED_PATH" - echo "Plugin $PLUGIN disabled" + disable_plugin "$PLUGIN" ;; - plugins:enable) + plugin:enable) + [[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable" PLUGIN="$2" - [[ -e $PLUGIN_PATH/$PLUGIN ]] && echo "Plugin already enabled" && exit 1 - [[ ! -e $PLUGIN_DISABLED_PATH/$PLUGIN ]] && echo "Plugin does not exist" && exit 1 - mv "$PLUGIN_DISABLED_PATH/$PLUGIN" "$PLUGIN_PATH" - echo "Plugin $PLUGIN enabled" + enable_plugin "$PLUGIN" ;; - help | ps:help) + plugin:uninstall) + [[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable" + PLUGIN="$2" + uninstall_plugin "$PLUGIN" + ;; + + 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) EOF ;; diff --git a/plugins/plugin/functions b/plugins/plugin/functions new file mode 100755 index 000000000..a30c6dcc7 --- /dev/null +++ b/plugins/plugin/functions @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +disable_plugin() { + local PLUGIN="$1" + [[ -e $PLUGIN_CORE_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Cannot disable a core plugin" + [[ ! -e $PLUGIN_ENABLED_PATH/$PLUGIN ]] && dokku_log_fail "Plugin already disabled" + [[ ! -e $PLUGIN_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Plugin does not exist" + plugn disable $PLUGIN + dokku_log_info1_quiet "Plugin $PLUGIN disabled" +} + +enable_plugin() { + local PLUGIN="$1" + [[ -e $PLUGIN_ENABLED_PATH/$PLUGIN ]] && dokku_log_fail "Plugin already enabled" + [[ ! -e $PLUGIN_AVAILABLE_PATH/$PLUGIN ]] && dokku_log_fail "Plugin does not exist" + plugn enable $PLUGIN + dokku_log_info1_quiet "Plugin $PLUGIN enabled" +} + +download_plugin() { + local PLUGIN_GIT_URL="$1" + plugn install $PLUGIN_GIT_URL +} + +download_and_enable_plugin() { + local PLUGIN_GIT_URL="$1" + local PLUGIN_NAME=$(echo $PLUGIN_GIT_URL | awk -F '/' '{ print $NF }' | sed -e "s:.git::g") + dokku_log_info1_quiet "Cloning plugin repo $PLUGIN_GIT_URL to $PLUGIN_AVAILABLE_PATH/$PLUGIN_NAME" + download_plugin $PLUGIN_GIT_URL + enable_plugin $PLUGIN_NAME +} + +uninstall_plugin() { + local PLUGIN_NAME="$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 + dokku_log_info1_quiet "Plugin $PLUGIN uninstalled" +} diff --git a/plugins/ps/commands b/plugins/ps/commands index cdf045996..37a052783 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/ps/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions" case "$1" in ps) diff --git a/plugins/ps/functions b/plugins/ps/functions index b0e3a1091..64f667210 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" print_dokku_scale_file() { local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" diff --git a/plugins/ps/pre-deploy b/plugins/ps/pre-deploy index d80691134..ea0d574bd 100755 --- a/plugins/ps/pre-deploy +++ b/plugins/ps/pre-deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/ps/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions" APP="$1" diff --git a/plugins/tags/commands b/plugins/tags/commands index c787840b1..c255f25bd 100755 --- a/plugins/tags/commands +++ b/plugins/tags/commands @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" -source "$PLUGIN_PATH/available/tags/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/tags/functions" case "$1" in tags) diff --git a/plugins/tags/functions b/plugins/tags/functions index 155e2778f..df1721dfd 100755 --- a/plugins/tags/functions +++ b/plugins/tags/functions @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" tag_image() { docker tag -f "$1" "$2" diff --git a/plugins/tar/commands b/plugins/tar/commands index 902157ef6..76da3766f 100755 --- a/plugins/tar/commands +++ b/plugins/tar/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" case "$1" in tar-from|tar:from) diff --git a/plugins/tar/receive-app b/plugins/tar/receive-app index 57b05857b..e84dc3dba 100755 --- a/plugins/tar/receive-app +++ b/plugins/tar/receive-app @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_PATH/available/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" APP="$1"; REV="$2" diff --git a/tests/unit/core_ports.bats b/tests/unit/core_ports.bats index fbfa297e8..79f6c1b95 100644 --- a/tests/unit/core_ports.bats +++ b/tests/unit/core_ports.bats @@ -165,7 +165,7 @@ check_urls() { } @test "(core) port exposure (dockerfile raw port)" { - source "$PLUGIN_PATH/available/common/functions" + source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" cat< $DOCKERFILE EXPOSE 3001/udp EXPOSE 3003 @@ -178,7 +178,7 @@ EOF } @test "(core) port exposure (dockerfile tcp port)" { - source "$PLUGIN_PATH/available/common/functions" + source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" cat< $DOCKERFILE EXPOSE 3001/udp EXPOSE 3000/tcp diff --git a/tests/unit/plugin.bats b/tests/unit/plugin.bats new file mode 100644 index 000000000..dfa0a849d --- /dev/null +++ b/tests/unit/plugin.bats @@ -0,0 +1,45 @@ +#!/usr/bin/env bats + +load test_helper +TEST_PLUGIN_NAME=smoke-test-plugin +TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_NAME}.git + +remove_test_plugin() { + rm -rf $PLUGIN_ENABLED_PATH/$TEST_PLUGIN_NAME $PLUGIN_AVAILABLE_PATH/$TEST_PLUGIN_NAME +} + +teardown() { + remove_test_plugin || true +} + +@test "(plugin) plugin:install, plugin:disable, plugin:uninstall" { + run bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin | grep enabled | grep $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin:disable $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin | grep disabled | grep $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin:uninstall $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku plugin | grep $TEST_PLUGIN_NAME" + echo "output: "$output + echo "status: "$status + assert_failure +} diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 9bb6c4ae4..a552569dd 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -2,7 +2,12 @@ # constants DOKKU_ROOT=${DOKKU_ROOT:=~dokku} -PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"} +DOKKU_LIB_ROOT=${DOKKU_LIB_PATH:="/var/lib/dokku"} +PLUGIN_PATH=${PLUGIN_PATH:="$DOKKU_LIB_ROOT/plugins"} +PLUGIN_AVAILABLE_PATH=${PLUGIN_AVAILABLE_PATH:="$PLUGIN_PATH/available"} +PLUGIN_ENABLED_PATH=${PLUGIN_ENABLED_PATH:="$PLUGIN_PATH/enabled"} +PLUGIN_CORE_PATH=${PLUGIN_CORE_PATH:="$DOKKU_LIB_ROOT/core-plugins"} +PLUGIN_CORE_AVAILABLE_PATH=${PLUGIN_CORE_AVAILABLE_PATH:="$PLUGIN_CORE_PATH/available"} TEST_APP=my-cool-guy-test-app # test functions