-
Notifications
You must be signed in to change notification settings - Fork 9
/
functions
executable file
·66 lines (54 loc) · 1.91 KB
/
functions
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
clone_main_cmd() {
declare desc="creates/updates app from remote git repo"
declare APP="$2" GITURL="$3" TAGNAME="${4:-master}"
local cmd="$1"
local APP_PATH=$DOKKU_ROOT/$APP
local PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
[[ -z $3 ]] && dokku_log_fail "Please specify an app name and git url ie. dokku clone <app> <giturl>"
[[ -d "$DOKKU_ROOT/$APP" ]] || dokku apps:create "$APP"
if [[ ! -d "$DOKKU_ROOT/$APP/.clone" ]]; then
cd "$DOKKU_ROOT/$APP"
if [[ -z $TAGNAME ]]; then
dokku_log_info1 "Creating $APP from $GITURL..."
git clone "$GITURL" .clone
else
dokku_log_info1 "Creating $APP from $GITURL $TAGNAME"
git clone -n -qq "$GITURL" .clone
cd .clone
git checkout -qq "$TAGNAME"
cd ..
fi
rsync -a "$DOKKU_ROOT/$APP/.clone/.git/" ./
rm -rf "$DOKKU_ROOT/$APP/.clone"
git config --bool core.bare true
cat > "$PRERECEIVE_HOOK" <<EOF
#!/usr/bin/env bash
set -e; set -o pipefail;
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook $APP
EOF
chmod +x "$PRERECEIVE_HOOK"
ps_rebuild "$APP"
fi
}
clone_key_cmd() {
declare desc="outputs the dokku public deploy key"
declare APP="$2" GITURL="$3"
local cmd="$1"
if [[ ! -f "$DOKKU_ROOT/.ssh/id_rsa.pub" ]]; then
dokku_log_fail "There is no deploy key, please re-install the clone plugin"
fi
cat "$DOKKU_ROOT/.ssh/id_rsa.pub"
}
clone_allow_cmd() {
declare desc="adds a domain to known_hosts"
declare DOMAIN="$2"
local cmd="$1"
[[ -z $2 ]] && dokku_log_fail "Please supply a git domain ie 'dokku clone:allow github.com'"
ssh-keyscan -t rsa "$DOMAIN" >> "$DOKKU_ROOT/.ssh/known_hosts"
dokku_log_info1 "$DOMAIN added to known hosts"
}