Skip to content

Instantly share code, notes, and snippets.

@gdamdam
Created April 16, 2016 03:02
Show Gist options
  • Save gdamdam/5832b22cc2da1fd5014e4d074fcd0a19 to your computer and use it in GitHub Desktop.
Save gdamdam/5832b22cc2da1fd5014e4d074fcd0a19 to your computer and use it in GitHub Desktop.
FABRIC: fabfile deployment app
"""fabfile.py example
Deploy <APP_TO_DEPLOY>:
fab deploy:<APP_TO_DEPLOY>
"""
import os,sys
from fabric.api import local
from fabric.context_managers import lcd
# Make sure the current user is <USER>
if os.getenv("USER") != '<USER>':
print "Restarting the program as <USER> user"
fabfile = os.path.abspath(__file__)
if fabfile.endswith(".pyc"):
fabfile = fabfile[:-1]
args = "sudo -u <USER> ".split() + ["fab", "-f", fabfile] + sys.argv[1:]
os.execvp("sudo", args)
def deploy(name):
if name == '<APP_TO_DEPLOY>':
with lcd('/var/www/<LOCATION_APP_TO_DEPLOY>'):
local('git pull origin master')
else:
print "Deploy target unknown"
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment