-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
dokku-deploy
executable file
·105 lines (89 loc) · 3.02 KB
/
dokku-deploy
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
#!/bin/sh -l
set -e
if [ -n "$TRACE" ]; then
set -x
fi
if [ -n "$PLUGIN_BRANCH" ]; then
export BRANCH="$PLUGIN_BRANCH"
fi
if [ -n "$PLUGIN_COMMAND" ]; then
export COMMAND="$PLUGIN_COMMAND"
fi
if [ -n "$PLUGIN_GIT_REMOTE_URL" ]; then
export GIT_REMOTE_URL="$PLUGIN_GIT_REMOTE_URL"
fi
if [ -n "$PLUGIN_GIT_PUSH_FLAGS" ]; then
export GIT_PUSH_FLAGS="$PLUGIN_GIT_PUSH_FLAGS"
fi
if [ -n "$PLUGIN_DEPLOY_DOCKER_IMAGE" ]; then
export DEPLOY_DOCKER_IMAGE="$PLUGIN_DEPLOY_DOCKER_IMAGE"
fi
if [ -n "$PLUGIN_DEPLOY_USER_EMAIL" ]; then
export DEPLOY_USER_EMAIL="$PLUGIN_DEPLOY_USER_EMAIL"
fi
if [ -n "$PLUGIN_DEPLOY_USER_NAME" ]; then
export DEPLOY_USER_NAME="$PLUGIN_DEPLOY_USER_NAME"
fi
if [ -n "$PLUGIN_REVIEW_APP_NAME" ]; then
export REVIEW_APP_NAME="$PLUGIN_REVIEW_APP_NAME"
fi
if [ -z "$BRANCH" ]; then
BRANCH="master"
fi
setup-ssh
commit_sha="$(parse-ci-commit)"
app_name="$(parse-app-name)"
ssh_remote="ssh://dokku@$(parse-ssh-host):$(parse-ssh-port)"
if [ "$COMMAND" = "review-apps:create" ] || [ "$COMMAND" = 'review-apps:destroy' ]; then
if [ -z "$REVIEW_APP_NAME" ]; then
CI_BRANCH_NAME="$(parse-ci-branch-name)"
if [ -z "$CI_BRANCH_NAME" ]; then
log-error "Unable to detect branch name and cannot generate review app name"
exit 1
fi
REVIEW_APP_NAME="review-${app_name}-${CI_BRANCH_NAME}"
log-info "No review app name specified, using $REVIEW_APP_NAME"
fi
fi
if [ "$COMMAND" = "review-apps:destroy" ]; then
log-info "Destroying review app '${REVIEW_APP_NAME}'"
ssh "$ssh_remote" -- --force apps:destroy "$REVIEW_APP_NAME"
exit 0
fi
if [ -n "$COMMAND" ] && [ "$COMMAND" != "review-apps:create" ] && [ "$COMMAND" != "deploy" ]; then
log-error "Invalid command specified"
exit 1
fi
if [ -z "$commit_sha" ]; then
log-error "Unable to detect commit sha"
exit 1
fi
if [ "$COMMAND" = "review-apps:create" ]; then
log-info "Ensuring review app '${REVIEW_APP_NAME}' exists"
ssh "$ssh_remote" -- apps:clone --skip-deploy --ignore-existing "$app_name" "$REVIEW_APP_NAME"
fi
is_review_app="false"
remote_app_name="$app_name"
if [ -n "$REVIEW_APP_NAME" ] && [ "$app_name" != "$REVIEW_APP_NAME" ]; then
is_review_app="true"
remote_app_name="$REVIEW_APP_NAME"
GIT_REMOTE_URL="${GIT_REMOTE_URL%"/$app_name"}/${REVIEW_APP_NAME}"
fi
git config --global --add safe.directory "$PWD"
if [ -f "bin/ci-pre-deploy" ]; then
log-info "Executing bin/ci-pre-deploy script"
chmod +x bin/ci-pre-deploy
APP_NAME="$remote_app_name" IS_REVIEW_APP="$is_review_app" SSH_REMOTE="$ssh_remote" bin/ci-pre-deploy
fi
if [[ -f ci-commit-override ]]; then
commit_sha="$(cat ci-commit-override)"
log-info "Overriding commit sha with $commit_sha from ci-commit-override"
fi
if [ -n "$DEPLOY_DOCKER_IMAGE" ]; then
log-info "Deploying image to Dokku Host"
ssh "$ssh_remote" -- git:from-image "$remote_app_name" "$DEPLOY_DOCKER_IMAGE" "$DEPLOY_USER_NAME" "$DEPLOY_USER_EMAIL"
else
log-info "Pushing to Dokku Host"
# shellcheck disable=SC2086
git push $GIT_PUSH_FLAGS "$GIT_REMOTE_URL" "$commit_sha:refs/heads/$BRANCH"
fi