-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabfile.py
More file actions
54 lines (38 loc) · 1.19 KB
/
fabfile.py
File metadata and controls
54 lines (38 loc) · 1.19 KB
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
from __future__ import with_statement
import re
import os
from fabric.api import settings, run, local, env
from fabric.context_managers import prefix
from fabric.contrib.files import exists
APP_DIR = '/apps/my_django'
VIRTUAL_ENV = APP_DIR + '/env'
env.hosts = ['derekzeng.me']
env.user = 'coderek'
env.key = '/Users/derekzeng/.ssh/id_rsa.pub'
env.cwd = APP_DIR
def init_virtual_env():
if not exists(VIRTUAL_ENV):
run('pip install virtualenv')
run('virtualenv {}'.format(VIRTUAL_ENV))
else:
print 'Virtual Env is already existed'
def pip_install():
init_virtual_env()
run('pip install -r {}/requirements.txt'.format(APP_DIR))
def git():
run('git reset --hard origin/master')
run('git pull')
def migrate():
run('django_env=prod ./manage.py migrate')
def collectstatic():
run('django_env=prod ./manage.py collectstatic --noinput -i node_modules')
def restart():
run('supervisorctl -c /apps/my_django/supervisord.conf restart all')
def deploy():
run('cd ' + APP_DIR)
git()
with prefix('source {}'.format(os.path.join(VIRTUAL_ENV, 'bin', 'activate'))):
pip_install()
migrate()
collectstatic()
restart()