-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·55 lines (47 loc) · 1.6 KB
/
deploy.sh
File metadata and controls
executable file
·55 lines (47 loc) · 1.6 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
#!/bin/bash
CWD="$PWD/bin"
echo "CWD $CWD"
BRANCH=$(sh $CWD/branch.sh)
echo "BRANCH=> $BRANCH"
DOKKU_APP=$(sh $CWD/app-name.sh)
echo "DOKKU_APP=> $DOKKU_APP"
# these could all be environment variables:
USER="root"
SSH="ssh -i ./deploy_key $USER@$SERVER_IP_ADDRESS"
URL="$SERVER_IP_ADDRESS:$DOKKU_APP"
echo "URL => $URL"
# create the dokku App
CREATE="dokku apps:create $DOKKU_APP"
echo "CREATE => $CREATE"
$SSH $CREATE
# set git remote for the "review" dokku app:
REMOTE="dokku dokku@$URL"
echo "REMOTE $REMOTE"
if [ "$TRAVIS" == "true" ]; then
$(git remote add $REMOTE)
# Travis does a "shallow" git clone so we need to "unshallow" it:
$(git fetch --unshallow) # see: https://github.com/dwyl/learn-devops/issues/33
$(git config --global push.default simple)
else
$(git remote set-url $REMOTE)
fi
# Temporarily Stop Nginx to avoid the git push / build failing:
KILL_NGINX="pkill nginx"
echo "KILL_NGINX => $KILL_NGINX"
SYSTEMCTL_START_NGINX="systemctl start nginx"
echo "SYSTEMCTL_START_NGINX => $SYSTEMCTL_START_NGINX"
$SSH $KILL_NGINX
$SSH $SYSTEMCTL_START_NGINX
# Push *ONLY* the latest commit to dokku (minimalist)
COMMIT_HASH=$(sh $CWD/commit-hash.sh)
echo "COMMIT_HASH=> $COMMIT_HASH"
PUSH="git push dokku $COMMIT_HASH:refs/heads/master" # this should work *everywhere*
echo "PUSH $PUSH"
$($PUSH)
# Apply the Letsencrypt Wildcard SSL/TLS Certificate to the app
CERTS="sudo dokku certs:add $DOKKU_APP < /etc/letsencrypt/live/ademo.app/certs.tar"
$SSH $CERTS
# Reload (restart) nginx so the new app is served:
RELOAD="systemctl stop nginx && nginx -t && nginx"
$SSH $RELOAD
# $(sh $CWD/docker-exited.sh)