Skip to content

Instantly share code, notes, and snippets.

@burlresearch
Created December 17, 2015 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burlresearch/4812c0e8508c131ae28e to your computer and use it in GitHub Desktop.
Save burlresearch/4812c0e8508c131ae28e to your computer and use it in GitHub Desktop.
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