2013-02-19 01:00:54 +01:00
|
|
|
#!/usr/bin/env python
|
2012-08-31 20:16:50 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2012-11-26 22:49:00 +01:00
|
|
|
import pylibmc
|
|
|
|
import traceback
|
2013-04-09 21:18:54 +02:00
|
|
|
import logging
|
2013-02-19 02:36:59 +01:00
|
|
|
from humbug_tools import check_output
|
2013-04-09 21:51:16 +02:00
|
|
|
import datetime
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2013-04-09 21:18:54 +02:00
|
|
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
|
|
|
level=logging.INFO)
|
|
|
|
|
2012-08-31 20:16:50 +02:00
|
|
|
# Color codes
|
|
|
|
OKBLUE = '\033[94m'
|
|
|
|
OKGREEN = '\033[92m'
|
|
|
|
WARNING = '\033[93m'
|
|
|
|
FAIL = '\033[91m'
|
|
|
|
ENDC = '\033[0m'
|
|
|
|
|
|
|
|
os.chdir("/home/humbug/humbug")
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
oldrev = sys.argv[1]
|
|
|
|
newrev = sys.argv[2]
|
|
|
|
refname = sys.argv[3]
|
|
|
|
|
|
|
|
subprocess.check_call(["git", "fetch"], stdout=open('/dev/null', 'w'))
|
2012-11-06 17:09:07 +01:00
|
|
|
subprocess.check_call(["git", "reset", "--hard", refname], stdout=open('/dev/null', 'w'))
|
2012-10-18 05:41:28 +02:00
|
|
|
|
2013-04-09 21:18:54 +02:00
|
|
|
# Delete all .pyc files to avoid old module files hanging around
|
|
|
|
subprocess.check_call(["find", ".", "-name", "*.pyc", "-delete"], stdout=open('/dev/null', 'w'))
|
|
|
|
|
|
|
|
# Update static files
|
|
|
|
logging.info("Updating static files")
|
|
|
|
subprocess.check_call(["./tools/update-prod-static"])
|
|
|
|
|
2013-04-09 21:51:16 +02:00
|
|
|
subprocess.check_call(["mkdir", '-p', '/home/humbug/humbug-deployments'])
|
|
|
|
timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
|
|
|
|
deploy_path = "/home/humbug/humbug-deployments/%s" % (timestamp,)
|
|
|
|
subprocess.check_call(["cp", '-a', '/home/humbug/humbug', deploy_path])
|
|
|
|
subprocess.check_call(["ln", '-nsf', deploy_path, "/home/humbug/humbug-deployments/current"])
|
|
|
|
|
2013-04-09 21:18:54 +02:00
|
|
|
logging.info("Restarting server...")
|
2013-04-09 21:51:16 +02:00
|
|
|
subprocess.check_call(["/home/humbug/humbug-deployments/current/tools/restart-server"])
|
|
|
|
|
2012-08-31 20:16:50 +02:00
|
|
|
|
|
|
|
if newrev == '0000000000000000000000000000000000000000':
|
|
|
|
# 0000000000000000000000000000000000000000 means we're deleting the ref
|
|
|
|
commits = ''
|
|
|
|
else:
|
2013-02-19 02:36:59 +01:00
|
|
|
commits = check_output(["git", "log", "%s..%s" % (oldrev, newrev)])
|
2012-08-31 20:16:50 +02:00
|
|
|
|
|
|
|
if '[schema]' in commits:
|
|
|
|
print
|
|
|
|
print FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC
|
|
|
|
print
|