forked from luanfonceca/speakerfight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
77 lines (56 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# coding: utf-8
from os import environ
from fabric.api import env, cd, run
from fabric.colors import yellow, green
REPOSITORY = '[email protected]:luanfonceca/speakerfight.git'
REMOTE = 'origin'
BRANCH = 'master'
env.hosts = ['speakerfight.com']
env.user = 'root'
env.password = environ.get('PASSWORD')
env.app_dir = '/home/speakerfight'
env.project_name = 'speakerfight'
env.virtualenv_dir = '/home/virtualenv'
def _run(command, pip='python'):
run('{venv}/bin/{target} {command}'.format(
venv=env.virtualenv_dir,
command=command,
target=pip))
def _update_app():
with cd(env.app_dir):
print yellow('Fetch the Code')
run('git pull {remote} {branch}'.format(
remote=REMOTE,
branch=BRANCH))
print yellow('Update the Python Requirements')
_run('install -r requirements.txt --quiet', 'pip')
print yellow('Cleanning the .pyc files')
_run('manage.py clean_pyc')
print yellow('Migrate the DB')
_run('manage.py migrate --noinput --verbosity=0')
print yellow('Collecting the static files')
_run('manage.py collectstatic --noinput --verbosity=0')
print yellow('Compiling the strings')
_run('manage.py compilemessages')
print green('App succefully updated')
def _restart_app():
print yellow('Restart the Uwsgi')
run('service uwsgi restart')
print yellow('Restart the Nginx')
run('service nginx restart')
print green('Services succefully restarted')
def deploy():
_update_app()
_restart_app()
print green('Deploy succefully done!')
def load_initial_data():
fixtures = [
'deck/fixtures/user.json',
'deck/fixtures/event.json',
'deck/fixtures/proposal.json',
]
with cd(env.app_dir):
print yellow('Collecting the initial data')
for fixture in fixtures:
_run('manage.py loaddata {}'.format(fixture))
print green('Data succefully loaded')