This repository has been archived by the owner on Oct 5, 2024. It is now read-only.
forked from EuroPython/djep
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfabfile.py
160 lines (124 loc) · 3.66 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
# -*- coding: utf-8 -*-
import functools
from os.path import join, splitext
from fabric.api import *
if not env.get('branch'):
abort("Please select a config file (staging.ini | production.ini)")
env.hosts = ['pyep00.gocept.net', ]
env.srv_user = 'pyep'
env.proj_name = 'pyconde'
env.www_root = join(env.root, 'htdocs')
env.proj_root = join(env.root, 'djep')
env.manage_py = join(env.proj_root, 'manage.py')
def srv_run(cmd):
return sudo("{envdirbin} {envdir} {cmd}".format(
envdirbin=join(env.root, 'bin', 'envdir'),
envdir=join(env.root, 'env'),
cmd=cmd
), user=env.srv_user)
def srv_open_shellfa(cmd):
return open_shell('sudo -u %s -s -- %s' % (env.srv_user, cmd))
def ve_python(cmd):
return srv_run('%s %s' % (join(env.root, 'bin', 'python'), cmd))
def manage_py(cmd):
return ve_python('%s %s' % (join(env.proj_root, 'manage.py'), cmd))
def supervisorctl(cmd):
return srv_run('%s %s' % (join(env.root, 'bin', 'supervisorctl'), cmd))
@task
def compilemessages():
"""Compile the i18n messages."""
with cd(join(env.proj_root, env.proj_name)):
manage_py('compilemessages')
# We have to compile the JavaScript messages within their respective app.
with cd(join(env.proj_root, env.proj_name, 'core')):
manage_py('compilemessages')
@task
def upgrade():
"""
Upgrades the server to the latest codebase.
"""
update_proj()
update_requirements()
syncdb()
migrate()
build_static_files()
compilemessages()
restart_celery()
restart_worker()
# build_docs()
@task
def syncdb():
"""
Executes python manage.py syncdb on the server.
"""
manage_py('syncdb --noinput')
@task
def migrate():
"""
Executes python manage.py migrate on the server.
"""
manage_py('migrate --noinput')
@task
def update_requirements():
"""
Updates the project's requirements based on the requirements.txt file.
"""
pip = join(env.root, 'bin', 'pip')
requirements = join(env.proj_root, 'requirements', '{0}.txt'.format(
env.environment))
srv_run('%s install -r %s' % (pip, requirements))
@task
def update_proj():
"""
Fetches changes from the repository.
"""
with cd(env.proj_root):
srv_run('git pull')
srv_run('git checkout -f %s' % env.branch)
@task
def build_static_files():
"""
Compiles less files into css, runs collectstatic and compress.
"""
with cd(env.proj_root):
srv_run('npm install')
with cd(env.proj_root + '/pyconde/skins/ep14/static/assets'):
srv_run('../../../../../node_modules/bower/bin/bower install')
with path('/srv/pyep/.gem/ruby/1.8/bin/', behavior='prepend'):
srv_run('./node_modules/grunt-cli/bin/grunt compass:dist')
manage_py('compilejsi18n')
manage_py('collectstatic --noinput -v1')
manage_py('compress --force')
@task
def restart_worker():
"""
Restarts the gunicorn workers managed by supervisord.
"""
return supervisorctl('restart site')
@task
def restart_celery():
"""
Restarts the gunicorn workers managed by supervisord.
"""
return supervisorctl('restart celery')
@task
def djshell():
"""
Starts a Django shell on the server.
"""
return srv_open_shell('%s %s shell' % (
join(env.root, 'bin', 'python'),
join(env.proj_root, 'manage.py')))
@task
def loaddata(fixture):
"""
Loads a given fixture name.
"""
manage_py('loaddata {0}'.format(fixture))
@task
def build_docs():
"""
Rebuilds the sphinx documentation on the server.
"""
with cd(join(env.proj_root, 'docs')):
srv_run("source ../../bin/activate && make html")