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-06-05 00:17:32 +02:00
|
|
|
from humbug_tools import DEPLOYMENTS_DIR, LOCK_DIR, TIMESTAMP_FORMAT, FAIL, ENDC
|
2013-04-09 21:51:16 +02:00
|
|
|
import datetime
|
2013-05-13 21:46:01 +02:00
|
|
|
import shutil
|
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
|
|
|
if len(sys.argv) > 1:
|
|
|
|
oldrev = sys.argv[1]
|
|
|
|
newrev = sys.argv[2]
|
|
|
|
refname = sys.argv[3]
|
|
|
|
|
2013-05-13 21:47:09 +02:00
|
|
|
subprocess.check_call(["mkdir", '-p',
|
2013-05-15 23:11:37 +02:00
|
|
|
DEPLOYMENTS_DIR,
|
2013-05-13 21:47:09 +02:00
|
|
|
'/home/humbug/logs'])
|
2013-05-13 21:46:01 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(LOCK_DIR)
|
|
|
|
except OSError:
|
|
|
|
print FAIL + "Deployment already in progress. Please run\n" \
|
|
|
|
+ " update-deployment %s %s %s\n" % (oldrev, newrev, refname) \
|
|
|
|
+ "manually when the current deployment finishes." + ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-05-28 23:59:50 +02:00
|
|
|
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)
|
|
|
|
deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp)
|
|
|
|
|
2013-05-29 20:35:02 +02:00
|
|
|
logging.info("Cloning the repository")
|
2013-05-28 23:59:50 +02:00
|
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname,
|
|
|
|
"humbug@git.humbughq.com:/srv/git/humbug.git",
|
|
|
|
deploy_path], stdout=open('/dev/null', 'w'))
|
|
|
|
os.chdir(deploy_path)
|
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"])
|
|
|
|
|
|
|
|
logging.info("Restarting server...")
|
2013-05-28 23:59:50 +02:00
|
|
|
subprocess.check_call(["./tools/restart-server"])
|
2013-04-09 21:51:16 +02:00
|
|
|
|
2013-05-15 23:58:05 +02:00
|
|
|
logging.info("Deployment complete")
|
|
|
|
shutil.rmtree(LOCK_DIR)
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2013-05-15 23:58:05 +02:00
|
|
|
subprocess.check_call(["./tools/purge-deployments"])
|