-
Notifications
You must be signed in to change notification settings - Fork 18
/
deploy.sh
executable file
·59 lines (50 loc) · 1.98 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
#!/bin/sh
# Scripts to deploy application to staging server
ENVIRONMENT='staging'
SERVER=$(jq -r ".credentials.server.$ENVIRONMENT.address" ../credentials.json)
USER=$(jq -r ".credentials.server.$ENVIRONMENT.username" ../credentials.json)
PASS=$(jq -r ".credentials.server.$ENVIRONMENT.password" ../credentials.json)
PG_USER=$(jq -r ".credentials.postgres.$ENVIRONMENT.username" ../credentials.json)
PG_PASS=$(jq -r ".credentials.postgres.$ENVIRONMENT.password" ../credentials.json)
echo "-- Remove our own venv dir"
rm -rf ./venv
echo "-- Copy credential file"
sudo cp ../credentials.json .
echo "-- Remove existing dir"
sshpass -p $PASS ssh -o StrictHostKeyChecking=no $USER@$SERVER -tt << EOF
rm -rf /app
logout
EOF
echo "-- Copy application code to staging server"
sshpass -p $PASS scp -o StrictHostKeyChecking=no -r `pwd` $USER@$SERVER:/app
# add scripts in cron (like the one created in #47)
# verify the webapplication is running
echo "-- Execute install script"
sshpass -p $PASS ssh -o StrictHostKeyChecking=no $USER@$SERVER -tt << EOF
cd /app
chmod +x /app/scripts/install/deploy/install_dependencies.sh
/app/scripts/install/deploy/install_dependencies.sh
cd /app
echo "-- REPLACE: add scripts to cron"
python3.6 -m venv venv
echo "-- Enabling virtual environment"
. venv/bin/activate
echo "-- Installing dependent libraries"
pip3 install -r requirements.txt
echo "-- Running database migrations"
export TIMELESSIS_CONFIG="config.StagingConfig"
export SQLALCHEMY_DATABASE_URI="postgresql://$PG_USER:$PG_PASS@localhost/timelessdb"
python3.6 manage.py db upgrade
chmod +x /app/scripts/install/deploy/create_data.sh
/app/scripts/install/deploy/create_data.sh
echo "-- Running web application server"
export FLASK_APP=main.py
export FLASK_ENV=development
export FLASK_RUN_PORT=80
export FLASK_RUN_HOST=$SERVER
nohup flask run > /var/log/timeless.log 2>&1 &
rm -rf /app/credentials.json
echo "-- REPLACE: verify web application is running ok"
logout
EOF
exit 0