-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.sh
executable file
·84 lines (63 loc) · 2.06 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
84
#!/bin/bash
########################################################################
# _____ _ _____ _
# | __ \(_) | __ \ | |
# | | | |_ __ _ _ __ __ _ ___ | | | | ___ _ __ | | ___ _ _
# | | | | |/ _` | '_ \ / _` |/ _ \ | | | |/ _ \ '_ \| |/ _ \| | | |
# | |__| | | (_| | | | | (_| | (_) | | |__| | __/ |_) | | (_) | |_| |
# |_____/| |\__,_|_| |_|\__, |\___/ |_____/ \___| .__/|_|\___/ \__, |
# _/ | __/ | | | __/ |
# |__/ |___/ |_| |___/
########################################################################
###########################
# Load configurations #
###########################
. config_base.sh
. config_app.sh
###########################
# Fetch current release #
###########################
# Current release
CURRENT_RELEASE=$APP_NAME'_'`date +"%Y%m%d%H%M%S"`
# Activate virtualenv
source $VIRTUAL_ENV
# Creates releases dir if not exists
[ -d $RELEASES_DIR ] || mkdir $RELEASES_DIR;
# Change dir to releases dir
cd $RELEASES_DIR;
# Clone
git clone $REPO --branch=$BRANCH --depth=1 $CURRENT_RELEASE;
###########################
# Setup app #
###########################
# Work on current release dir
cd $RELEASES_DIR$CURRENT_RELEASE
# Install packages
pip install -r requirements.txt
# Test app with production settings
cd $RELEASES_DIR$CURRENT_RELEASE
./manage.py test --settings=$CONFIGURATION
TESTS_RESULT=$?
###########################
# Linking #
###########################
# Tests passed
if [[ $TESTS_RESULT -eq 0 ]]; then
# Migrate production database
echo 'Migrating...'
./manage.py migrate --settings=$CONFIGURATION
echo 'Migrated.'
# Collect statics
./manage.py collectstatic --noinput
# Work on Base Dir
cd $BASE_DIR
# Drops existing current
rm $CURRENT_DIR
# New current
ln -s $RELEASES_DIR$CURRENT_RELEASE $CURRENT_DIR
# Reload apache
sudo service apache2 reload
echo 'Success!'
else
echo 'Tests failed!'
fi