Skip to content

Commit 59ce0bd

Browse files
committed
Add fabfile for deployment
1 parent ffa6ae0 commit 59ce0bd

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/output_*/
66
/source/components/
77
/vendor/
8+
*.pyc
89
publish.sh

fabfile.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from fabric.api import *
2+
from fabric.utils import abort
3+
from fabric.contrib.project import rsync_project
4+
from fabric.contrib.files import exists
5+
6+
if not env.hosts:
7+
env.hosts = ['www-data@igor.io']
8+
9+
project_name = 'stackphp.com'
10+
target_dir = '/var/www/'+project_name
11+
backup_dir = target_dir+'-backup'
12+
staging_dir = target_dir+'-staging'
13+
14+
@task(default=True)
15+
def deploy():
16+
puts('> Cleaning up previous backup and staging dir')
17+
run('rm -rf %s %s' % (backup_dir, staging_dir))
18+
19+
puts('> Preparing staging')
20+
run('cp -r %s %s' % (target_dir, staging_dir))
21+
22+
puts('> Uploading changes')
23+
with cd(staging_dir):
24+
with hide('stdout'):
25+
extra_opts = '--omit-dir-times'
26+
rsync_project(
27+
env.cwd,
28+
'./',
29+
delete=True,
30+
exclude=['.git', '*.pyc'],
31+
extra_opts=extra_opts,
32+
)
33+
34+
puts('> Switching changes to live')
35+
run('mv %s %s' % (target_dir, backup_dir))
36+
run('mv %s %s' % (staging_dir, target_dir))
37+
38+
@task
39+
def rollback():
40+
if exists(backup_dir):
41+
puts('> Rolling back to previous deploy')
42+
run('mv %s %s' % (target_dir, staging_dir))
43+
run('mv %s %s' % (backup_dir, target_dir))
44+
else:
45+
abort('Rollback failed, no backup exists')
46+
47+
@task
48+
def reload():
49+
puts('> Reloading nginx and php5-fpm')
50+
run('service nginx reload')
51+
run('service php5-fpm reload')
52+
53+
@task
54+
def restart():
55+
puts('> Restarting nginx and php5-fpm')
56+
run('service nginx restart')
57+
run('service php5-fpm restart')

0 commit comments

Comments
 (0)