From e163e18150537e5cdfd1e4f3418571294119db73 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2023 23:26:44 -0500 Subject: [PATCH] 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 cb57513..a05d650 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 mysql 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_MYSQL_LOLLIPOP_PORT_3306_TCP_ADDR=172.17.0.1 The following will be set on the linked application by default: ``` -DATABASE_URL=mysql://mysql:SOME_PASSWORD@dokku-mysql-lollipop:3306/lollipop +DATABASE_URL=mysql://lollipop:SOME_PASSWORD@dokku-mysql-lollipop:3306/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 mysql:link lollipop playground This will cause `DATABASE_URL` to be set as: ``` -mysql2://mysql:SOME_PASSWORD@dokku-mysql-lollipop:3306/lollipop +mysql2://lollipop:SOME_PASSWORD@dokku-mysql-lollipop:3306/lollipop +``` + +If you specify `MYSQL_DATABASE_SCHEME` to equal `http`, we`ll also automatically adjust `DATABASE_URL` to match the http interface: + +``` +http://lollipop:SOME_PASSWORD@dokku-mysql-lollipop:${PLUGIN_DATASTORE_PORTS[1]} ``` ### unlink the mysql service from the app @@ -252,6 +259,10 @@ mysql2://mysql:SOME_PASSWORD@dokku-mysql-lollipop:3306/lollipop dokku mysql:unlink ``` +flags: + +- `-n|--no-restart "false"`: whether or not to restart the app on unlink (default: true) + You can unlink a mysql 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 mysql 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 513b51b..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}://mysql:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]}/lollipop + #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://mysql:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lollipop:${PLUGIN_DATASTORE_PORTS[0]}/lollipop + #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"