2015-11-16 17:40:32 +01:00
|
|
|
#!/usr/bin/env python2.7
|
2012-08-31 20:16:50 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2013-04-09 21:18:54 +02:00
|
|
|
import logging
|
2013-04-09 21:51:16 +02:00
|
|
|
import datetime
|
2013-05-13 21:46:01 +02:00
|
|
|
import shutil
|
2013-07-02 17:24:16 +02:00
|
|
|
import time
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2015-11-16 17:40:32 +01:00
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
|
2013-10-25 23:46:02 +02:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
2013-11-13 20:57:31 +01:00
|
|
|
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC, make_deploy_path
|
2013-10-25 23:20:40 +02:00
|
|
|
|
2013-04-09 21:18:54 +02:00
|
|
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
|
|
|
level=logging.INFO)
|
|
|
|
|
2013-07-02 17:17:16 +02:00
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print FAIL + "Usage: update-deployment refname" + ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
refname = sys.argv[1]
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2013-05-13 21:47:09 +02:00
|
|
|
subprocess.check_call(["mkdir", '-p',
|
2013-05-15 23:11:37 +02:00
|
|
|
DEPLOYMENTS_DIR,
|
2013-10-04 19:19:57 +02:00
|
|
|
'/home/zulip/logs'])
|
2013-05-13 21:46:01 +02:00
|
|
|
|
2013-07-02 17:24:16 +02:00
|
|
|
start_time = time.time()
|
|
|
|
got_lock = False
|
|
|
|
while time.time() - start_time < 300:
|
|
|
|
try:
|
|
|
|
os.mkdir(LOCK_DIR)
|
|
|
|
got_lock = True
|
|
|
|
break
|
|
|
|
except OSError:
|
|
|
|
print WARNING + "Another deployment in progress; waiting for lock..." + ENDC
|
2016-01-10 19:46:09 +01:00
|
|
|
time.sleep(3)
|
2013-07-02 17:24:16 +02:00
|
|
|
|
|
|
|
if not got_lock:
|
2013-05-13 21:46:01 +02:00
|
|
|
print FAIL + "Deployment already in progress. Please run\n" \
|
2013-10-31 18:44:49 +01:00
|
|
|
+ " %s/current/tools/update-deployment %s\n" % (DEPLOYMENTS_DIR, refname) \
|
2013-05-13 21:46:01 +02:00
|
|
|
+ "manually when the current deployment finishes." + ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
try:
|
|
|
|
deploy_path = make_deploy_path()
|
2013-05-28 23:59:50 +02:00
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
logging.info("Cloning the repository")
|
|
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname,
|
|
|
|
"git@git.zulip.net:eng/zulip.git",
|
|
|
|
deploy_path], stdout=open('/dev/null', 'w'))
|
2012-10-18 05:41:28 +02:00
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
os.chdir(deploy_path)
|
|
|
|
# Hack to deploy images not included in open source project
|
|
|
|
subprocess.check_call(["cp", "-a", "/etc/zulip/zulip-dropbox.png",
|
|
|
|
os.path.join(deploy_path, "static/images/logo")])
|
2013-04-09 21:18:54 +02:00
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
# Update static files
|
|
|
|
logging.info("Updating static files")
|
|
|
|
subprocess.check_call(["./tools/update-prod-static", "--prev-deploy",
|
|
|
|
os.path.join(DEPLOYMENTS_DIR, 'current')])
|
2013-04-09 21:51:16 +02:00
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
logging.info("Restarting server...")
|
|
|
|
subprocess.check_call(["./scripts/restart-server"])
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
logging.info("Deployment complete")
|
|
|
|
subprocess.check_call(["./scripts/purge-old-deployments"])
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(LOCK_DIR)
|