Created
June 10, 2010 12:30
-
-
Save haplo/432920 to your computer and use it in GitHub Desktop.
Fabric deployment with virtualenv support in the server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This fabfile deploys projects versioned in git and that use a virtualenv in the | |
remote server. | |
The deploy and deploy_version tasks are framework-independent. | |
The freshdb task is specific for Django projects. | |
The restart task is for projects deployed using FastCGI. | |
TODO: | |
* Bootstrap command to create a virtualenv and install requirements with pip. | |
""" | |
from __future__ import with_statement | |
from fabric.api import cd, env, require, run, settings | |
env.project_name = 'project_name' | |
env.user = 'remote_user' | |
env.hosts = ['your_host.com'] | |
env.home_path = '/home/remote_user' | |
env.path = '%s/path/to/project' % env.home_path | |
env.virtualenv_dir = '%s/env' % env.home_path | |
def _virtualenv(command): | |
"""Execute a command in remote host inside a virtualenv.""" | |
require('virtualenv_dir') | |
run('source %s/bin/activate && %s' % (env.virtualenv_dir, command)) | |
def deploy(): | |
"""Update the remote code to the last version and make it visible.""" | |
deploy_version() | |
def deploy_version(version=None): | |
"""Update the remote code to a specific version and make it visible.""" | |
require('path') | |
with cd(env.path): | |
run('git checkout master') | |
run('git pull') | |
if version is not None: | |
run('git checkout %s' % version) | |
restart() | |
def freshdb(): | |
"""Delete the remote DB and make a fresh syncdb.""" | |
require('path') | |
with cd(env.path): | |
with settings(warn_only=True): | |
run('rm chattr.db') | |
_virtualenv('python manage.py syncdb --noinput') | |
def restart(): | |
"""Restart the FastCGI process (to make changes visible).""" | |
require('home_path') | |
with settings(warn_only=True): | |
run('kill $(cat %(home_path)s/run/chattr.pid)' % env) | |
run('sh %(path)s/conf/chattr_fastcgi.sh' % env) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment