forked from frankV/manekineko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
173 lines (131 loc) · 3.58 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
"""
fabfile
~~~~~~~
fabric commands
"""
import os
from fabric.api import *
from fabric.contrib.project import rsync_project
from fabric.contrib import console
from fabric import utils
import fabric_gunicorn as gunicorn
project = "fbone"
# the user to use for the remote commands
env.user = ''
# the servers where the commands are executed
env.hosts = ['']
RSYNC_EXCLUDE = [
'app_wsgi.py',
'*.pyc',
'.DS_Store',
'config/',
'conf/',
'tmp/',
'*.cfg',
'*.conf',
'LICENSE',
'*.md',
'.hg*',
'.flow'
]
def bootstrap():
""" initialize remote host environment (virtualenv, deploy, update) """
create_virtualenv()
deploy()
update_requirements()
def create_virtualenv():
""" setup virtualenv on remote host """
with prefix("source ~/.bash_profile"):
run('mkvirtualenv %s' % 'fbone')
def update_requirements():
""" update external dependencies on remote host """
with prefix('workon fbone'):
requirements = os.path.join(env.path, 'requirements.txt')
cmd = ['pip install -r %s' % requirements]
run(' '.join(cmd))
def reset():
"""Reset local debug env.
"""
local("rm -rf /tmp/instance")
local("mkdir /tmp/instance")
local("python manage.py initdb")
def apt_get(*packages):
sudo('apt-get -y --no-upgrade install %s' % ' '.join(packages), shell=False)
def setup():
"""Setup virtual env.
"""
apt_get("python-pip libmysqlclient-dev python-dev")
local("virtualenv env")
activate_this = "env/bin/activate_this.py"
execfile(activate_this, dict(__file__=activate_this))
local("python setup.py install")
reset()
def deploy():
""" rsync code to remote host """
if env['roles'] == ['production']:
if not console.confirm('Are you sure you want to deploy production?',
default=False):
utils.abort('Production deployment aborted.')
run('mkdir -p %s' % os.path.join(env.path, 'tmp/instance'))
extra_opts = '--update'
rsync_project(
env.path,
env.root,
exclude=RSYNC_EXCLUDE,
delete=True,
extra_opts=extra_opts,)
def create_database():
"""Creates role and database"""
pass
def d():
"""Debug.
"""
reset()
local("python manage.py runserver")
def babel():
"""Babel compile.
"""
local("pybabel extract -F ../fbone/config -k lazy_gettext -o messages.pot fbone")
local("pybabel init -i messages.pot -d fbone/translations -l es")
local("pybabel init -i messages.pot -d fbone/translations -l en")
local("pybabel compile -f -d fbone/translations")
def service(command=None):
""" usage: service:command
ex: fab -R production service:status
commands: start, stop, status
"""
if command:
run('service fbone %s' % command)
utils.error('invalid command')
def ps(name=None):
""" usage: ps:name
ex: fab -R production ps:name
name: process name
"""
if name:
run('ps aux | grep %s' % name)
utils.error('invalid command')
@task
def dev():
# env.user = 'root'
# env.hosts = ['localhost']
env.gunicorn_wsgi_app = 'app_wsgi'
# env.remote_workdir = '/root/lurcat-flask/lurcat'
env.virtualenv_dir = os.environ['WORKON_HOME'] + 'env'
env.gunicorn_workers = 1
local("export LURCAT_CFG='config/server.cfg'")
@task
def deploy():
local('hg pull')
local('hg update')
restart()
@task
def restart():
gunicorn.restart()
@task
def start_app():
gunicorn.start()
@task
def stop_app():
gunicorn.stop()