-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy.sh
83 lines (68 loc) · 2.42 KB
/
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -e
HEROKU_APP=$1
# check $1 is valid
if [ -z $HEROKU_APP ]; then
echo "Invalid Heroku app name"
echo "Usage: $0 [appname]"
exit
fi
echo "Checking app"
if ! heroku apps | grep $HEROKU_APP > /dev/null; then
echo "Creating app"
heroku create $HEROKU_APP
fi
echo "Checking buildpack"
if ! heroku buildpacks -a $HEROKU_APP | grep "http://github.com/ryandotsmith/null-buildpack.git" > /dev/null; then
echo "Setting buildpack"
heroku buildpacks:set http://github.com/ryandotsmith/null-buildpack.git -a $HEROKU_APP
fi
echo "Checking for Postgres addon"
if ! heroku addons -a $HEROKU_APP | grep "heroku-postgresql" > /dev/null; then
echo "Adding Postgres"
heroku addons:create heroku-postgresql:hobby-dev -a $HEROKU_APP
fi
echo "Getting DATABASE_URL"
DATABASE_URL=`heroku config:get DATABASE_URL -a $HEROKU_APP`
if [[ ! $DATABASE_URL =~ ^postgres://([^:]+):([^@]+)@([^:]+):([^/]+)/(.*)$ ]]; then
echo "DATABASE_URL format unrecognised"
exit 1
fi
GF_DATABASE_HOST=${BASH_REMATCH[3]}:${BASH_REMATCH[4]}
GF_DATABASE_NAME=${BASH_REMATCH[5]}
GF_DATABASE_USER=${BASH_REMATCH[1]}
GF_DATABASE_PASSWORD=${BASH_REMATCH[2]}
echo "Getting Postgres credentials"
POSTGRES_CREDENTIALS=`heroku pg:credentials:url DATABASE -a $HEROKU_APP | grep dbname | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
if [[ ! $POSTGRES_CREDENTIALS =~ ^\"(.*)\"$ ]]; then
echo "POSTGRES_CREDENTIALS format unrecognised"
exit 1
fi
POSTGRES_CREDENTIALS=${BASH_REMATCH[1]}
echo "Setting up session database"
(\
echo "\connect ${GF_DATABASE_NAME}"; \
echo "CREATE TABLE session (key CHAR(16) NOT NULL, data bytea, expiry INT NOT NULL, PRIMARY KEY (key));"; \
echo "\dt"; echo "\q" \
) | heroku pg:psql -a $HEROKU_APP DATABASE_URL
echo "Enter administrator username [default: admin]"
read USER
USER=${USER:-admin}
echo "Enter administrator password"
read -s PASS
echo "Enter secret key"
read SECRET
echo "Setting variables"
heroku config:set \
GF_DATABASE_TYPE="postgres" \
GF_DATABASE_HOST="$GF_DATABASE_HOST" \
GF_DATABASE_NAME="$GF_DATABASE_NAME" \
GF_DATABASE_USER="$GF_DATABASE_USER" \
GF_DATABASE_PASSWORD="$GF_DATABASE_PASSWORD" \
GF_DATABASE_SSL_MODE="require" \
GF_SESSION_PROVIDER="postgres" \
GF_SESSION_PROVIDER_CONFIG="$POSTGRES_CREDENTIALS" \
GF_SECURITY_ADMIN_USER="$USER" \
GF_SECURITY_ADMIN_PASSWORD="$PASS" \
GF_SECURITY_SECRET_KEY="$SECRET" \
-a $HEROKU_APP