-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfabfile.py
More file actions
66 lines (52 loc) · 1.8 KB
/
fabfile.py
File metadata and controls
66 lines (52 loc) · 1.8 KB
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
from fabric.api import *
env.roledefs = {'dev': ['dev.fs.uwaterloo.ca'], 'prod': ['www-app.fs.uwaterloo.ca']}
deploy_to = {'dev': '/srv/python-apps/dev-course.feds.ca', 'prod': '/srv/course.feds.ca' }
repository = 'https://github.com/feds-sdn/Course-Qualifier.git'
source_dir = 'Course-Qualifier' # Must be the app name
def _annotate_hosts_with_ssh_config_info(): #{{{
from os.path import expanduser
from paramiko.config import SSHConfig
def hostinfo(host, config):
hive = config.lookup(host)
if 'hostname' in hive:
host = hive['hostname']
if 'user' in hive:
host = '%s@%s' % (hive['user'], host)
if 'port' in hive:
host = '%s:%s' % (host, hive['port'])
return host
try:
config_file = file(expanduser('~/.ssh/config'))
except IOError:
pass
else:
config = SSHConfig()
config.parse(config_file)
keys = [config.lookup(host).get('identityfile', None)
for host in env.hosts]
env.key_filename = [expanduser(key) for key in keys if key is not None]
env.hosts = [hostinfo(host, config) for host in env.hosts]
for role, rolehosts in env.roledefs.items():
env.roledefs[role] = [hostinfo(host, config) for host in rolehosts]
_annotate_hosts_with_ssh_config_info() #}}}
def pull():
git_dir = deploy_to[env.roles[0]] + '/' + source_dir
with settings(warn_only=True):
result = sudo('cd ' + git_dir + ' && git pull')
if result.failed:
with cd(deploy_to[env.roles[0]]):
sudo('git clone ' + repository + ' ' + git_dir)
def install():
with cd(deploy_to[env.roles[0]]):
sudo('bin/pip install ' + source_dir)
def restart():
with cd(deploy_to[env.roles[0]]):
sudo('touch dispatch.wsgi')
def deploy():
pull()
install()
restart()
def setup():
with cd(deploy_to[env.roles[0]]):
sudo('bin/pip install -r ' + source_dir + '/requirements.txt')
sudo('bin/paster setup-app config.ini')