From fc8a8d6138a0b089e9d386c947e02f3886cb4e1e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 1 Feb 2020 17:06:27 -0800 Subject: [PATCH] feat: implement docker-options:clear Closes #3776 --- docs/advanced-usage/docker-options.md | 32 +++++++++++++++++ plugins/docker-options/commands | 1 + plugins/docker-options/subcommands/clear | 29 +++++++++++++++ tests/unit/20_docker-options.bats | 45 ++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100755 plugins/docker-options/subcommands/clear diff --git a/docs/advanced-usage/docker-options.md b/docs/advanced-usage/docker-options.md index 967ae1328..9414eb187 100644 --- a/docs/advanced-usage/docker-options.md +++ b/docs/advanced-usage/docker-options.md @@ -6,6 +6,7 @@ Pass [options](https://docs.docker.com/engine/reference/run/) to Docker during D ``` docker-options:add OPTION # Add Docker option to app for phase (comma-separated phase list) +docker-options:clear [...] # Clear a docker options from application docker-options:remove OPTION # Remove Docker option from app for phase (comma-separated phase list) docker-options:report [] [] # Displays a docker options report for one or more apps ``` @@ -44,6 +45,37 @@ dokku docker-options:add node-js-app run "-v /var/log/node-js-app:/app/logs" dokku docker-options:remove node-js-app run "-v /var/log/node-js-app:/app/logs" ``` +### Clear all Docker options for an app + +Docker options can be removed for a specific app using the `docker-options:clear` command. + +```shell +dokku docker-options:clear node-js-app +``` + +``` +-----> Clearing docker-options for node-js-app on all phases +``` + +One or more valid phases can also be specified. Phases are comma delimited, and specifying an invalid phase will result in an error. + +```shell +dokku docker-options:clear node-js-app run +``` + +``` +-----> Clearing docker-options for node-js-app on phase run +``` + +```shell +dokku docker-options:clear node-js-app build,run +``` + +``` +-----> Clearing docker-options for node-js-app on phase build +-----> Clearing docker-options for node-js-app on phase run +``` + ### Displaying docker-options reports for an app > New as of 0.8.1 diff --git a/plugins/docker-options/commands b/plugins/docker-options/commands index ea9b8b268..b29fbd6ef 100755 --- a/plugins/docker-options/commands +++ b/plugins/docker-options/commands @@ -8,6 +8,7 @@ docker_options_help_content_func() { cat < [phase(s)], [DEPRECATED] Alternative for docker-options:report docker-options:add OPTION, Add Docker option to app for phase (comma separated phase list) + docker-options:clear [phase(s)], Clear a docker options from application with an optional phase (comma separated phase list) docker-options:remove OPTION, Remove Docker option from app for phase (comma separated phase list) docker-options:report [] [], Displays a docker options report for one or more apps help_content diff --git a/plugins/docker-options/subcommands/clear b/plugins/docker-options/subcommands/clear new file mode 100755 index 000000000..6a6c6ae9f --- /dev/null +++ b/plugins/docker-options/subcommands/clear @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" + +cmd-docker-options-clear() { + declare desc="clear a docker options from application" + declare cmd="docker-options:clear" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare APP="$1" PHASES="$2" + + [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" + verify_app_name "$APP" + + if [[ -z "$PHASES" ]]; then + dokku_log_info1 "Clearing docker-options for $APP on all phases" + rm -f "$(fn-get-phase-file-path "$APP" "build")" "$(fn-get-phase-file-path "$APP" "deploy")" "$(fn-get-phase-file-path "$APP" "run")" + return + fi + + read -ra passed_phases <<<"$(get_phases "$PHASES")" + for phase in "${passed_phases[@]}"; do + dokku_log_info1 "Clearing docker-options for $APP on phase $phase" + rm -f "$(fn-get-phase-file-path "$APP" "$phase")" + done +} + +cmd-docker-options-clear "$@" diff --git a/tests/unit/20_docker-options.bats b/tests/unit/20_docker-options.bats index 1f568d0e6..76bc8c1d3 100644 --- a/tests/unit/20_docker-options.bats +++ b/tests/unit/20_docker-options.bats @@ -23,6 +23,51 @@ teardown() { assert_success } + +@test "(docker-options) docker-options:clear" { + run /bin/bash -c "dokku docker-options:add $TEST_APP build,deploy,run \"-v /tmp\"" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options:clear $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options $TEST_APP | egrep '\-v /tmp' | wc -l | grep -q 0" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku docker-options:add $TEST_APP build,deploy,run \"-v /tmp\"" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options:clear $TEST_APP build" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options $TEST_APP | egrep '\-v /tmp' | wc -l | grep -q 2" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options:clear $TEST_APP deploy" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options $TEST_APP | egrep '\-v /tmp' | wc -l | grep -q 1" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options:clear $TEST_APP run" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku docker-options $TEST_APP | egrep '\-v /tmp' | wc -l | grep -q 0" + echo "output: $output" + echo "status: $status" + assert_success +} + @test "(docker-options) docker-options:add (build phase)" { run /bin/bash -c "dokku docker-options:add $TEST_APP build \"-v /tmp\"" echo "output: $output"