2016-04-07 15:03:22 +02:00
|
|
|
#!/usr/bin/env python
|
2016-03-10 17:15:34 +01:00
|
|
|
from __future__ import print_function
|
2012-08-31 20:16:50 +02:00
|
|
|
import os
|
2016-07-24 19:21:04 +02:00
|
|
|
from six.moves import configparser # type: ignore # https://github.com/python/typeshed/issues/307
|
2012-08-31 20:16:50 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2013-04-09 21:18:54 +02:00
|
|
|
import logging
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2016-07-24 19:21:04 +02:00
|
|
|
config_file = configparser.RawConfigParser()
|
2016-07-20 05:42:17 +02:00
|
|
|
config_file.read("/etc/zulip/zulip.conf")
|
|
|
|
|
|
|
|
ZULIP_COM = config_file.get('machine', 'deploy_type') in ['zulip.com-prod',
|
|
|
|
'zulip.com-staging']
|
2016-07-20 05:59:39 +02:00
|
|
|
if ZULIP_COM:
|
|
|
|
git_url = "git@git.zulip.net:eng/zulip.git"
|
|
|
|
else:
|
|
|
|
git_url = config_file.get('deployment', 'git_repo_url')
|
2016-07-20 05:42:17 +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__), '..'))
|
2016-01-10 20:58:11 +01:00
|
|
|
from zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
|
|
|
|
get_deployment_lock, release_deployment_lock
|
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:
|
2016-03-10 17:15:34 +01:00
|
|
|
print(FAIL + "Usage: update-deployment refname" + ENDC)
|
2013-07-02 17:17:16 +02:00
|
|
|
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
|
|
|
|
2016-01-10 20:58:11 +01:00
|
|
|
error_rerun_script = "%s/current/tools/update-deployment %s" % (DEPLOYMENTS_DIR, refname)
|
|
|
|
get_deployment_lock(error_rerun_script)
|
2013-05-13 21:46:01 +02:00
|
|
|
|
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")
|
2016-07-20 05:59:39 +02:00
|
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname, git_url, 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)
|
2016-07-13 23:21:31 +02:00
|
|
|
|
2016-07-20 05:42:43 +02:00
|
|
|
if ZULIP_COM:
|
|
|
|
# Install the zulip.com settings (local_settings.py) as prod_settings.py
|
|
|
|
subprocess.check_call(["ln", "-nsf", os.path.join(deploy_path, "zproject/local_settings.py"),
|
|
|
|
os.path.join(deploy_path, "zproject/prod_settings.py")])
|
2016-07-20 05:55:58 +02:00
|
|
|
else:
|
|
|
|
# Install the prod_settings.py symlink
|
|
|
|
subprocess.check_call(["ln", "-nsf", "/etc/zulip/settings.py",
|
|
|
|
os.path.join(deploy_path, "zproject/prod_settings.py")])
|
2016-07-20 05:42:43 +02:00
|
|
|
|
2016-07-19 08:57:46 +02:00
|
|
|
subprocess.check_call(["sudo", os.path.join(deploy_path, "scripts", "lib", "create-production-venv"),
|
2016-07-13 23:21:31 +02:00
|
|
|
os.path.join(deploy_path, "zulip-venv")])
|
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
# Hack to deploy images not included in open source project
|
2016-07-19 06:58:10 +02:00
|
|
|
if os.path.exists("/etc/zulip/zulip-dropbox.png"):
|
|
|
|
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:
|
2016-01-10 20:58:11 +01:00
|
|
|
release_deployment_lock()
|