Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 4b94330

Browse files
committed
Create an apps core plugin.
This creates the following commands: - apps - apps:create <app> - apps:destroy <app> It also: - makes `delete` an alias for `apps:destroy` - adds confirmation to `apps:destroy` - allows a developer to remove apps that have been created via apps:create but have not been deployed Refs dokku-alt#87 Refs #543 Refs #586 Closes #599 Refs #655 Refs #656 Refs #685 Closes #757
1 parent f03c0c5 commit 4b94330

6 files changed

Lines changed: 89 additions & 36 deletions

File tree

plugins/00_dokku-standard/commands

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
#!/usr/bin/env bash
22
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
34
case "$1" in
45
delete)
5-
if [[ -z $2 ]]; then
6-
echo "Please specify an app to delete"
7-
exit 1
8-
fi
9-
APP="$2"; IMAGE="dokku/$APP";
10-
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
11-
echo "App does not exist"
12-
exit 1
13-
fi
14-
15-
pluginhook pre-delete $APP
16-
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
17-
ID=$(< "$DOKKU_ROOT/$APP/CONTAINER")
18-
19-
docker stop $ID > /dev/null || true
20-
docker rm $ID > /dev/null || true
21-
fi
22-
23-
docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null &
24-
25-
pluginhook post-delete $APP
6+
dokku apps:destroy $2
267
;;
278

289
logs)
@@ -85,7 +66,6 @@ case "$1" in
8566

8667
help)
8768
cat && cat<<EOF
88-
delete <app> Delete an application
8969
logs <app> [-t] Show the last logs for an application (-t follows)
9070
run <app> <cmd> Run a command in the environment of an application
9171
url <app> Show the URL for an application

plugins/00_dokku-standard/pre-delete

Lines changed: 0 additions & 8 deletions
This file was deleted.

plugins/apps/commands

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
4+
case "$1" in
5+
apps)
6+
echo "=== My Apps"
7+
find $DOKKU_ROOT -maxdepth 1 -type d \( ! -iname ".*" \) | sed 's|^\./||g' | sed 's|'$DOKKU_ROOT'\/||' | tail -n +2
8+
;;
9+
10+
apps:create)
11+
if [[ -z $2 ]]; then
12+
echo "Please specify an app to create"
13+
exit 1
14+
fi
15+
APP="$2"
16+
if [[ -d "$DOKKU_ROOT/$APP" ]]; then
17+
echo " ! Name is already taken"
18+
exit 1
19+
fi
20+
21+
mkdir -p "$DOKKU_ROOT/$APP"
22+
echo "Creating $APP... done"
23+
;;
24+
25+
apps:destroy)
26+
if [[ -z $2 ]]; then
27+
echo "Please specify an app to delete"
28+
exit 1
29+
fi
30+
APP="$2"; IMAGE="dokku/$APP";
31+
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
32+
echo "App $APP does not exist"
33+
exit 1
34+
fi
35+
36+
echo " ! WARNING: Potentially Destructive Action"
37+
echo " ! This command will destroy $APP (including all add-ons)."
38+
echo " ! To proceed, type \"$APP\""
39+
echo ""
40+
41+
read -p "> " app_name
42+
if [[ "$app_name" != "$APP" ]]; then
43+
echo " ! Confirmation did not match $APP. Aborted."
44+
exit 1
45+
fi
46+
47+
echo "Destroying $APP (including all add-ons)"
48+
49+
pluginhook pre-delete $APP
50+
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
51+
ID=$(< "$DOKKU_ROOT/$APP/CONTAINER")
52+
53+
docker stop $ID > /dev/null || true
54+
docker rm $ID > /dev/null || true
55+
fi
56+
57+
docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null &
58+
59+
pluginhook post-delete $APP
60+
;;
61+
62+
help)
63+
cat && cat<<EOF
64+
apps List your apps
65+
apps:create <app> Create a new app
66+
apps:destroy <app> Permanently destroy an app
67+
EOF
68+
;;
69+
70+
esac
71+
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env bash
22
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
34
[[ -n $1 ]] && rm -r "$DOKKU_ROOT/$1" > /dev/null

plugins/apps/pre-delete

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
4+
APP="$1"; IMAGE="dokku/$APP"; CACHE_DIR="$DOKKU_ROOT/$APP/cache"
5+
if [[ -d $CACHE_DIR ]]; then
6+
docker run -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \;
7+
fi

plugins/config/commands

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ config_styled_hash () {
5353
config_restart_app() {
5454
APP="$1";
5555

56-
echo "-----> Releasing $APP ..."
57-
dokku release $APP
58-
echo "-----> Release complete!"
59-
echo "-----> Deploying $APP ..."
60-
dokku deploy $APP
61-
echo "-----> Deploy complete!"
56+
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
57+
echo "-----> Releasing $APP ..."
58+
dokku release $APP
59+
echo "-----> Release complete!"
60+
echo "-----> Deploying $APP ..."
61+
dokku deploy $APP
62+
echo "-----> Deploy complete!"
63+
fi
6264
}
6365

6466
config_write() {

0 commit comments

Comments
 (0)