Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fabric fabfile for Django/Heroku App
from fabric.api import env, local, require
def deploy():
"""fab [environment] deploy"""
require('environment')
maintenance_on()
push()
syncdb()
migrate()
maintenance_off()
ps()
def maintenance_on():
"""fab [environment] maintenance_on"""
require('environment')
local('heroku maintenance:on --remote %s' % env.environment)
def maintenance_off():
"""fab [environment] maintenance_off"""
require('environment')
local('heroku maintenance:off --remote %s' % env.environment)
def push():
"""fab [environment] push"""
require('environment')
local('git push %s master' % env.environment)
def syncdb():
"""fab [environment] syncdb"""
require('environment')
if(env.environment == "development"):
local('foreman run python manage.py syncdb')
else:
local('heroku run python manage.py syncdb --remote %s' % env.environment)
def migrate(app=None):
"""fab [environment] migrate"""
require('environment')
if(env.environment == "development"):
if(app is not None):
local('foreman run python manage.py migrate %s' % app)
else:
local('foreman run python manage.py migrate')
else:
if(app is not None):
local('heroku run python manage.py migrate %s --remote %s' % (app, env.environment))
else:
local('heroku run python manage.py migrate --remote %s' % env.environment)
def schemamigration(app):
"""fab schemamigration:[app]"""
local('foreman run "python manage.py schemamigration %s --auto"' % app)
def ps():
"""fab [environment] ps"""
require('environment')
local('heroku ps --remote %s' % env.environment)
def open():
"""fab [environment] open"""
require('environment')
local('heroku open --remote %s' % env.environment)
def development():
"""fab development [command]"""
env.environment = 'development'
def staging():
"""fab staging [command]"""
env.environment = 'staging'
def production():
"""fab production [command]"""
env.environment = 'production'
@alej0varas

This comment has been minimized.

Copy link

commented May 8, 2013

Hi, great gist!

I can't find any information about the --remote option you are using. Can you explain it please?

@teddyknox

This comment has been minimized.

Copy link

commented Aug 8, 2013

bump

@goldhand

This comment has been minimized.

Copy link

commented Oct 5, 2013

@alej0varas: It's for using a staging environment on heroku.

@ysim

This comment has been minimized.

Copy link

commented Oct 28, 2013

@agconti

This comment has been minimized.

Copy link

commented Nov 5, 2014

An updated version for django 1.7: https://gist.github.com/agconti/bee7007252a72f52751d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.