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
|
from fabric.api import abort, env, local, put, roles, run, sudo
import re
env.roledefs = {'slave': ['1.cdn.libravatar.org', '2.cdn.libravatar.org', '3.cdn.libravatar.org'],
'master': ['0.cdn.libravatar.org']}
COMMON_PACKAGES = ['libravatar-cdn', 'libravatar-common', 'libravatar-cdn-common']
SLAVE_PACKAGES = ['libravatar-seccdn', 'libravatar-slave']
MASTER_PACKAGES = ['libravatar', 'libravatar-www', 'libravatar-master']
# Extract current version number from Debian changelog
with open('debian/changelog', 'r') as changelog:
PACKAGE_VERSION = re.search('\(([0-9]+\.[0-9])\)', changelog.readline()).group(1)
def commit_changelog():
if local("bzr status --short", capture=True) != 'M debian/changelog':
abort("You must first update the Debian changelog.")
local('bzr commit -m "Bump changelog for deployment"', capture=False)
def prepare():
local('make clean', capture=False)
commit_changelog()
local('make package', capture=False)
def copy_and_install_packages(package_names):
all_debs = ''
for package_name in package_names:
deb = '%s_%s_all.deb' % (package_name, PACKAGE_VERSION)
all_debs += ' /home/%s/debs/%s' % (env.user, deb)
put('../%s' % deb, 'debs/')
sudo('/usr/bin/dpkg -i%s' % all_debs, shell=False)
def restart_apache():
# Restart Apache to make mod_wsgi use the new files
sudo('/usr/sbin/apache2ctl configtest', shell=False)
sudo('/usr/sbin/apache2ctl graceful', shell=False)
def commit_etc_changes():
# TODO: deal with etckeeper (check that the git branch is clean, then commit automatically)
pass
@roles('slave')
def deploy_slave():
run('mkdir -p debs') # ensure the target directory exists
copy_and_install_packages(COMMON_PACKAGES)
copy_and_install_packages(SLAVE_PACKAGES)
restart_apache()
commit_etc_changes()
@roles('master')
def deploy_master():
run('mkdir -p debs') # ensure the target directory exists
copy_and_install_packages(COMMON_PACKAGES)
copy_and_install_packages(MASTER_PACKAGES)
restart_apache()
commit_etc_changes()
def deploy():
deploy_slave()
deploy_master()
def stage():
pass # TODO: deploy all of the packages to a staging server
|