Skip to content
Snippets Groups Projects
Select Git revision
  • df0d2c59286455ea1a2271f61aeb810572eeb321
  • test default protected
  • master protected
  • original
  • pirati-backup protected
  • beta-2
  • beta-1
  • v3.1.4
  • v3.1.3
  • v3.1.2
  • v3.1.1
  • v3.1.0
  • v3.0.16
  • v3.0.15
  • v3.0.14
  • v3.0.13
  • v3.0.12
  • v3.0.11
  • v3.0.10
  • v3.0.9
  • v3.0.8
  • v3.0.7
  • v3.0.6
  • v3.0.5
  • v3.0.4
25 results

glue.py

Blame
  • fabfile.py 2.52 KiB
    """
    Deployment Fabric file
    
    A fabric deployment script for Helios that assumes the following:
    - locally, development is /web/helios-server
    - remotely, production is /web/production/helios-server
    - remotely, staging is /web/staging/helios-server
    - all of these directories are git checkouts that have a proper origin pointer
    
    Other assumptions that should probably change:
    - both staging and production run under the same apache instance
    
    Deployment is git and tag based, so:
    
    fab staging_deploy:tag=v3.0.4,hosts="vote.heliosvoting.org"
    fab production_deploy:tag=v3.0.5,hosts="vote.heliosvoting.org"
    
    IMPORTANT: settings file may need to be tweaked manually
    """
    
    from fabric.api import local, settings, abort, cd, run, sudo
    from fabric.contrib.console import confirm
    
    STAGING_DIR = "/web/staging/helios-server"
    PRODUCTION_DIR = "/web/production/helios-server"
    
    def run_tests():
        result = local("python manage.py test", capture=False)
        if result.failed:
            abort("tests failed, will not deploy.")
    
    def check_tag(tag, path):
        result = local('git tag')
        if tag not in result.split("\n"):
            abort("no local tag %s" % tag)
    
        with cd(path):
            run('git pull origin master')
            run('git fetch --tags')
            result = run('git tag')
            if tag not in result.split("\n"):
                abort("no remote tag %s" % tag)
    
    def checkout_tag(tag, path):
        with cd(path):
            result = run('git checkout %s' % tag)
            if result.failed:
                abort("on remote: could not check out tag %s" % tag)
    
            result = run('git submodule init')
            if result.failed:
                abort("on remote: could not init submodules")
    
            result = run('git submodule update')
            if result.failed:
                abort("on remote: could not update submodules")
    
    def migrate_db(path):
        with cd(path):
            result = run('python manage.py migrate')
            if result.failed:
                abort("could not migrate")
    
    def restart_apache():
        result = sudo('/etc/init.d/apache2 restart')
        if result.failed:
            abort("could not restart apache")
    
    def restart_celeryd():
        result = sudo('/etc/init.d/celeryd restart')
        if result.failed:
            abort("could not restart celeryd")
    
    def deploy(tag, path):
        confirm("Ready to deploy %s to %s?" % (tag,path))
        run_tests()
        check_tag(tag, path=path)
        checkout_tag(tag, path=path)
        migrate_db(path=path)
        restart_apache()
        
    def staging_deploy(tag):
        deploy(tag, path=STAGING_DIR)
    
    def production_deploy(tag):
        deploy(tag, path=PRODUCTION_DIR)
        restart_celeryd()