Skip to content

Instantly share code, notes, and snippets.

@mwalling
Created October 22, 2009 17:28
Show Gist options
  • Save mwalling/216109 to your computer and use it in GitHub Desktop.
Save mwalling/216109 to your computer and use it in GitHub Desktop.
from fabutils import needsDeployLocation, runAsAdmin
import os.path
@needsDeployLocation
@roles('www')
def deploy():
"""
Deploys code to production servers
"""
with cd(env.deploy_location):
put('dstarweb', 'dstarweb')
put('lib', 'lib')
# dont forget to merge the settings files
pass
@needsDeployLocation
@roles('www')
def dump_database():
"""
Dumps database to json fixture
"""
with cd(os.path.join(env.deploy_location, 'dstarweb')):
run('python manage.py dumpdata --format=json --indent=2 > fixtures/fulldump.json')
get(os.path.join(env.deploy_location, 'dstarweb', 'fixtures','fulldump.json'),
os.path.join(env.deploy_type, datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')+'.json'))
pass
pass
@needsDeployLocation
@roles('www')
def evolve_database():
"""
Evolves database to new schema
"""
with cd(os.path.join(env.deploy_location, 'dstarweb')):
run('python manage.py evolve --execute')
pass
pass
@needsDeployLocation
@roles('www')
def restartfcgi():
"""
Restarts django fastcgi on deployment servers
"""
pass
@runAsAdmin
@roles('www')
def restarthttpd():
"""
Restarts Lighttpd on production server
"""
pass
@runAsAdmin
@roles('www')
def updatedjango():
"""
Updates local django checkout and installs
"""
with cd('/usr/src/django'):
sudo('svn update')
sudo('python setup.py install')
pass
restartfcgi()
pass
from __future__ import with_statement
from fabric.context_managers import settings
from fabric.state import env
from fabric.utils import abort
import functools
def needsDeployLocation(func):
@functools.wraps(func)
def checkDeploySet(*args,**kwargs):
if env.deploy_location is None:
abort("Need to specify production or staging enviroment")
else:
return func(*args, **kwargs)
return checkDeploySet
class runAsAdmin(object):
"""
Changes to a user who has sudo privs
"""
def __init__(self, f):
self.f = f
def __call__(self, *args, **kwargs):
with settings(user='wallinma'):
self.f(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment