Files
dokku/plugins/apps/commands
2015-02-06 08:28:14 -08:00

68 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
case "$1" in
apps)
dokku_log_info2_quiet "My Apps"
find $DOKKU_ROOT -follow -maxdepth 1 -type d \( ! -iname ".*" \) -not -path $DOKKU_ROOT/tls | sed 's|^\./||g' | sed 's|'$DOKKU_ROOT'\/||' | tail -n +2 | sort
;;
apps:create)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ -d "$DOKKU_ROOT/$2" ]] && dokku_log_warn "Name is already taken" && exit 1
APP="$2"
mkdir -p "$DOKKU_ROOT/$APP"
echo "Creating $APP... done"
;;
apps:destroy)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
[[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1
APP="$2"; IMAGE="dokku/$APP"
[[ "$3" == "force" ]] && DOKKU_APPS_FORCE_DELETE=1
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 -p "> " app_name
if [[ "$app_name" != "$APP" ]]; then
dokku_log_warn "Confirmation did not match $APP. Aborted."
exit 1
fi
fi
echo "Destroying $APP (including all add-ons)"
pluginhook pre-delete $APP
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
ID=$(< "$DOKKU_ROOT/$APP/CONTAINER")
docker stop $ID > /dev/null || true
docker rm $ID > /dev/null || true
fi
docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null &
pluginhook post-delete $APP
;;
help | apps:help)
cat && cat<<EOF
apps List your apps
apps:create <app> Create a new app
apps:destroy <app> Permanently destroy an app
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac