Skip to content

Commit

Permalink
feat: add ability to skip restarts on link and unlink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Diaz-Gonzalez committed Feb 21, 2023
1 parent deabe36 commit e163e18
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -252,6 +259,10 @@ mysql2://mysql:SOME_PASSWORD@dokku-mysql-lollipop:3306/lollipop
dokku mysql:unlink <service> <app>
```

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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" ;;
Expand All @@ -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^^}"
Expand All @@ -751,6 +752,9 @@ service_parse_args() {
m)
export SERVICE_MEMORY=$OPTARG
;;
n)
export SERVICE_RESTART_APPS=false
;;
N)
export SERVICE_INITIAL_NETWORK=$OPTARG
;;
Expand Down Expand Up @@ -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[@]}"
Expand Down
9 changes: 7 additions & 2 deletions subcommands/link
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions subcommands/unlink
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion subcommands/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -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 <service> to the specified versions"
Expand Down

0 comments on commit e163e18

Please sign in to comment.