Skip to content

Instantly share code, notes, and snippets.

@jacquesbh
Created September 14, 2014 16:24
Show Gist options
  • Save jacquesbh/349c538bdbf179fd333b to your computer and use it in GitHub Desktop.
Save jacquesbh/349c538bdbf179fd333b to your computer and use it in GitHub Desktop.
Article Fabric and Magento • http://jacques.sh/2014/09/fabric-magento.html
@task
def backup():
""" Backup Backup Backup """
if not _has_tag('backup'):
abort("Hum… What are you doing? Dude, this server is not allowed to backup!")
# Clean cache
if _has_tag('redis'):
run('redis-cli -n 0 flushdb')
@task
@parallel
def deploy():
""" Deploy Deploy Deploy """
# Pull the sources
with cd('/var/www/www.mon-projet.net/')
run('git pull')
# Clean cache
run('redis-cli -n 0 flushdb')
# Reindex
with cd('/var/www/www.mon-projet.net/shell/')
run('php indexer.php reindexall')
@task
@parallel
def deploy():
""" Deploy Deploy Deploy """
# pull the project
if _has_tag('www'):
with cd(_get_setting('path')):
run('git pull')
# clean the cache
if _has_tag('redis'):
run('redis-cli -n 0 flushdb')
# reindex
if _has_tag('database'):
with cd(_get_setting('path') + 'shell/'):
run('php indexer.php reindexall')
def _get_setting(setting=False,host=False):
""" Returns the host's settings (or the specified one) """
if not host:
host = env.host
settings = env.settings_by_host[host]
if not setting:
return settings
return settings[setting]
def _has_tag(tag, host=False):
""" Returns if the host has the tag """
tags = _get_setting('tags', host).split(' ')
return (tag in tags)
# Hosts
env.hosts = ['www-data@back.mon-projet.net:22', 'www-data@front.mon-projet.net:22']
# Settings
env.settings_by_host = {
'front.mon-projet.net': {
'tags': 'www',
'path': '/var/www/www.mon-projet.net/'
},
'back.mon-projet.net': {
'tags': 'www redis database',
'path': '/var/www/admin.mon-projet.net/'
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment