Merge pull request #98 from dokku/linked-existence
feat: implement exists and linked subcommands
This commit is contained in:
@@ -29,11 +29,13 @@ redis:connect <name> Connect via redis-cli to a redis service
|
||||
redis:create <name> Create a redis service with environment variables
|
||||
redis:destroy <name> Delete the service, delete the data and stop its container if there are no links left
|
||||
redis:enter <name> [command] Enter or run a command in a running redis service container
|
||||
redis:exists <service> Check if the redis service exists
|
||||
redis:export <name> > <file> Export a dump of the redis service database
|
||||
redis:expose <name> [port] Expose a redis service on custom port if provided (random port otherwise)
|
||||
redis:import <name> <file> Import a dump into the redis service database
|
||||
redis:info <name> Print the connection information
|
||||
redis:link <name> <app> Link the redis service to the app
|
||||
redis:linked <name> <app> Check if the redis service is linked to an app
|
||||
redis:list List all redis services
|
||||
redis:logs <name> [-t] Print the most recent log(s) for this service
|
||||
redis:promote <name> <app> Promote service <name> as REDIS_URL in <app>
|
||||
|
||||
@@ -289,6 +289,20 @@ service_info() {
|
||||
fi
|
||||
}
|
||||
|
||||
service_is_linked() {
|
||||
declare desc="Links a service to an application"
|
||||
declare SERVICE="$1" APP="$2"
|
||||
update_plugin_scheme_for_app "$APP"
|
||||
local SERVICE_URL=$(service_url "$SERVICE")
|
||||
local EXISTING_CONFIG=$(config_all "$APP")
|
||||
local LINK=$(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1) || true
|
||||
if [[ -z $LINK ]]; then
|
||||
dokku_log_warn "Service $SERVICE is not linked to $APP"
|
||||
exit 1
|
||||
fi
|
||||
dokku_log_info1 "Service $SERVICE is linked to $APP"
|
||||
}
|
||||
|
||||
service_link() {
|
||||
declare desc="Links a service to an application"
|
||||
declare SERVICE="$1" APP="$2"
|
||||
|
||||
20
subcommands/exists
Executable file
20
subcommands/exists
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_BASE_PATH/common/functions"
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||
|
||||
service-exists-cmd() {
|
||||
#E here we check if the lolipop $PLUGIN_COMMAND_PREFIX service exists.
|
||||
#E dokku $PLUGIN_COMMAND_PREFIX:exists lolipop
|
||||
#A service, service to run command against
|
||||
declare desc="check if the $PLUGIN_SERVICE service exists"
|
||||
local cmd="$PLUGIN_COMMAND_PREFIX:exists" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
||||
declare SERVICE="$1"
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
||||
verify_service_name "$SERVICE"
|
||||
dokku_log_info1 "Service $SERVICE exists"
|
||||
}
|
||||
|
||||
service-exists-cmd "$@"
|
||||
24
subcommands/linked
Executable file
24
subcommands/linked
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_BASE_PATH/common/functions"
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||
|
||||
service-linked-cmd() {
|
||||
#E here we check if the lolipop $PLUGIN_COMMAND_PREFIX service is linked to the 'playground' app.
|
||||
#E dokku $PLUGIN_COMMAND_PREFIX:linked lolipop playground
|
||||
#A service, service to run command against
|
||||
#A app, app to run command against
|
||||
declare desc="check if the $PLUGIN_SERVICE service is linked to an app"
|
||||
local cmd="$PLUGIN_COMMAND_PREFIX:linked" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
||||
declare SERVICE="$1" APP="$2"
|
||||
APP=${APP:="$DOKKU_APP_NAME"}
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
||||
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
verify_app_name "$APP"
|
||||
verify_service_name "$SERVICE"
|
||||
service_is_linked "$SERVICE" "$APP"
|
||||
}
|
||||
|
||||
service-linked-cmd "$@"
|
||||
Reference in New Issue
Block a user