Files
dokku/plugins/apps/functions
2016-03-03 22:11:35 -08:00

48 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
apps_create() {
local desc="verifies app name and creates an app"
[[ -z $1 ]] && dokku_log_fail "Please specify an app to run the command on"
[[ ! "$1" =~ ^[a-z].* && ! "$1" =~ ^[0-9].* ]] && dokku_log_fail "App name must begin with lowercase alphanumeric character"
[[ -d "$DOKKU_ROOT/$1" ]] && dokku_log_fail "Name is already taken"
local APP="$1"
mkdir -p "$DOKKU_ROOT/$APP"
echo "Creating $APP... done"
plugn trigger post-create "$APP"
}
apps_destroy() {
local APP="$1"; local IMAGE_TAG=$(get_running_image_tag "$APP")
verify_app_name "$APP"
if [[ -z "$DOKKU_APPS_FORCE_DELETE" ]]; then
dokku_log_warn "WARNING: Potentially Destructive Action"
dokku_log_warn "This command will destroy $APP (including all add-ons)."
dokku_log_warn "To proceed, type \"$APP\""
echo ""
read -rp "> " app_name
if [[ "$app_name" != "$APP" ]]; then
dokku_log_fail "Confirmation did not match $APP. Aborted."
fi
fi
echo "Destroying $APP (including all add-ons)"
plugn trigger pre-delete "$APP" "$IMAGE_TAG"
local DOKKU_APP_CIDS=$(get_app_container_ids "$APP")
local cid
if [[ -n $DOKKU_APP_CIDS ]]; then
for cid in $DOKKU_APP_CIDS; do
docker stop "$cid" > /dev/null || true
docker rm "$cid" > /dev/null || true
done
fi
plugn trigger post-delete "$APP" "$IMAGE_TAG"
}