Sign up to create your own snipts, or login.

Public snipts » saebyn's snipts » fabric setup for django

posted on Oct 18, 2009 at 2:31 p.m. EDT in 
  • #
    
    def localhost():
        config.fab_hosts = ['localhost']
        config.path = '/home/john/saebyn'
        config.env_path = '/usr/local/pythonenv/'
        config.env_name = 'SAEBYN-1'
        config.fab_user = 'john'
    
    def local_test():
        localhost()
        local('source $(env_path)/$(env_name)/bin/activate; cd $(path)/website; ./manage.py runserver --settings=local_settings')
    
    def test():
        """Production server settings"""
        config.fab_hosts = ['saebyn.info']
        config.path = '/home/www/test.saebyn.info'
        config.fab_user = 'john'
        config.env_path = '/usr/local/pythonenv/'
        config.env_name = 'SAEBYN-1'
    
    def production():
        """Production server settings"""
        config.fab_hosts = ['saebyn.info']
        config.path = '/home/www/saebyn.info'
        config.fab_user = 'john'
        config.env_path = '/usr/local/pythonenv/'
        config.env_name = 'SAEBYN-1'
    
    def setup():
        """
        Setup a fresh virtualenv and install everything we need so it's ready to
        deploy to
        """
        create_virtualenv()
        install_requirements()
    
    def create_virtualenv():
        sudo('mkdir -p $(env_path)')
        sudo('cd $(env_path); virtualenv $(env_name)')
        sudo('cd $(env_path); chown -R $(fab_user) $(env_name)')
    
    def install_requirements():
        """Install the required packages using pip"""
        run('cd $(env_path)/$(env_name); pip install -E . -r $(path)/requirements.txt')
    
    def deploy():
        """Deploy the latest version of the site to the server and restart apache"""
        push_live()
        migrate()
        restart_apache()
    
    def push_live():
        """Rebase 'live' using 'master', push it."""
        local('git checkout live')
        local('git rebase master')
        local('git push origin live')
        local('git checkout master')
    
    def migrate():
        """Run our migrations"""
        run('source $(env_path)/$(env_name)/bin/activate; cd $(path)/website; python manage.py syncdb --noinput --migrate')
    
    def restart_apache():
        """Restart the web server"""
        sudo('/etc/init.d/apache2 restart')
    

    copy | embed

0 Comments

Sign up, or login to leave a comment.