py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-07-28 21:13:31 +02:00
|
|
|
import os
|
2017-02-19 02:01:01 +01:00
|
|
|
from six.moves import configparser
|
2016-07-28 21:13:31 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import logging
|
|
|
|
|
|
|
|
config_file = configparser.RawConfigParser()
|
|
|
|
config_file.read("/etc/zulip/zulip.conf")
|
2016-07-28 22:04:19 +02:00
|
|
|
LOCAL_GIT_CACHE_DIR = '/srv/zulip.git'
|
2016-07-28 21:13:31 +02:00
|
|
|
|
2016-07-29 00:43:32 +02:00
|
|
|
try:
|
2016-07-28 21:13:31 +02:00
|
|
|
git_url = config_file.get('deployment', 'git_repo_url')
|
2016-07-29 00:43:32 +02:00
|
|
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
|
|
git_url = "https://github.com/zulip/zulip.git"
|
2016-07-31 02:56:30 +02:00
|
|
|
try:
|
|
|
|
deploy_options = config_file.get('deployment', 'deploy_options').strip().split()
|
|
|
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
|
|
deploy_options = []
|
2016-07-28 21:13:31 +02:00
|
|
|
|
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
2016-08-13 17:46:19 +02:00
|
|
|
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
|
2016-07-28 22:04:19 +02:00
|
|
|
get_deployment_lock, release_deployment_lock, su_to_zulip
|
2016-07-28 21:13:31 +02:00
|
|
|
|
2017-10-18 04:38:22 +02:00
|
|
|
logging.basicConfig(format="%(asctime)s upgrade-zulip-from-git: %(message)s",
|
2016-07-28 21:13:31 +02:00
|
|
|
level=logging.INFO)
|
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
2017-10-18 04:38:22 +02:00
|
|
|
print(FAIL + "Usage: upgrade-zulip-from-git refname" + ENDC)
|
2016-07-28 21:13:31 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
refname = sys.argv[1]
|
|
|
|
|
|
|
|
subprocess.check_call(["mkdir", '-p',
|
|
|
|
DEPLOYMENTS_DIR,
|
|
|
|
'/home/zulip/logs'])
|
|
|
|
|
2017-10-18 04:38:22 +02:00
|
|
|
error_rerun_script = "%s/current/scripts/upgrade-zulip-from-git %s" % (DEPLOYMENTS_DIR, refname)
|
2016-07-28 21:13:31 +02:00
|
|
|
get_deployment_lock(error_rerun_script)
|
|
|
|
|
|
|
|
try:
|
|
|
|
deploy_path = make_deploy_path()
|
2016-07-28 22:04:19 +02:00
|
|
|
if not os.path.exists(LOCAL_GIT_CACHE_DIR):
|
|
|
|
logging.info("Cloning the repository")
|
|
|
|
subprocess.check_call(["git", "clone", "-q", git_url, "--mirror", LOCAL_GIT_CACHE_DIR],
|
|
|
|
stdout=open('/dev/null', 'w'))
|
|
|
|
subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR])
|
|
|
|
|
|
|
|
logging.info("Fetching the latest commits")
|
|
|
|
os.chdir(LOCAL_GIT_CACHE_DIR)
|
2017-06-22 03:47:25 +02:00
|
|
|
subprocess.check_call(["git", "remote", "set-url", "origin", git_url], preexec_fn=su_to_zulip)
|
2016-07-28 22:04:19 +02:00
|
|
|
subprocess.check_call(["git", "fetch", "-q"], preexec_fn=su_to_zulip)
|
|
|
|
|
|
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname, LOCAL_GIT_CACHE_DIR, deploy_path],
|
|
|
|
stdout=open('/dev/null', 'w'),
|
|
|
|
preexec_fn=su_to_zulip)
|
2016-07-28 21:13:31 +02:00
|
|
|
os.chdir(deploy_path)
|
|
|
|
|
2017-07-29 07:33:42 +02:00
|
|
|
subprocess.check_call(["ln", "-nsf", "/etc/zulip/settings.py",
|
|
|
|
os.path.join(deploy_path, "zproject/prod_settings.py")])
|
2016-07-28 21:13:31 +02:00
|
|
|
|
2017-07-29 08:05:24 +02:00
|
|
|
subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "next")])
|
|
|
|
|
2016-07-28 21:13:31 +02:00
|
|
|
subprocess.check_call(["sudo", os.path.join(deploy_path, "scripts", "lib", "upgrade-zulip-stage-2"),
|
2016-07-31 02:56:30 +02:00
|
|
|
deploy_path, "--from-git"] + deploy_options)
|
2016-07-28 21:13:31 +02:00
|
|
|
finally:
|
|
|
|
release_deployment_lock()
|