From 3c6b6e1c0f8b4ac98564462762776258c36b078f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2023 23:26:44 -0500 Subject: [PATCH 01/11] feat: add ability to skip restarts on link and unlink Refs dokku/dokku-redis#192 --- README.md | 17 ++++++++++++++--- common-functions | 10 +++++++--- subcommands/link | 9 +++++++-- subcommands/unlink | 1 + subcommands/upgrade | 2 +- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8955f2a..61a0460 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,7 @@ flags: - `-a|--alias "BLUE_DATABASE"`: an alternative alias to use for linking to an app via environment variable - `-q|--querystring "pool=5"`: ampersand delimited querystring arguments to append to the service link +- `-n|--no-restart "false"`: whether or not to restart the app on link (default: true) A redis service can be linked to a container. This will use native docker links via the docker-options plugin. Here we link it to our `playground` app. @@ -223,7 +224,7 @@ DOKKU_REDIS_LOLLIPOP_PORT_6379_TCP_ADDR=172.17.0.1 The following will be set on the linked application by default: ``` -REDIS_URL=redis://:SOME_PASSWORD@dokku-redis-lollipop:6379 +REDIS_URL=redis://lollipop:SOME_PASSWORD@dokku-redis-lollipop:6379/lollipop ``` The host exposed here only works internally in docker containers. If you want your container to be reachable from outside, you should use the `expose` subcommand. Another service can be linked to your app: @@ -242,7 +243,13 @@ dokku redis:link lollipop playground This will cause `REDIS_URL` to be set as: ``` -redis2://:SOME_PASSWORD@dokku-redis-lollipop:6379 +redis2://lollipop:SOME_PASSWORD@dokku-redis-lollipop:6379/lollipop +``` + +If you specify `REDIS_DATABASE_SCHEME` to equal `http`, we`ll also automatically adjust `REDIS_URL` to match the http interface: + +``` +http://lollipop:SOME_PASSWORD@dokku-redis-lollipop:${PLUGIN_DATASTORE_PORTS[1]} ``` ### unlink the redis service from the app @@ -252,6 +259,10 @@ redis2://:SOME_PASSWORD@dokku-redis-lollipop:6379 dokku redis:unlink ``` +flags: + +- `-n|--no-restart "false"`: whether or not to restart the app on unlink (default: true) + You can unlink a redis service: > NOTE: this will restart your app and unset related environment variables @@ -453,7 +464,7 @@ flags: - `-I|--image-version IMAGE_VERSION`: the image version to start the service with - `-N|--initial-network INITIAL_NETWORK`: the initial network to attach the service to - `-P|--post-create-network NETWORKS`: a comman-separated list of networks to attach the service container to after service creation -- `-R|--restart-apps "true"`: whether to force an app restart +- `-R|--restart-apps "true"`: whether or not to force an app restart (default: false) - `-S|--post-start-network NETWORKS`: a comman-separated list of networks to attach the service container to after service start - `-s|--shm-size SHM_SIZE`: override shared memory size for redis docker container diff --git a/common-functions b/common-functions index 10a4677..17a6da4 100755 --- a/common-functions +++ b/common-functions @@ -631,7 +631,7 @@ service_link() { fi [[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}" plugn trigger service-action post-link "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "$APP" - if [[ "$DOKKU_GLOBAL_FLAGS" == *"--no-restart"* ]]; then + if [[ "$DOKKU_GLOBAL_FLAGS" == *"--no-restart"* ]] || [[ "$SERVICE_RESTART_APPS" == "false" ]]; then config_set --no-restart "$APP" "${ALIAS}_URL=$SERVICE_URL" else config_set "$APP" "${ALIAS}_URL=$SERVICE_URL" @@ -714,6 +714,7 @@ service_parse_args() { "--initial-network") set -- "$@" "-N" ;; "--image") set -- "$@" "-i" ;; "--memory") set -- "$@" "-m" ;; + "--no-restart") set -- "$@" "-n" ;; "--password") set -- "$@" "-p" ;; "--post-create-network") set -- "$@" "-P" ;; "--post-start-network") set -- "$@" "-S" ;; @@ -727,7 +728,7 @@ service_parse_args() { done OPTIND=1 - while getopts "a:c:C:d:i:I:m:n:N:p:P:q:R:r:s:S:u:" opt; do + while getopts "a:c:C:d:i:I:m:n:nN:p:P:q:R:r:s:S:u:" opt; do case "$opt" in a) SERVICE_ALIAS="${OPTARG^^}" @@ -751,6 +752,9 @@ service_parse_args() { m) export SERVICE_MEMORY=$OPTARG ;; + n) + export SERVICE_RESTART_APPS=false + ;; N) export SERVICE_INITIAL_NETWORK=$OPTARG ;; @@ -971,7 +975,7 @@ service_unlink() { [[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP" plugn trigger service-action post-unlink "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "$APP" - if [[ "$DOKKU_GLOBAL_FLAGS" == *"--no-restart"* ]]; then + if [[ "$DOKKU_GLOBAL_FLAGS" == *"--no-restart"* ]] || [[ "$SERVICE_RESTART_APPS" == "false" ]]; then config_unset --no-restart "$APP" "${LINK[@]}" else config_unset "$APP" "${LINK[@]}" diff --git a/subcommands/link b/subcommands/link index 8b971aa..f59f82a 100755 --- a/subcommands/link +++ b/subcommands/link @@ -23,7 +23,7 @@ service-link-cmd() { #E #E the following will be set on the linked application by default: #E - #E ${PLUGIN_DEFAULT_ALIAS}_URL=${PLUGIN_SCHEME}://:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]} + #E ${PLUGIN_DEFAULT_ALIAS}_URL=${PLUGIN_SCHEME}://lollipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]}/lollipop #E #E the host exposed here only works internally in docker containers. #E if you want your container to be reachable from outside, you should @@ -37,11 +37,16 @@ service-link-cmd() { #E dokku $PLUGIN_COMMAND_PREFIX:link lollipop playground #E this will cause ${PLUGIN_DEFAULT_ALIAS}_URL to be set as: #E - #E ${PLUGIN_SCHEME}2://:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]} + #E ${PLUGIN_SCHEME}2://lollipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]}/lollipop + #E + #E If you specify ${PLUGIN_VARIABLE}_DATABASE_SCHEME to equal `http`, we'll also automatically adjust ${PLUGIN_DEFAULT_ALIAS}_URL to match the http interface: + #E + #E http://lollipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[1]} #A service, service to run command against #A app, app to run command against #F -a|--alias "BLUE_DATABASE", an alternative alias to use for linking to an app via environment variable #F -q|--querystring "pool=5", ampersand delimited querystring arguments to append to the service link + #F -n|--no-restart "false", whether or not to restart the app on link (default: true) declare desc="link the $PLUGIN_SERVICE service to the app" local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@") [[ ${argv[0]} == "$cmd" ]] && shift 1 diff --git a/subcommands/unlink b/subcommands/unlink index 7819079..63c4c97 100755 --- a/subcommands/unlink +++ b/subcommands/unlink @@ -11,6 +11,7 @@ service-unlink-cmd() { #E dokku $PLUGIN_COMMAND_PREFIX:unlink lollipop playground #A service, service to run command against #A app, app to run command against + #F -n|--no-restart "false", whether or not to restart the app on unlink (default: true) declare desc="unlink the $PLUGIN_SERVICE service from the app" local cmd="$PLUGIN_COMMAND_PREFIX:unlink" argv=("$@") [[ ${argv[0]} == "$cmd" ]] && shift 1 diff --git a/subcommands/upgrade b/subcommands/upgrade index 898b268..93352c1 100755 --- a/subcommands/upgrade +++ b/subcommands/upgrade @@ -16,7 +16,7 @@ service-upgrade-cmd() { #F -I|--image-version IMAGE_VERSION, the image version to start the service with #F -N|--initial-network INITIAL_NETWORK, the initial network to attach the service to #F -P|--post-create-network NETWORKS, a comman-separated list of networks to attach the service container to after service creation - #F -R|--restart-apps "true", whether to force an app restart + #F -R|--restart-apps "true", whether or not to force an app restart (default: false) #F -S|--post-start-network NETWORKS, a comman-separated list of networks to attach the service container to after service start #F -s|--shm-size SHM_SIZE, override shared memory size for $PLUGIN_COMMAND_PREFIX docker container declare desc="upgrade service to the specified versions" From 673fc4c9bb469e7abff384a98d804ace717f6165 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2023 23:35:12 -0500 Subject: [PATCH 02/11] chore: make all the service names used in the service_link tests the same --- tests/service_link.bats | 60 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/service_link.bats b/tests/service_link.bats index 663718e..837b773 100755 --- a/tests/service_link.bats +++ b/tests/service_link.bats @@ -2,14 +2,14 @@ load test_helper setup() { - dokku "$PLUGIN_COMMAND_PREFIX:create" l - dokku "$PLUGIN_COMMAND_PREFIX:create" m + dokku "$PLUGIN_COMMAND_PREFIX:create" ls + dokku "$PLUGIN_COMMAND_PREFIX:create" ms dokku apps:create my-app } teardown() { - dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" m - dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" ms + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" ls dokku --force apps:destroy my-app } @@ -22,7 +22,7 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:link) error when the app argument is missing" { - run dokku "$PLUGIN_COMMAND_PREFIX:link" l + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls echo "output: $output" echo "status: $status" assert_contains "${lines[*]}" "Please specify an app to run the command on" @@ -30,7 +30,7 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:link) error when the app does not exist" { - run dokku "$PLUGIN_COMMAND_PREFIX:link" l not_existing_app + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls not_existing_app echo "output: $output" echo "status: $status" assert_contains "${lines[*]}" "App not_existing_app does not exist" @@ -46,73 +46,73 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:link) error when the service is already linked to app" { - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app - run dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app echo "output: $output" echo "status: $status" assert_contains "${lines[*]}" "Already linked as REDIS_URL" assert_failure - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } @test "($PLUGIN_COMMAND_PREFIX:link) exports REDIS_URL to app" { - run dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app echo "output: $output" echo "status: $status" url=$(dokku config:get my-app REDIS_URL) - password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" - assert_contains "$url" "redis://:$password@dokku-redis-l:6379" + password="$(sudo cat "$PLUGIN_DATA_ROOT/ls/PASSWORD")" + assert_contains "$url" "redis://:$password@dokku-redis-ls:6379" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } @test "($PLUGIN_COMMAND_PREFIX:link) generates an alternate config url when REDIS_URL already in use" { dokku config:set my-app REDIS_URL=redis://host:6379 - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app run dokku config my-app assert_contains "${lines[*]}" "DOKKU_REDIS_AQUA_URL" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:link" m my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ms my-app run dokku config my-app assert_contains "${lines[*]}" "DOKKU_REDIS_BLACK_URL" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:unlink" m my-app - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ms my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } @test "($PLUGIN_COMMAND_PREFIX:link) links to app with docker-options" { - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app run dokku docker-options:report my-app - assert_contains "${lines[*]}" "--link dokku.redis.l:dokku-redis-l" + assert_contains "${lines[*]}" "--link dokku.redis.ls:dokku-redis-ls" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } @test "($PLUGIN_COMMAND_PREFIX:link) uses apps REDIS_DATABASE_SCHEME variable" { dokku config:set my-app REDIS_DATABASE_SCHEME=redis2 - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app url=$(dokku config:get my-app REDIS_URL) - password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" - assert_contains "$url" "redis2://:$password@dokku-redis-l:6379" + password="$(sudo cat "$PLUGIN_DATA_ROOT/ls/PASSWORD")" + assert_contains "$url" "redis2://:$password@dokku-redis-ls:6379" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } @test "($PLUGIN_COMMAND_PREFIX:link) adds a querystring" { - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app --querystring "pool=5" + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --querystring "pool=5" url=$(dokku config:get my-app REDIS_URL) assert_contains "$url" "?pool=5" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } @test "($PLUGIN_COMMAND_PREFIX:link) uses a specified config url when alias is specified" { - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app --alias "ALIAS" + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --alias "ALIAS" url=$(dokku config:get my-app ALIAS_URL) - password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" - assert_contains "$url" "redis://:$password@dokku-redis-l:6379" + password="$(sudo cat "$PLUGIN_DATA_ROOT/ls/PASSWORD")" + assert_contains "$url" "redis://:$password@dokku-redis-ls:6379" assert_success - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } From ba0f46a8b5e200150e9638837478efe8041712ed Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2023 23:40:09 -0500 Subject: [PATCH 03/11] chore: make all the service names used in the service_unlink tests the same --- tests/service_unlink.bats | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/service_unlink.bats b/tests/service_unlink.bats index 1cb1da4..e709747 100755 --- a/tests/service_unlink.bats +++ b/tests/service_unlink.bats @@ -3,11 +3,11 @@ load test_helper setup() { dokku apps:create my-app - dokku "$PLUGIN_COMMAND_PREFIX:create" l + dokku "$PLUGIN_COMMAND_PREFIX:create" ls } teardown() { - dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" ls dokku --force apps:destroy my-app } @@ -17,12 +17,12 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:unlink) error when the app argument is missing" { - run dokku "$PLUGIN_COMMAND_PREFIX:unlink" l + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls assert_contains "${lines[*]}" "Please specify an app to run the command on" } @test "($PLUGIN_COMMAND_PREFIX:unlink) error when the app does not exist" { - run dokku "$PLUGIN_COMMAND_PREFIX:unlink" l not_existing_app + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls not_existing_app assert_contains "${lines[*]}" "App not_existing_app does not exist" } @@ -32,13 +32,13 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:unlink) error when service not linked to app" { - run dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app assert_contains "${lines[*]}" "Not linked to app my-app" } @test "($PLUGIN_COMMAND_PREFIX:unlink) removes link from docker-options" { - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app >&2 - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app >&2 + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app check_value="Docker options build: Docker options deploy: --restart=on-failure:10 Docker options run:" options=$(dokku --quiet docker-options:report my-app | xargs) @@ -46,8 +46,8 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:unlink) unsets config url from app" { - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app >&2 - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app >&2 + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app config=$(dokku config:get my-app REDIS_URL || true) assert_equal "$config" "" } From 6b39dea20e928fce00707aba862fe67c15327c3d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2023 23:47:03 -0500 Subject: [PATCH 04/11] tests: add test for --no-restart to unlink tests --- tests/service_unlink.bats | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/service_unlink.bats b/tests/service_unlink.bats index e709747..83fc6f8 100755 --- a/tests/service_unlink.bats +++ b/tests/service_unlink.bats @@ -51,3 +51,9 @@ teardown() { config=$(dokku config:get my-app REDIS_URL || true) assert_equal "$config" "" } + +@test "($PLUGIN_COMMAND_PREFIX:unlink) respects --no-restart" { + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app --no-restart + assert_output_contains "Restarting app my-app" 0 + assert_success +} From 577d73e7f06cb8dfed7559b843b0036fe6fb733d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2023 23:51:28 -0500 Subject: [PATCH 05/11] tests: add test for --no-restart to link tests --- tests/service_link.bats | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/service_link.bats b/tests/service_link.bats index 837b773..9c5675f 100755 --- a/tests/service_link.bats +++ b/tests/service_link.bats @@ -116,3 +116,19 @@ teardown() { assert_success dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } + +@test "($PLUGIN_COMMAND_PREFIX:unlink) respects --no-restart" { + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --no-restart + assert_output_contains "Restarting app my-app" 1 + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --no-restart + assert_output_contains "Restarting app my-app" 0 + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app + assert_success +} From 3cb6d2fe7bf91466d6bc85a3fe1fe8e6cc2b09a2 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Feb 2023 00:08:53 -0500 Subject: [PATCH 06/11] tests: add output/status and flesh out restart tests a bit more --- tests/service_link.bats | 10 +++++++++- tests/service_unlink.bats | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/service_link.bats b/tests/service_link.bats index 9c5675f..7d461aa 100755 --- a/tests/service_link.bats +++ b/tests/service_link.bats @@ -117,18 +117,26 @@ teardown() { dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } -@test "($PLUGIN_COMMAND_PREFIX:unlink) respects --no-restart" { +@test "($PLUGIN_COMMAND_PREFIX:link) respects --no-restart" { run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --no-restart + echo "output: $output" + echo "status: $status" assert_output_contains "Restarting app my-app" 1 assert_success run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app + echo "output: $output" + echo "status: $status" assert_success run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --no-restart + echo "output: $output" + echo "status: $status" assert_output_contains "Restarting app my-app" 0 assert_success run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app + echo "output: $output" + echo "status: $status" assert_success } diff --git a/tests/service_unlink.bats b/tests/service_unlink.bats index 83fc6f8..b16f61d 100755 --- a/tests/service_unlink.bats +++ b/tests/service_unlink.bats @@ -53,7 +53,20 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:unlink) respects --no-restart" { + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app + echo "output: $output" + echo "status: $status" + assert_output_contains "Restarting app my-app" 1 + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app + echo "output: $output" + echo "status: $status" + assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app --no-restart + echo "output: $output" + echo "status: $status" assert_output_contains "Restarting app my-app" 0 assert_success } From 3154beb12dfc4b84cd8fb3827cae72bfd217cb11 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Feb 2023 00:29:30 -0500 Subject: [PATCH 07/11] fix: move arg-less flags to the front --- common-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-functions b/common-functions index 17a6da4..7472f84 100755 --- a/common-functions +++ b/common-functions @@ -728,7 +728,7 @@ service_parse_args() { done OPTIND=1 - while getopts "a:c:C:d:i:I:m:n:nN:p:P:q:R:r:s:S:u:" opt; do + while getopts "na:c:C:d:i:I:m:n:N:p:P:q:R:r:s:S:u:" opt; do case "$opt" in a) SERVICE_ALIAS="${OPTARG^^}" From b3747635b20d7abfe081e8efb7cdbbb3a8b8cc06 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Feb 2023 00:48:23 -0500 Subject: [PATCH 08/11] fix: update tests to properly handle case where app is not running --- common-functions | 2 ++ tests/service_link.bats | 7 ++++--- tests/service_unlink.bats | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common-functions b/common-functions index 7472f84..0b3b952 100755 --- a/common-functions +++ b/common-functions @@ -633,6 +633,7 @@ service_link() { plugn trigger service-action post-link "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "$APP" if [[ "$DOKKU_GLOBAL_FLAGS" == *"--no-restart"* ]] || [[ "$SERVICE_RESTART_APPS" == "false" ]]; then config_set --no-restart "$APP" "${ALIAS}_URL=$SERVICE_URL" + dokku_log_verbose "Skipping restart of linked app" else config_set "$APP" "${ALIAS}_URL=$SERVICE_URL" fi @@ -977,6 +978,7 @@ service_unlink() { plugn trigger service-action post-unlink "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "$APP" if [[ "$DOKKU_GLOBAL_FLAGS" == *"--no-restart"* ]] || [[ "$SERVICE_RESTART_APPS" == "false" ]]; then config_unset --no-restart "$APP" "${LINK[@]}" + dokku_log_verbose "Skipping restart of linked app" else config_unset "$APP" "${LINK[@]}" fi diff --git a/tests/service_link.bats b/tests/service_link.bats index 7d461aa..d3985aa 100755 --- a/tests/service_link.bats +++ b/tests/service_link.bats @@ -117,11 +117,12 @@ teardown() { dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } + @test "($PLUGIN_COMMAND_PREFIX:link) respects --no-restart" { - run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --no-restart + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app echo "output: $output" echo "status: $status" - assert_output_contains "Restarting app my-app" 1 + assert_output_contains "Skipping restart of linked app" 0 assert_success run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app @@ -132,7 +133,7 @@ teardown() { run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app --no-restart echo "output: $output" echo "status: $status" - assert_output_contains "Restarting app my-app" 0 + assert_output_contains "Skipping restart of linked app" assert_success run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app diff --git a/tests/service_unlink.bats b/tests/service_unlink.bats index b16f61d..47ec081 100755 --- a/tests/service_unlink.bats +++ b/tests/service_unlink.bats @@ -56,7 +56,7 @@ teardown() { run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app echo "output: $output" echo "status: $status" - assert_output_contains "Restarting app my-app" 1 + assert_output_contains "Skipping restart of linked app" 0 assert_success run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app @@ -67,6 +67,6 @@ teardown() { run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app --no-restart echo "output: $output" echo "status: $status" - assert_output_contains "Restarting app my-app" 0 + assert_output_contains "Skipping restart of linked app" assert_success } From 5e78f7d1e59af45df2d0b7f8cf35801a1106ba81 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Feb 2023 00:49:18 -0500 Subject: [PATCH 09/11] chore: remove extra newline --- tests/service_link.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/service_link.bats b/tests/service_link.bats index d3985aa..90de706 100755 --- a/tests/service_link.bats +++ b/tests/service_link.bats @@ -117,7 +117,6 @@ teardown() { dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app } - @test "($PLUGIN_COMMAND_PREFIX:link) respects --no-restart" { run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app echo "output: $output" From dbaa985fe62f6bc1d69c326c6e173381c1963de7 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 25 Feb 2023 00:47:26 -0500 Subject: [PATCH 10/11] tests: link service before unlinking --- tests/service_unlink.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/service_unlink.bats b/tests/service_unlink.bats index 47ec081..2116980 100755 --- a/tests/service_unlink.bats +++ b/tests/service_unlink.bats @@ -53,6 +53,11 @@ teardown() { } @test "($PLUGIN_COMMAND_PREFIX:unlink) respects --no-restart" { + run dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app + echo "output: $output" + echo "status: $status" + assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app echo "output: $output" echo "status: $status" From a9021655470943f979117a9048fc227de846f91e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 25 Feb 2023 01:50:30 -0500 Subject: [PATCH 11/11] fix: update link docs to remove erroneous copy-paste --- README.md | 10 ++-------- subcommands/link | 8 ++------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 61a0460..bc87acc 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ DOKKU_REDIS_LOLLIPOP_PORT_6379_TCP_ADDR=172.17.0.1 The following will be set on the linked application by default: ``` -REDIS_URL=redis://lollipop:SOME_PASSWORD@dokku-redis-lollipop:6379/lollipop +REDIS_URL=redis://:SOME_PASSWORD@dokku-redis-lollipop:6379 ``` The host exposed here only works internally in docker containers. If you want your container to be reachable from outside, you should use the `expose` subcommand. Another service can be linked to your app: @@ -243,13 +243,7 @@ dokku redis:link lollipop playground This will cause `REDIS_URL` to be set as: ``` -redis2://lollipop:SOME_PASSWORD@dokku-redis-lollipop:6379/lollipop -``` - -If you specify `REDIS_DATABASE_SCHEME` to equal `http`, we`ll also automatically adjust `REDIS_URL` to match the http interface: - -``` -http://lollipop:SOME_PASSWORD@dokku-redis-lollipop:${PLUGIN_DATASTORE_PORTS[1]} +redis2://:SOME_PASSWORD@dokku-redis-lollipop:6379 ``` ### unlink the redis service from the app diff --git a/subcommands/link b/subcommands/link index f59f82a..661ce49 100755 --- a/subcommands/link +++ b/subcommands/link @@ -23,7 +23,7 @@ service-link-cmd() { #E #E the following will be set on the linked application by default: #E - #E ${PLUGIN_DEFAULT_ALIAS}_URL=${PLUGIN_SCHEME}://lollipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]}/lollipop + #E ${PLUGIN_DEFAULT_ALIAS}_URL=${PLUGIN_SCHEME}://:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]} #E #E the host exposed here only works internally in docker containers. #E if you want your container to be reachable from outside, you should @@ -37,11 +37,7 @@ service-link-cmd() { #E dokku $PLUGIN_COMMAND_PREFIX:link lollipop playground #E this will cause ${PLUGIN_DEFAULT_ALIAS}_URL to be set as: #E - #E ${PLUGIN_SCHEME}2://lollipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]}/lollipop - #E - #E If you specify ${PLUGIN_VARIABLE}_DATABASE_SCHEME to equal `http`, we'll also automatically adjust ${PLUGIN_DEFAULT_ALIAS}_URL to match the http interface: - #E - #E http://lollipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[1]} + #E ${PLUGIN_SCHEME}2://:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]} #A service, service to run command against #A app, app to run command against #F -a|--alias "BLUE_DATABASE", an alternative alias to use for linking to an app via environment variable