Created
September 19, 2012 16:43
-
-
Save galvarado/3750693 to your computer and use it in GitHub Desktop.
fabfile
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
| from fabric.api import * | |
| from fabric.context_managers import hide | |
| def dev(): | |
| env.enviroment = 'dev' | |
| env.branch = 'dev' | |
| env.push_code = True | |
| env.collect_static = False | |
| env.resetdb = True | |
| env.syncdb = True | |
| env.migrate = True | |
| setup() | |
| def staging(): | |
| env.enviroment = 'staging' | |
| env.branch = 'dev' | |
| env.push_code = True | |
| env.collect_static = False | |
| env.resetdb = False | |
| env.syncdb = True | |
| env.migrate = True | |
| setup() | |
| def production(): | |
| env.enviroment = 'prod' | |
| env.branch = 'production' | |
| env.push_code = True | |
| env.collect_static = True | |
| env.resetdb = False | |
| env.syncdb = True | |
| env.migrate = True | |
| setup() | |
| def setup(): | |
| with hide('running', 'stdout', 'stderr'): | |
| # Get the app directory | |
| env.app_directory = local(""" | |
| while [ ! -e "fabfile.py" ]; do | |
| cd .. | |
| done | |
| manage_file=$(find . | grep manage.py | grep -v lib | grep -v build | head -1); | |
| echo ${manage_file%manage.py} | |
| """, capture=True) | |
| # Get the app name from the git remote name | |
| env.app_name = local(""" | |
| git remote -v | grep ^{enviroment} | head -1 | cut -d":" -f2 | cut -d"." -f1 | |
| """.format(**env), capture=True) | |
| env.managepy = '{app_directory}manage.py'.format(**env) | |
| def push_code(branch=None): | |
| if branch is not None: | |
| env.branch = branch | |
| command = 'git push --force {enviroment} {branch}:master'.format(**env) | |
| local(command) | |
| def resetdb(): | |
| command = 'heroku pg:reset DATABASE --confirm {app_name}'.format(**env) | |
| local(command) | |
| def syncdb(): | |
| command = 'heroku run python {managepy} syncdb --noinput --app={app_name}'.format(**env) | |
| local(command) | |
| def shell(): | |
| command = 'heroku run python {managepy} shell --app={app_name}'.format(**env) | |
| local(command) | |
| def migrate(): | |
| command = 'heroku run python {managepy} migrate --app={app_name}'.format(**env) | |
| local(command) | |
| def collect_static(): | |
| command = 'heroku run python {managepy} collectstatic --noinput --app={app_name}'.format(**env) | |
| local(command) | |
| def deploy(branch=None): | |
| # Pushing code to heroku | |
| if env.push_code: | |
| push_code(branch) | |
| # Resetting database | |
| if env.resetdb: | |
| resetdb() | |
| # Syncing database | |
| if env.syncdb: | |
| syncdb() | |
| # Running migrations | |
| if env.migrate: | |
| migrate() | |
| # Collecting static files | |
| if env.collect_static: | |
| collect_static() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment