-
-
Save hzbd/5446080 to your computer and use it in GitHub Desktop.
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.utils import abort | |
| from fabric.contrib.project import rsync_project | |
| from fabric.contrib.files import exists | |
| env.hosts = ['[email protected]'] | |
| target_dir = '/var/www/igor.io' | |
| backup_dir = target_dir+'-backup' | |
| staging_dir = target_dir+'-staging' | |
| def deploy(): | |
| puts('> Cleaning up previous backup and staging dir') | |
| run('rm -rf %s %s' % (backup_dir, staging_dir)) | |
| puts('> Preparing staging') | |
| run('cp -r %s %s' % (target_dir, staging_dir)) | |
| puts('> Uploading changes') | |
| with cd(staging_dir): | |
| extra_opts = '--omit-dir-times' | |
| rsync_project( | |
| env.cwd, | |
| './', | |
| delete=True, | |
| exclude=['.git', '*.pyc'], | |
| extra_opts=extra_opts, | |
| ) | |
| puts('> Switching changes to live') | |
| run('mv %s %s' % (target_dir, backup_dir)) | |
| run('mv %s %s' % (staging_dir, target_dir)) | |
| def rollback(): | |
| if exists(backup_dir): | |
| puts('> Rolling back to previous deploy') | |
| run('mv %s %s' % (target_dir, staging_dir)) | |
| run('mv %s %s' % (backup_dir, target_dir)) | |
| else: | |
| abort('Rollback failed, no backup exists') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment