#!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" apps_create() { declare desc="verifies app name and creates an app" declare APP="$1" is_valid_app_name "$APP" [[ -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "Name is already taken" mkdir -p "$DOKKU_ROOT/$APP" dokku_log_info1_quiet "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 DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)" [[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}" if [[ -n $DOKKU_APP_CIDS ]]; then local cid for cid in $DOKKU_APP_CIDS; do # shellcheck disable=SC2086 docker stop $DOCKER_STOP_TIME_ARG "$cid" > /dev/null || true docker rm "$cid" > /dev/null || true done fi plugn trigger post-delete "$APP" "$IMAGE_TAG" } apps_exists() { declare desc="checks if an app exists" declare APP="$1" is_valid_app_name "$APP" [[ -d "$DOKKU_ROOT/$APP" ]] || dokku_log_fail "App does not exist" dokku_log_info1 "App already exists" } apps_maybe_create() { declare desc="creates an app dir if allowed" declare APP="$1" if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then DOKKU_GLOBAL_DISABLE_AUTOCREATE="$(config_get --global DOKKU_DISABLE_APP_AUTOCREATION || true)" if [[ "$DOKKU_GLOBAL_DISABLE_AUTOCREATE" == "true" ]]; then dokku_log_warn "App auto-creation disabled." dokku_log_fail " ! Re-enable app auto-creation or create an app with 'dokku apps:create ${APP}'" else suppress_output apps_create "$APP" fi fi }