Created
April 16, 2016 03:02
-
-
Save gdamdam/5832b22cc2da1fd5014e4d074fcd0a19 to your computer and use it in GitHub Desktop.
FABRIC: fabfile deployment app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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