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 25, 2023
1 parent dd1072b commit b8efde2
Showing 5 changed files with 26 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -188,6 +188,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 meilisearch 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.

@@ -233,13 +234,23 @@ This will cause `MEILISEARCH_URL` to be set as:
http2://lollipop:SOME_PASSWORD@dokku-meilisearch-lollipop:7700/lollipop
```

If you specify `MEILISEARCH_DATABASE_SCHEME` to equal `http`, we`ll also automatically adjust `MEILISEARCH_URL` to match the http interface:

```
http://lollipop:SOME_PASSWORD@dokku-meilisearch-lollipop:${PLUGIN_DATASTORE_PORTS[1]}
```

### unlink the meilisearch service from the app

```shell
# usage
dokku meilisearch:unlink <service> <app>
```

flags:

- `-n|--no-restart "false"`: whether or not to restart the app on unlink (default: true)

You can unlink a meilisearch service:

> NOTE: this will restart your app and unset related environment variables
@@ -426,7 +437,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 meilisearch docker container

10 changes: 7 additions & 3 deletions common-functions
Original file line number Diff line number Diff line change
@@ -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[@]}"
5 changes: 5 additions & 0 deletions subcommands/link
Original file line number Diff line number Diff line change
@@ -38,10 +38,15 @@ service-link-cmd() {
#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]}
#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
1 change: 1 addition & 0 deletions subcommands/unlink
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion subcommands/upgrade
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit b8efde2

Please sign in to comment.