-
Notifications
You must be signed in to change notification settings - Fork 6
/
fabfile.py
57 lines (37 loc) · 1.4 KB
/
fabfile.py
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
from __future__ import with_statement
from fabric.api import local, cd, env, run
from fabric.colors import green
PRODUCTION_DIR = 'keep'
PRODUCTION_SETTINGS = 'settings.production'
SUPERVISOR_NAME = 'keep'
MONGODB_NAME = 'dhlab'
env.use_ssh_config = True
env.user = 'ubuntu'
env.hosts = [ 'keep-dev' ]
def backup_db():
'''Backup local MongoDB database'''
local( 'mongodump -d %s -o _data/dhlab-backup' % ( MONGODB_NAME ) )
def restore_db():
'''Restore MongoDB database from backup. DELETES DATA'''
local( 'mongorestore --drop _data/dhlab-backup' )
def build_static():
local( 'python dhlab_backend/manage.py collectstatic --settings="%s"' %
( PRODUCTION_SETTINGS ) )
def clean():
'''Clean up project directory.'''
local( "find . -name '*.pyc' -delete" )
def deploy():
'''Deploy the backend to the server'''
print green( 'Deploy to EC2 instance...' )
with cd( PRODUCTION_DIR ):
# Stop all running processes
run( 'supervisorctl stop %s' % ( SUPERVISOR_NAME ) )
# Pull latest code from git
run( 'git pull origin master' )
# Start up all processes again
run( 'supervisorctl start all' )
def test():
print green( 'Running tests...' )
local('coverage run dhlab_backend/manage.py test --settings=settings.test')
print green( 'Generating coverage report...' )
local( 'coverage html --omit="*.pyenvs*"' )