mirror of https://github.com/zulip/zulip.git
71 lines
2.6 KiB
Plaintext
71 lines
2.6 KiB
Plaintext
|
#!/usr/bin/env python
|
||
|
from __future__ import print_function
|
||
|
import os
|
||
|
from six.moves import configparser # type: ignore # https://github.com/python/typeshed/issues/307
|
||
|
import sys
|
||
|
import subprocess
|
||
|
import logging
|
||
|
|
||
|
config_file = configparser.RawConfigParser()
|
||
|
config_file.read("/etc/zulip/zulip.conf")
|
||
|
|
||
|
ZULIP_COM = config_file.get('machine', 'deploy_type') in ['zulip.com-prod',
|
||
|
'zulip.com-staging']
|
||
|
if ZULIP_COM:
|
||
|
git_url = "git@git.zulip.net:eng/zulip.git"
|
||
|
else:
|
||
|
git_url = config_file.get('deployment', 'git_repo_url')
|
||
|
|
||
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
||
|
|
||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||
|
from zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
|
||
|
get_deployment_lock, release_deployment_lock
|
||
|
|
||
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
||
|
level=logging.INFO)
|
||
|
|
||
|
if len(sys.argv) != 2:
|
||
|
print(FAIL + "Usage: update-deployment refname" + ENDC)
|
||
|
sys.exit(1)
|
||
|
|
||
|
refname = sys.argv[1]
|
||
|
|
||
|
subprocess.check_call(["mkdir", '-p',
|
||
|
DEPLOYMENTS_DIR,
|
||
|
'/home/zulip/logs'])
|
||
|
|
||
|
error_rerun_script = "%s/current/tools/update-deployment %s" % (DEPLOYMENTS_DIR, refname)
|
||
|
get_deployment_lock(error_rerun_script)
|
||
|
|
||
|
try:
|
||
|
deploy_path = make_deploy_path()
|
||
|
|
||
|
logging.info("Cloning the repository")
|
||
|
subprocess.check_call(["git", "clone", "-q", "-b", refname, git_url, deploy_path],
|
||
|
stdout=open('/dev/null', 'w'))
|
||
|
|
||
|
os.chdir(deploy_path)
|
||
|
|
||
|
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")])
|
||
|
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")])
|
||
|
|
||
|
# Hack to deploy images not included in open source project
|
||
|
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")])
|
||
|
|
||
|
subprocess.check_call(["sudo", os.path.join(deploy_path, "scripts", "lib", "upgrade-zulip-stage-2"),
|
||
|
deploy_path, "--skip-migrations", "--skip-puppet", "--from-git"])
|
||
|
|
||
|
logging.info("Deployment complete")
|
||
|
subprocess.check_call(["./scripts/purge-old-deployments"])
|
||
|
finally:
|
||
|
release_deployment_lock()
|