Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example Fabric build file with the ability to `build` and `deploy` to a variety of targets.
import os
from fabric.api import *
from fabric.context_managers import lcd
from fabric.contrib.project import rsync_project
@task
def build(composer_extra=""):
with lcd('src/private'):
local("composer install %s" % composer_extra)
with lcd('src'):
local("npm install")
local("gulp --production")
@task
def prod():
env.WEB_SRV_ID = 'nginx'
env.hosts.append('admin@example.com')
env.DEPLOY_TO = '/content/www/'
@task
def dev():
env.WEB_SRV_ID = 'admin'
env.hosts.append('admin@dev.example.com')
env.DEPLOY_TO = '/var/www/example/'
@task
def deploy():
if env.WEB_SRV_ID == 'nginx':
sudo('chmod -R g+w %s' % env.DEPLOY_TO)
rsync_project(
local_dir=os.getcwd() + '/src',
remote_dir=env.DEPLOY_TO,
extra_opts='--no-perms --omit-dir-times -l --exclude-from=%s/build/sync.ignore' % os.getcwd(),
exclude=[],
delete=True
)
if env.WEB_SRV_ID == 'nginx':
sudo('chown -R {0}:{0} {1}'.format(env.WEB_SRV_ID, env.DEPLOY_TO))
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.