~libravatar/libravatar/master

908 by Francois Marier
fabric: remove squeeze hacks
1
from fabric.api import abort, env, local, parallel, put, roles, run, sudo
2
from fabric.context_managers import lcd
660 by Francois Marier
Add initial fabfile for preparing the packages
3
import re
4
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
5
env.roledefs = {'cdn_only': ['2.cdn.libravatar.org'],
910 by Francois Marier
fabric: remove cdn3 from the list
6
                'seccdn': ['1.cdn.libravatar.org', '5.cdn.libravatar.org'],
799 by Francois Marier
Build packages for apt.libravatar.org
7
                'master': ['0.cdn.libravatar.org'],
8
                'repo': ['apt.libravatar.org']}
660 by Francois Marier
Add initial fabfile for preparing the packages
9
791 by Francois Marier
Pull the deployment code into a separate libravatar-deployment package (LP: #1049622)
10
COMMON_PACKAGES = ['libravatar-cdn', 'libravatar-common', 'libravatar-cdn-common', 'libravatar-deployment']
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
11
CDNCOMMON_PACKAGES = ['libravatar-slave']
12
SECCDN_PACKAGES = ['libravatar-seccdn']
660 by Francois Marier
Add initial fabfile for preparing the packages
13
MASTER_PACKAGES = ['libravatar', 'libravatar-www', 'libravatar-master']
14
15
# Extract current version number from Debian changelog
16
with open('debian/changelog', 'r') as changelog:
17
    PACKAGE_VERSION = re.search('\(([0-9]+\.[0-9])\)', changelog.readline()).group(1)
18
19
20
def commit_changelog():
740 by Francois Marier
Update prepare command for git
21
    if local("git status --porcelain", capture=True) != "M debian/changelog":
660 by Francois Marier
Add initial fabfile for preparing the packages
22
        abort("You must first update the Debian changelog.")
23
740 by Francois Marier
Update prepare command for git
24
    local('git commit -a -m "Bump changelog for deployment"', capture=False)
660 by Francois Marier
Add initial fabfile for preparing the packages
25
26
27
def prepare():
28
    local('make clean', capture=False)
29
    commit_changelog()
907 by Francois Marier
Don't require fabric inside the LXC container
30
    print "You must now build the packages in the LXC container: make package"
663 by Francois Marier
Add working deployment functions to the fabfile
31
32
799 by Francois Marier
Build packages for apt.libravatar.org
33
def sign_repo():
34
    # from http://blog.mycrot.ch/2011/04/26/creating-your-own-signed-apt-repository-and-debian-packages/
35
    with lcd('../libravatar-repo/'):
36
        local('rm -rf db dists pool');
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
37
        all_packages = COMMON_PACKAGES + CDNCOMMON_PACKAGES + SECCDN_PACKAGES + MASTER_PACKAGES
799 by Francois Marier
Build packages for apt.libravatar.org
38
        for package_name in all_packages:
39
            deb = '../%s_%s_all.deb' % (package_name, PACKAGE_VERSION)
929 by Francois Marier
Update cdn packages for jessie
40
            local("/usr/bin/reprepro --ask-passphrase -Vb . includedeb jessie %s" % deb)
799 by Francois Marier
Build packages for apt.libravatar.org
41
42
43
@roles('repo')
44
def upload_packages():
45
    run('rm -rf /var/www/apt-libravatar/db /var/www/apt-libravatar/dists /var/www/apt-libravatar/pool');
46
    for directory in ['conf', 'db', 'dists', 'pool']:
47
        put('../libravatar-repo/%s' % directory, '/var/www/apt-libravatar/')
48
49
50
def update_repo():
51
    sign_repo()
52
    upload_packages()
53
54
55
def install_packages(package_names):
663 by Francois Marier
Add working deployment functions to the fabfile
56
    all_debs = ''
57
    for package_name in package_names:
799 by Francois Marier
Build packages for apt.libravatar.org
58
        all_debs += ' %s' % package_name
663 by Francois Marier
Add working deployment functions to the fabfile
59
799 by Francois Marier
Build packages for apt.libravatar.org
60
    sudo('/usr/bin/apt-get install -y %s' % all_debs, shell=False)
663 by Francois Marier
Add working deployment functions to the fabfile
61
62
63
def restart_apache():
64
    # Restart Apache to make mod_wsgi use the new files
65
    sudo('/usr/sbin/apache2ctl configtest', shell=False)
66
    sudo('/usr/sbin/apache2ctl graceful', shell=False)
67
68
680 by Francois Marier
Deploy to the slaves in parallel (with fallback for older fabric)
69
@parallel
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
70
@roles('cdn_only')
71
def deploy_cdn():
799 by Francois Marier
Build packages for apt.libravatar.org
72
    sudo('/usr/bin/apt-get update', shell=False)
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
73
    install_packages(COMMON_PACKAGES + CDNCOMMON_PACKAGES)
663 by Francois Marier
Add working deployment functions to the fabfile
74
    restart_apache()
660 by Francois Marier
Add initial fabfile for preparing the packages
75
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
76
@parallel
77
@roles('seccdn')
78
def deploy_seccdn():
79
    sudo('/usr/bin/apt-get update', shell=False)
80
    install_packages(COMMON_PACKAGES + CDNCOMMON_PACKAGES + SECCDN_PACKAGES)
81
    restart_apache()
660 by Francois Marier
Add initial fabfile for preparing the packages
82
83
@roles('master')
84
def deploy_master():
799 by Francois Marier
Build packages for apt.libravatar.org
85
    sudo('/usr/bin/apt-get update', shell=False)
86
    install_packages(COMMON_PACKAGES + MASTER_PACKAGES)
663 by Francois Marier
Add working deployment functions to the fabfile
87
    restart_apache()
660 by Francois Marier
Add initial fabfile for preparing the packages
88
89
90
def deploy():
828 by Francois Marier
Split CDN and SECCDN deployments in fabfile
91
    deploy_cdn()
92
    deploy_seccdn()
660 by Francois Marier
Add initial fabfile for preparing the packages
93
    deploy_master()
94
95
96
def stage():
663 by Francois Marier
Add working deployment functions to the fabfile
97
    pass  # TODO: deploy all of the packages to a staging server