-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathdokku_first_deploy.sh
executable file
·61 lines (48 loc) · 2.13 KB
/
dokku_first_deploy.sh
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
#!/usr/bin/env bash
set -ex
# Script to run for the first Dokku deploy
# It tries to be idempotent where possible, but it's not always possible.
# After running this once, later deploys can be done just by pushing master to Dokku:
#
# git push dokku master
#
# To deploy other branches, see http://dokku.viewdocs.io/dokku/deployment/application-deployment/#deploying-non-master-branch
# Allow overriding project name on command line
if [ "$1" != "" ] ; then
PROJECT="$1"
else
PROJECT="{{ project_name }}"
fi
if ! git status >/dev/null ; then
echo "The project must be checked into git before continuing"
exit 1
fi
DOKKU_SERVER=dokku
if ! ssh $DOKKU_SERVER version ; then
echo "This script assumes 'ssh'"$DOKKU_SERVER"' will connect as dokku to the dokku server."
echo "Either edit the top of this script, or add something like this to your ~/.ssh/config file:"
cat <<_EOF_
Host $DOKKU_SERVER
Hostname my.dokku.server.tld
User dokku
RequestTTY yes
_EOF_
exit 1
fi
dokku() { ssh $DOKKU_SERVER "$@"; }
dokku apps:report $PROJECT || dokku apps:create $PROJECT
STORAGE=/var/lib/dokku/data/storage/$PROJECT
dokku storage:list $PROJECT | grep --quiet $STORAGE || dokku storage:mount $PROJECT $STORAGE:/storage
dokku config:set $PROJECT MEDIA_ROOT=/storage/media MEDIA_URL=/media ENVIRONMENT=production DOMAIN=$PROJECT.$(dokku domains:report $PROJECT --domains-global-vhosts)
# Create and link to database
dokku postgres:info $PROJECT-database || dokku postgres:create $PROJECT-database
dokku postgres:info $PROJECT-database | grep Links: | grep --quiet $PROJECT || dokku postgres:link $PROJECT-database $PROJECT
# Create a secret key, but only if there's not one already.
dokku config:get $PROJECT DJANGO_SECRET_KEY >/dev/null || dokku config:set --no-restart $PROJECT DJANGO_SECRET_KEY=$(make generate-secret)
# Create remote
git remote | grep dokku || git remote add dokku $DOKKU_SERVER:$PROJECT
# PUSH! First deploy
git push dokku master
# Set up letsencrypt - assumes DOKKU_LETSENCRYPT_EMAIL is already set globally on the Dokku server, or else it'll fail
dokku letsencrypt $PROJECT
dokku letsencrypt:cron-job --add $PROJECT