feat: add ability to skip restarts on link and unlink

Refs dokku/dokku-redis#192
This commit is contained in:
Jose Diaz-Gonzalez
2023-02-20 23:26:44 -05:00
parent d68fee775d
commit ad22989894
5 changed files with 26 additions and 5 deletions

View File

@@ -206,6 +206,7 @@ flags:
- `-a|--alias "BLUE_DATABASE"`: an alternative alias to use for linking to an app via environment variable - `-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 - `-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 postgres 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. A postgres 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.
@@ -251,6 +252,12 @@ This will cause `DATABASE_URL` to be set as:
postgres2://lollipop:SOME_PASSWORD@dokku-postgres-lollipop:5432/lollipop postgres2://lollipop:SOME_PASSWORD@dokku-postgres-lollipop:5432/lollipop
``` ```
If you specify `POSTGRES_DATABASE_SCHEME` to equal `http`, we`ll also automatically adjust `DATABASE_URL` to match the http interface:
```
http://lollipop:SOME_PASSWORD@dokku-postgres-lollipop:${PLUGIN_DATASTORE_PORTS[1]}
```
### unlink the postgres service from the app ### unlink the postgres service from the app
```shell ```shell
@@ -258,6 +265,10 @@ postgres2://lollipop:SOME_PASSWORD@dokku-postgres-lollipop:5432/lollipop
dokku postgres:unlink <service> <app> dokku postgres:unlink <service> <app>
``` ```
flags:
- `-n|--no-restart "false"`: whether or not to restart the app on unlink (default: true)
You can unlink a postgres service: You can unlink a postgres service:
> NOTE: this will restart your app and unset related environment variables > NOTE: this will restart your app and unset related environment variables
@@ -459,7 +470,7 @@ flags:
- `-I|--image-version IMAGE_VERSION`: the image version to start the service with - `-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 - `-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 - `-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|--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 postgres docker container - `-s|--shm-size SHM_SIZE`: override shared memory size for postgres docker container

View File

@@ -631,7 +631,7 @@ service_link() {
fi fi
[[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}" [[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}"
plugn trigger service-action post-link "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "$APP" 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" config_set --no-restart "$APP" "${ALIAS}_URL=$SERVICE_URL"
else else
config_set "$APP" "${ALIAS}_URL=$SERVICE_URL" config_set "$APP" "${ALIAS}_URL=$SERVICE_URL"
@@ -714,6 +714,7 @@ service_parse_args() {
"--initial-network") set -- "$@" "-N" ;; "--initial-network") set -- "$@" "-N" ;;
"--image") set -- "$@" "-i" ;; "--image") set -- "$@" "-i" ;;
"--memory") set -- "$@" "-m" ;; "--memory") set -- "$@" "-m" ;;
"--no-restart") set -- "$@" "-n" ;;
"--password") set -- "$@" "-p" ;; "--password") set -- "$@" "-p" ;;
"--post-create-network") set -- "$@" "-P" ;; "--post-create-network") set -- "$@" "-P" ;;
"--post-start-network") set -- "$@" "-S" ;; "--post-start-network") set -- "$@" "-S" ;;
@@ -727,7 +728,7 @@ service_parse_args() {
done done
OPTIND=1 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 case "$opt" in
a) a)
SERVICE_ALIAS="${OPTARG^^}" SERVICE_ALIAS="${OPTARG^^}"
@@ -751,6 +752,9 @@ service_parse_args() {
m) m)
export SERVICE_MEMORY=$OPTARG export SERVICE_MEMORY=$OPTARG
;; ;;
n)
export SERVICE_RESTART_APPS=false
;;
N) N)
export SERVICE_INITIAL_NETWORK=$OPTARG export SERVICE_INITIAL_NETWORK=$OPTARG
;; ;;
@@ -971,7 +975,7 @@ service_unlink() {
[[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP" [[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP"
plugn trigger service-action post-unlink "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "$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[@]}" config_unset --no-restart "$APP" "${LINK[@]}"
else else
config_unset "$APP" "${LINK[@]}" config_unset "$APP" "${LINK[@]}"

View File

@@ -38,10 +38,15 @@ service-link-cmd() {
#E this will cause ${PLUGIN_DEFAULT_ALIAS}_URL to be set as: #E this will cause ${PLUGIN_DEFAULT_ALIAS}_URL to be set as:
#E #E
#E ${PLUGIN_SCHEME}2://lollipop: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 service, service to run command against
#A app, app 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 -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 -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" declare desc="link the $PLUGIN_SERVICE service to the app"
local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@") local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@")
[[ ${argv[0]} == "$cmd" ]] && shift 1 [[ ${argv[0]} == "$cmd" ]] && shift 1

View File

@@ -11,6 +11,7 @@ service-unlink-cmd() {
#E dokku $PLUGIN_COMMAND_PREFIX:unlink lollipop playground #E dokku $PLUGIN_COMMAND_PREFIX:unlink lollipop playground
#A service, service to run command against #A service, service to run command against
#A app, app 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" declare desc="unlink the $PLUGIN_SERVICE service from the app"
local cmd="$PLUGIN_COMMAND_PREFIX:unlink" argv=("$@") local cmd="$PLUGIN_COMMAND_PREFIX:unlink" argv=("$@")
[[ ${argv[0]} == "$cmd" ]] && shift 1 [[ ${argv[0]} == "$cmd" ]] && shift 1

View File

@@ -16,7 +16,7 @@ service-upgrade-cmd() {
#F -I|--image-version IMAGE_VERSION, the image version to start the service with #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 -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 -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|--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 #F -s|--shm-size SHM_SIZE, override shared memory size for $PLUGIN_COMMAND_PREFIX docker container
declare desc="upgrade service <service> to the specified versions" declare desc="upgrade service <service> to the specified versions"