Created
April 14, 2016 12:07
-
-
Save 607011/dfbb239b3ce8ff42900d0950148109b4 to your computer and use it in GitHub Desktop.
Git post-receive hook to deploy latest release to a given directory
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys, os, subprocess | |
from datetime import datetime | |
oldrev, newrev, branch = sys.stdin.read().split() | |
refs, head, branch = branch.split('/') | |
deploy_to = None | |
# change deploy_to to path to directory where to deploy to | |
if branch == 'master': | |
deploy_to = '/var/www/myproject' | |
elif branch == 'dev': | |
deploy_to = '/var/www/myproject-dev' | |
if deploy_to is not None: | |
with open('%s/deployment.log' % (deploy_to), 'a') as f: | |
f.write('[%s] updated %s from %s to %s\n' | |
% (datetime.now().isoformat(), | |
branch, oldrev, newrev)) | |
subprocess.call( | |
'GIT_WORK_TREE=%s git checkout -f %s' | |
% (deploy_to, branch), shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment