forked from rdiankov/openrave.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
109 lines (94 loc) · 3.18 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
import os
from fabric.api import *
from fabric.contrib import files
# Fab settings
env.hosts = ['openrave.org']
# Deployment environment paths and settings and such.
env.deploy_base = '/var/openrave'
env.virtualenv = '/usr/local'
env.code_dir = os.path.join(env.deploy_base, 'openrave.org_svn')
env.svn_url = 'https://openrave.svn.sourceforge.net/svnroot/openrave/openrave.org'
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.
"""
puts("Deploying")
if not files.exists(env.code_dir):
run('svn checkout %s %s'%(env.svn_url,env.code_dir))
with cd(env.code_dir):
run('svn update')
run('rm -rf %s'%os.path.join(env.deploy_base,'staticnew'))
run('svn export %s %s'%(os.path.join(env.code_dir,'openrave_website','static'), os.path.join(env.deploy_base,'staticnew')))
run('rm -rf %s; mv %s %s'%(os.path.join(env.deploy_base,'static'), os.path.join(env.deploy_base,'staticnew'), os.path.join(env.deploy_base,'static')))
# have to chown/chmod docdata for searching
sudo('chown -R $USER:www-data %s'%os.path.join(env.code_dir,'docdata'))
sudo('chmod -R g+w %s'%os.path.join(env.code_dir,'docdata'))
def update_dependencies():
"""
Update dependencies in the virtualenv.
"""
pip = os.path.join(env.virtualenv,'bin', 'pip')
reqs = os.path.join(env.code_dir, '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')
managepy('compilemessages --locale=ja_JP')
def update_docs():
"""
Force an update of the docs on the server.
"""
managepy('update_docs -v2')
def copy_db():
"""
Copy the production DB locally for testing.
"""
local('ssh %s pg_dump -U openrave -c openrave_website | psql openrave_website ' % env.hosts[0])
def copy_docs():
"""
Copy build docs locally for testing.
"""
local('rsync -av --delete --exclude=.svn %s:%s/ /tmp/openravedocs/' %(env.hosts[0], env.deploy_base.child('docbuilds')))
def managepy(cmd):
"""
Helper: run a management command remotely.
"""
django_admin = os.path.join(env.virtualenv, 'bin', 'django-admin.py')
run('%s %s --settings=openrave_website.settings' % (django_admin, cmd))
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)