forked from django/djangoproject.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
106 lines (91 loc) · 2.78 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
import unipath
from fabric.api import *
from fabric.contrib import files
# Fab settings
env.hosts = ['ve.djangoproject.com']
# Deployment environment paths and settings and such.
env.deploy_base = unipath.Path('/home/www/djangoproject.com')
env.virtualenv = env.deploy_base
env.code_dir = env.deploy_base.child('src')
env.git_url = 'git://github.com/django/djangoproject.com.git'
env.default_deploy_ref = 'origin/master'
def full_deploy():
"""
Full deploy: new code, update dependencies, migrate, and restart services.
"""
deploy_code()
update_dependencies()
migrate()
apache("restart")
memcached("restart")
def deploy():
"""
Quick deploy: new code and an in-place reload.
"""
deploy_code()
apache("reload")
def apache(cmd):
"""
Manage the apache service. For example, `fab apache:restart`.
"""
sudo('invoke-rc.d apache2 %s' % cmd)
def memcached(cmd):
"""
Manage the memcached service. For example, `fab apache:restart`.
"""
sudo('invoke-rc.d memcached %s' % cmd)
def deploy_code(ref=None):
"""
Update code on the servers from Git.
"""
ref = ref or env.default_deploy_ref
puts("Deploying %s" % ref)
if not files.exists(env.code_dir):
sudo('git clone %s %s' % (env.git_url, env.code_dir))
with cd(env.code_dir):
sudo('git fetch && git reset --hard %s' % ref)
def update_dependencies():
"""
Update dependencies in the virtualenv.
"""
pip = env.virtualenv.child('bin', 'pip')
reqs = env.code_dir.child('deploy-requirements.txt')
sudo('%s -q install -U pip' % pip)
sudo('%s -q install -r %s' % (pip, reqs))
def migrate():
"""
Run migrate/syncdb.
"""
managepy('syncdb')
managepy('migrate')
def update_docs():
"""
Force an update of the docs on the server.
"""
managepy('update_docs', site='docs')
def copy_db():
"""
Copy the production DB locally for testing.
"""
local('ssh %s pg_dump -U djangoproject -c djangoproject | psql djangoproject' % env.hosts[0])
def copy_docs():
"""
Copy build docs locally for testing.
"""
local('rsync -av --delete --exclude=.svn %s:%s/ /tmp/djangodocs/' %
(env.hosts[0], env.deploy_base.child('docbuilds')))
def managepy(cmd, site='www'):
"""
Helper: run a management command remotely.
"""
assert site in ('docs', 'www')
django_admin = env.virtualenv.child('bin', 'django-admin.py')
sudo('%s %s --settings=django_website.settings.%s' % (django_admin, cmd, site))
def southify(app):
"""
Southify an app remotely.
This fakes the initial migration and then migrates forward. Use it the first
time you do a deploy on app that's been newly southified.
"""
managepy('migrate %s 0001 --fake' % app)
managepy('migrate %s' % app)