2016-07-01 07:34:58 +02:00
|
|
|
#!/usr/bin/env python
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2015-08-17 06:37:14 +02:00
|
|
|
import os
|
2015-08-20 02:46:50 +02:00
|
|
|
import sys
|
2015-08-19 04:18:08 +02:00
|
|
|
import logging
|
|
|
|
import platform
|
2016-04-06 20:12:32 +02:00
|
|
|
import subprocess
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
|
2016-07-02 22:15:55 +02:00
|
|
|
PY2 = sys.version_info[0] == 2
|
|
|
|
|
2016-06-27 23:50:38 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
sys.path.append(ZULIP_PATH)
|
2016-08-13 17:46:19 +02:00
|
|
|
from scripts.lib.zulip_tools import run, subprocess_text_output, OKBLUE, ENDC, WARNING
|
2016-06-22 18:17:46 +02:00
|
|
|
from scripts.lib.setup_venv import setup_virtualenv, VENV_DEPENDENCIES
|
2016-08-18 13:53:16 +02:00
|
|
|
from scripts.lib.node_cache import setup_node_modules
|
|
|
|
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2015-08-19 04:18:08 +02:00
|
|
|
SUPPORTED_PLATFORMS = {
|
|
|
|
"Ubuntu": [
|
|
|
|
"trusty",
|
2016-04-04 23:22:14 +02:00
|
|
|
"xenial",
|
2015-08-19 04:18:08 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2016-07-02 22:15:55 +02:00
|
|
|
PY2_VENV_PATH = "/srv/zulip-venv"
|
2016-04-24 18:31:09 +02:00
|
|
|
PY3_VENV_PATH = "/srv/zulip-py3-venv"
|
2016-07-09 09:08:41 +02:00
|
|
|
VAR_DIR_PATH = os.path.join(ZULIP_PATH, 'var')
|
|
|
|
LOG_DIR_PATH = os.path.join(VAR_DIR_PATH, 'log')
|
2016-07-16 16:13:17 +02:00
|
|
|
UPLOAD_DIR_PATH = os.path.join(VAR_DIR_PATH, 'uploads')
|
2016-07-09 19:01:36 +02:00
|
|
|
TEST_UPLOAD_DIR_PATH = os.path.join(VAR_DIR_PATH, 'test_uploads')
|
2016-07-13 10:49:26 +02:00
|
|
|
COVERAGE_DIR_PATH = os.path.join(VAR_DIR_PATH, 'coverage')
|
2016-07-16 16:44:41 +02:00
|
|
|
LINECOVERAGE_DIR_PATH = os.path.join(VAR_DIR_PATH, 'linecoverage-report')
|
2016-08-11 18:33:52 +02:00
|
|
|
NODE_TEST_COVERAGE_DIR_PATH = os.path.join(VAR_DIR_PATH, 'node-coverage')
|
2016-06-14 10:33:23 +02:00
|
|
|
|
2016-07-02 22:15:55 +02:00
|
|
|
if PY2:
|
|
|
|
VENV_PATH = PY2_VENV_PATH
|
|
|
|
else:
|
|
|
|
VENV_PATH = PY3_VENV_PATH
|
|
|
|
|
2016-07-19 17:32:32 +02:00
|
|
|
TRAVIS = "--travis" in sys.argv
|
|
|
|
PRODUCTION_TRAVIS = "--production-travis" in sys.argv
|
|
|
|
|
2016-04-06 19:09:16 +02:00
|
|
|
if not os.path.exists(os.path.join(ZULIP_PATH, ".git")):
|
|
|
|
print("Error: No Zulip git repository present!")
|
2015-11-01 17:11:06 +01:00
|
|
|
print("To setup the Zulip development environment, you should clone the code")
|
|
|
|
print("from GitHub, rather than using a Zulip production release tarball.")
|
2015-10-14 01:18:49 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2016-04-06 19:27:42 +02:00
|
|
|
if platform.architecture()[0] == '64bit':
|
|
|
|
arch = 'amd64'
|
|
|
|
elif platform.architecture()[0] == '32bit':
|
|
|
|
arch = "i386"
|
|
|
|
else:
|
|
|
|
logging.critical("Only x86 is supported; ping zulip-devel@googlegroups.com if you want another architecture.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-04-06 20:12:32 +02:00
|
|
|
# Ideally we wouldn't need to install a dependency here, before we
|
|
|
|
# know the codename.
|
2016-09-08 04:30:48 +02:00
|
|
|
subprocess.check_call(["sudo", "apt-get", "update"])
|
|
|
|
subprocess.check_call(["sudo", "apt-get", "install", "-y", "lsb-release", "software-properties-common"])
|
2016-07-12 16:55:20 +02:00
|
|
|
vendor = subprocess_text_output(["lsb_release", "-is"])
|
|
|
|
codename = subprocess_text_output(["lsb_release", "-cs"])
|
2016-04-06 19:27:42 +02:00
|
|
|
if not (vendor in SUPPORTED_PLATFORMS and codename in SUPPORTED_PLATFORMS[vendor]):
|
|
|
|
logging.critical("Unsupported platform: {} {}".format(vendor, codename))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-04-06 19:30:16 +02:00
|
|
|
POSTGRES_VERSION_MAP = {
|
|
|
|
"trusty": "9.3",
|
2016-04-04 23:22:14 +02:00
|
|
|
"xenial": "9.5",
|
2016-04-06 19:30:16 +02:00
|
|
|
}
|
|
|
|
POSTGRES_VERSION = POSTGRES_VERSION_MAP[codename]
|
|
|
|
|
2016-04-04 23:22:14 +02:00
|
|
|
UBUNTU_COMMON_APT_DEPENDENCIES = [
|
|
|
|
"closure-compiler",
|
|
|
|
"memcached",
|
|
|
|
"rabbitmq-server",
|
|
|
|
"redis-server",
|
|
|
|
"hunspell-en-us",
|
|
|
|
"supervisor",
|
|
|
|
"git",
|
2016-09-21 08:44:01 +02:00
|
|
|
"libssl-dev",
|
2016-04-04 23:22:14 +02:00
|
|
|
"yui-compressor",
|
|
|
|
"wget",
|
|
|
|
"ca-certificates", # Explicit dependency in case e.g. wget is already installed
|
|
|
|
"puppet", # Used by lint-all
|
|
|
|
"gettext", # Used by makemessages i18n
|
|
|
|
"curl", # Used for fetching PhantomJS as wget occasionally fails on redirects
|
|
|
|
"netcat", # Used for flushing memcached
|
2016-06-22 18:17:46 +02:00
|
|
|
] + VENV_DEPENDENCIES
|
2016-04-04 23:22:14 +02:00
|
|
|
|
|
|
|
APT_DEPENDENCIES = {
|
|
|
|
"trusty": UBUNTU_COMMON_APT_DEPENDENCIES + [
|
|
|
|
"postgresql-9.3",
|
2016-07-27 22:27:13 +02:00
|
|
|
"postgresql-9.3-tsearch-extras",
|
2016-08-26 02:25:53 +02:00
|
|
|
"postgresql-9.3-pgroonga",
|
2016-04-04 23:22:14 +02:00
|
|
|
],
|
|
|
|
"xenial": UBUNTU_COMMON_APT_DEPENDENCIES + [
|
|
|
|
"postgresql-9.5",
|
2016-07-27 22:27:13 +02:00
|
|
|
"postgresql-9.5-tsearch-extras",
|
2016-08-26 02:25:53 +02:00
|
|
|
"postgresql-9.5-pgroonga",
|
2016-04-04 23:22:14 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:30:16 +02:00
|
|
|
TSEARCH_STOPWORDS_PATH = "/usr/share/postgresql/%s/tsearch_data/" % (POSTGRES_VERSION,)
|
2015-08-17 06:37:14 +02:00
|
|
|
REPO_STOPWORDS_PATH = os.path.join(
|
|
|
|
ZULIP_PATH,
|
|
|
|
"puppet",
|
|
|
|
"zulip",
|
|
|
|
"files",
|
|
|
|
"postgresql",
|
|
|
|
"zulip_english.stop",
|
|
|
|
)
|
|
|
|
|
2015-08-21 03:06:18 +02:00
|
|
|
LOUD = dict(_out=sys.stdout, _err=sys.stderr)
|
|
|
|
|
2016-06-14 10:33:23 +02:00
|
|
|
|
2015-08-20 02:46:50 +02:00
|
|
|
def main():
|
2016-06-15 21:11:24 +02:00
|
|
|
# type: () -> int
|
2016-07-27 22:27:13 +02:00
|
|
|
|
|
|
|
# npm install and management commands expect to be run from the root of the
|
|
|
|
# project.
|
|
|
|
os.chdir(ZULIP_PATH)
|
|
|
|
|
2016-08-05 22:27:03 +02:00
|
|
|
run(["sudo", "./scripts/lib/setup-apt-repo"])
|
2016-09-14 03:33:42 +02:00
|
|
|
|
|
|
|
# Add groonga repository to get the pgroonga packages; retry if it fails :/
|
|
|
|
try:
|
|
|
|
run(["sudo", "add-apt-repository", "-y", "ppa:groonga/ppa"])
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print(WARNING + "`Could not add groonga; retrying..." + ENDC)
|
|
|
|
run(["sudo", "add-apt-repository", "-y", "ppa:groonga/ppa"])
|
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "apt-get", "update"])
|
2016-06-22 17:11:25 +02:00
|
|
|
run(["sudo", "apt-get", "-y", "install", "--no-install-recommends"] + APT_DEPENDENCIES[codename])
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-07-19 17:39:16 +02:00
|
|
|
if TRAVIS:
|
|
|
|
if PY2:
|
|
|
|
MYPY_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "mypy.txt")
|
2016-07-20 21:42:33 +02:00
|
|
|
setup_virtualenv(PY3_VENV_PATH, MYPY_REQS_FILE, patch_activate_script=True,
|
|
|
|
virtualenv_args=['-p', 'python3'])
|
2016-07-19 17:39:16 +02:00
|
|
|
DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py2_dev.txt")
|
2016-07-20 21:42:33 +02:00
|
|
|
setup_virtualenv(PY2_VENV_PATH, DEV_REQS_FILE, patch_activate_script=True)
|
2016-07-19 17:39:16 +02:00
|
|
|
else:
|
|
|
|
DEV_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "py3_dev.txt")
|
2016-07-20 21:42:33 +02:00
|
|
|
setup_virtualenv(VENV_PATH, DEV_REQS_FILE, patch_activate_script=True,
|
|
|
|
virtualenv_args=['-p', 'python3'])
|
2016-07-19 17:39:16 +02:00
|
|
|
else:
|
2016-07-21 01:56:50 +02:00
|
|
|
# Import tools/setup_venv.py instead of running it so that we get an
|
|
|
|
# activated virtualenv for the rest of the provisioning process.
|
|
|
|
from tools.setup import setup_venvs
|
|
|
|
setup_venvs.main()
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-05-03 02:55:35 +02:00
|
|
|
# Put Python2 virtualenv activation in our .bash_profile.
|
2015-08-20 02:46:50 +02:00
|
|
|
with open(os.path.expanduser('~/.bash_profile'), 'w+') as bash_profile:
|
|
|
|
bash_profile.writelines([
|
|
|
|
"source .bashrc\n",
|
|
|
|
"source %s\n" % (os.path.join(VENV_PATH, "bin", "activate"),),
|
|
|
|
])
|
2015-08-20 22:40:06 +02:00
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "cp", REPO_STOPWORDS_PATH, TSEARCH_STOPWORDS_PATH])
|
2015-08-20 22:40:06 +02:00
|
|
|
|
2016-07-09 09:08:41 +02:00
|
|
|
# create log directory `zulip/var/log`
|
|
|
|
run(["mkdir", "-p", LOG_DIR_PATH])
|
2016-07-16 16:13:17 +02:00
|
|
|
# create upload directory `var/uploads`
|
|
|
|
run(["mkdir", "-p", UPLOAD_DIR_PATH])
|
2016-07-09 19:01:36 +02:00
|
|
|
# create test upload directory `var/test_upload`
|
|
|
|
run(["mkdir", "-p", TEST_UPLOAD_DIR_PATH])
|
2016-07-13 10:49:26 +02:00
|
|
|
# create coverage directory`var/coverage`
|
|
|
|
run(["mkdir", "-p", COVERAGE_DIR_PATH])
|
2016-07-16 16:44:41 +02:00
|
|
|
# create linecoverage directory`var/linecoverage-report`
|
|
|
|
run(["mkdir", "-p", LINECOVERAGE_DIR_PATH])
|
2016-08-11 18:33:52 +02:00
|
|
|
# create linecoverage directory`var/node-coverage`
|
|
|
|
run(["mkdir", "-p", NODE_TEST_COVERAGE_DIR_PATH])
|
2016-07-09 09:08:41 +02:00
|
|
|
|
2016-05-26 12:28:45 +02:00
|
|
|
run(["tools/setup/download-zxcvbn"])
|
2016-05-26 13:34:48 +02:00
|
|
|
run(["tools/setup/emoji_dump/build_emoji"])
|
2016-10-05 11:13:19 +02:00
|
|
|
run(["scripts/setup/generate_secrets.py", "--development"])
|
2016-07-19 17:32:32 +02:00
|
|
|
if TRAVIS and not PRODUCTION_TRAVIS:
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "service", "rabbitmq-server", "restart"])
|
|
|
|
run(["sudo", "service", "redis-server", "restart"])
|
|
|
|
run(["sudo", "service", "memcached", "restart"])
|
2015-12-12 14:17:30 +01:00
|
|
|
elif "--docker" in sys.argv:
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "service", "rabbitmq-server", "restart"])
|
|
|
|
run(["sudo", "pg_dropcluster", "--stop", POSTGRES_VERSION, "main"])
|
|
|
|
run(["sudo", "pg_createcluster", "-e", "utf8", "--start", POSTGRES_VERSION, "main"])
|
|
|
|
run(["sudo", "service", "redis-server", "restart"])
|
|
|
|
run(["sudo", "service", "memcached", "restart"])
|
2016-07-19 17:32:32 +02:00
|
|
|
if not PRODUCTION_TRAVIS:
|
2016-06-22 17:45:17 +02:00
|
|
|
# These won't be used anyway
|
|
|
|
run(["scripts/setup/configure-rabbitmq"])
|
|
|
|
run(["tools/setup/postgres-init-dev-db"])
|
|
|
|
run(["tools/do-destroy-rebuild-database"])
|
|
|
|
run(["tools/setup/postgres-init-test-db"])
|
|
|
|
run(["tools/do-destroy-rebuild-test-database"])
|
|
|
|
run(["python", "./manage.py", "compilemessages"])
|
2016-09-21 08:44:01 +02:00
|
|
|
|
|
|
|
# Here we install nvm, node, and npm.
|
|
|
|
run(["sudo", "tools/setup/install-node"])
|
|
|
|
|
|
|
|
# This is a wrapper around `npm install`, which we run last since
|
|
|
|
# it can often fail due to network issues beyond our control.
|
2016-07-29 00:33:34 +02:00
|
|
|
try:
|
2016-09-28 09:27:13 +02:00
|
|
|
# Hack: We remove `node_modules` as root to work around an
|
|
|
|
# issue with the symlinks being improperly owned by root.
|
|
|
|
if os.path.islink("node_modules"):
|
|
|
|
run(["sudo", "rm", "-f", "node_modules"])
|
2016-07-29 00:33:34 +02:00
|
|
|
setup_node_modules()
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print(WARNING + "`npm install` failed; retrying..." + ENDC)
|
|
|
|
setup_node_modules()
|
2016-07-29 00:30:47 +02:00
|
|
|
|
|
|
|
print()
|
2016-08-11 20:43:30 +02:00
|
|
|
print(OKBLUE + "Zulip development environment setup succeeded!" + ENDC)
|
2016-01-26 02:59:30 +01:00
|
|
|
return 0
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2015-08-20 02:46:50 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|