forked from crisward/dokku-require
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions
More file actions
executable file
·100 lines (86 loc) · 3.55 KB
/
functions
File metadata and controls
executable file
·100 lines (86 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
DOKKU_REQUIRE_PREFIX="${DOKKU_REQUIRE_PREFIX:-dokku}"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
require_get_app_plugins(){
local JSON_NODE=$1
cat | python -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj'"${JSON_NODE}"').strip("\"")';
}
require_get_json_len(){
local JSON_NODE=$1
cat | python -c 'import json,sys;obj=json.load(sys.stdin);print len(obj'"${JSON_NODE}"')';
}
require_install_link() {
declare desc="installs and links plugin passed in"
declare APP="$1" PLUGIN="$2"
if [[ -d "$PLUGIN_AVAILABLE_PATH/$PLUGIN/" ]]; then
if ! dokku "$PLUGIN:exists" "$APP" > /dev/null 2>&1; then
dokku_log_info1 "Setting up $PLUGIN"
dokku "$PLUGIN:create" "$APP"
fi
if ! dokku "$PLUGIN:linked" "$APP" "$APP" > /dev/null 2>&1; then
DOKKU_CONFIG_RESTART=false dokku "$PLUGIN:link" "$APP" "$APP"
fi
else
dokku_log_info1 "$PLUGIN plugin is not available on your system - attempting to contine without $PLUGIN"
fi
}
require_install_commands() {
declare desc="runs commands passed in from plugin list"
declare APP="$1" INDEX="$2"
local COMMAND COUNT PLUGIN TOTAL
COUNT=0
PLUGIN=$(require_get_app_plugins "[\"$DOKKU_REQUIRE_PREFIX\"][\"plugins\"][${INDEX}][\"name\"]" < "$APP_JSON_FILE" 2>&1)
if [[ -d "$PLUGIN_AVAILABLE_PATH/$PLUGIN/" ]]; then
TOTAL=$(require_get_json_len "[\"$DOKKU_REQUIRE_PREFIX\"][\"plugins\"][${INDEX}][\"commands\"]" < "$APP_JSON_FILE" 2>&1)
while [[ "$COUNT" -lt "$TOTAL" ]]; do
COMMAND=$(require_get_app_plugins "[\"$DOKKU_REQUIRE_PREFIX\"][\"plugins\"][${INDEX}][\"commands\"][${COUNT}]" < "$APP_JSON_FILE" 2>&1)
if [[ $? -ne 0 ]]; then
break
fi
COMMAND="${COMMAND//\$APP/$APP}"
# shellcheck disable=SC2086
DOKKU_CONFIG_RESTART=false dokku $COMMAND || break
let COUNT=COUNT+1
done
else
dokku_log_info1 "$PLUGIN plugin is not available on your system - attempting to contine without $PLUGIN"
fi
}
require_add_volumes() {
declare desc="adds volumes from app.json file"
declare APP="$1"
local APPPATH COUNT HOSTPATH TOTAL
COUNT=0
if TOTAL=$(require_get_json_len "[\"$DOKKU_REQUIRE_PREFIX\"][\"volumes\"]" < "$APP_JSON_FILE" 2>&1); then
dokku_log_info1 "Setting up $TOTAL volumes from app.json"
while [[ "$COUNT" -lt "$TOTAL" ]]; do
HOSTPATH=$(require_get_app_plugins "[\"$DOKKU_REQUIRE_PREFIX\"][\"volumes\"][${COUNT}][\"host\"]" < "$APP_JSON_FILE" 2>&1)
APPPATH=$(require_get_app_plugins "[\"$DOKKU_REQUIRE_PREFIX\"][\"volumes\"][${COUNT}][\"app\"]" < "$APP_JSON_FILE" 2>&1)
# "phases" key is optional
set +eo pipefail
PHASES=$(require_get_app_plugins "[\"$DOKKU_REQUIRE_PREFIX\"][\"volumes\"][${COUNT}][\"phases\"]" < "$APP_JSON_FILE" 2>&1)
set -eo pipefail
if [[ -z "$PHASES" ]]; then
PHASES="build,deploy,run"
fi
if [[ $? -ne 0 ]] || [[ -z "$HOSTPATH" ]] || [[ -z "$APPPATH" ]]; then
break
fi
# swap $APP for app name in commands
HOSTPATH="${HOSTPATH//\$APP/$APP}"
APPPATH="${APPPATH//\$APP/$APP}"
mkdir -p "$HOSTPATH"
dokku docker-options:add "$APP" "$PHASES" -v "$HOSTPATH:$APPPATH"
let COUNT=COUNT+1
done
fi
}
require_mode_cmd() {
declare desc="sets DOKKU_REQUIRE_PREFIX"
declare MODE="$2"
local cmd="mode"
[[ -d $DOKKU_ROOT/.dokkurc ]] || mkdir -p "$DOKKU_ROOT/.dokkurc"
echo "Setting DOKKU_REQUIRE_PREFIX to $MODE"
echo "export DOKKU_REQUIRE_PREFIX=$MODE" > "$DOKKU_ROOT/.dokkurc/DOKKU_REQUIRE_PREFIX"
}