forked from dokku-alt/dokku-alt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands
More file actions
executable file
·130 lines (112 loc) · 3.45 KB
/
Copy pathcommands
File metadata and controls
executable file
·130 lines (112 loc) · 3.45 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
source "$(dirname $0)/../dokku_common"
create_pre_receive_hook() {
PRERECEIVE_HOOK="$2/hooks/pre-receive"
cat > "$PRERECEIVE_HOOK" <<EOF
#!/usr/bin/env bash
set -e; set -o pipefail;
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook "$1"
EOF
chmod +x "$PRERECEIVE_HOOK"
}
create_bare_repository() {
git init --bare "$2" > /dev/null
create_pre_receive_hook "$@"
}
case "$1" in
git-hook)
verify_app_name "$2"
# if we got here we have full access
export NAME="dokku"
export FINGERPRINT=""
while read oldrev newrev refname
do
# Only run this script for the master branch. You can remove this
# if block if you wish to run it for others as well.
if [[ $refname = "refs/heads/master" ]] ; then
dokku rebuild "$APP" "$newrev"
else
echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master."
echo $'\e[1G\e[K'"-----> for example, try 'git push <dokku> ${refname/refs\/heads\/}:master'"
fi
done
;;
git-upload-pack)
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
pluginhook git-pre-pull $APP
cat | git-upload-pack "$DOKKU_ROOT/$APP"
pluginhook git-post-pull $APP
;;
git-*)
APP="$(echo "$2" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
check_app_name "$APP"
if [[ $1 == "git-receive-pack" && ! -d "$APP_DIR/refs" ]]; then
[[ "$DOKKU_DISABLE_AUTO_APP_CREATE" == "1" ]] && fail "$APP: application doesn't exit, please create it with: dokku create $APP"
create_bare_repository "$APP" "$APP_DIR"
fi
verify_app_name "$APP"
args=$@
git-shell -c "$args"
;;
create|apps:create)
check_app_name "$2"
verify_max_args 2 "$@"
[[ -d "$APP_DIR/refs" ]] && fail "$APP: already exist"
create_bare_repository "$APP" "$APP_DIR"
info "Application $APP created!"
;;
clone)
cleanup_clone() {
dokku delete "$APP"
}
check_app_name "$2"
verify_max_args 4 "$@"
[[ -d "$APP_DIR/refs" ]] && fail "$APP: already exist"
info "Cloning $APP repository from $3..."
git clone --bare -b "${4:-master}" "$3" "$APP_DIR"
cd "$APP_DIR"
HEAD="$(git rev-parse "${4:-master}")"
trap cleanup_clone EXIT
create_pre_receive_hook "$APP" "$APP_DIR"
dokku rebuild "$APP" "$HEAD"
echo "$HEAD" > "refs/heads/master"
trap - EXIT
;;
import:docker)
cleanup() {
dokku delete "$APP"
[[ -n "$TMP_WORK_DIR" ]] && rm -rf "$TMP_WORK_DIR"
}
check_app_name "$2"
verify_max_args 3 "$@"
dokku create "$2"
trap cleanup EXIT
TMP_WORK_DIR="$(mktemp -d)"
echo "$3"
# clone git repository
chmod 755 "$TMP_WORK_DIR"
unset GIT_DIR GIT_WORK_TREE
pushd "$TMP_WORK_DIR" > /dev/null
git clone "$APP_DIR" "$TMP_WORK_DIR" > /dev/null
git config advice.detachedHead false
git config user.email "$(id -u -n)@$(hostname)"
git config user.name "$(id -u -n)"
cat <<EOF > Dockerfile
FROM $3
EOF
git add Dockerfile
git commit -am "Created application with Docker FROM $3"
git push origin master
trap - EXIT
;;
help | git:help)
cat && cat <<EOF
create <app> Create shallow app
clone <app> <repository> [branch] Create application by cloning git repository
import:docker <app> <docker-image-from> Create application from Docker image
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac