Files
zulip/tools/update-prod-static
Greg Price a099e698e2 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-16 17:54:43 -07:00

112 lines
4.3 KiB
Python
Executable File

#!/usr/bin/env python3
# Updates static files for production.
from __future__ import absolute_import
import os
import subprocess
import argparse
import sys
# We need settings so we can figure out where the prod-static directory is.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import scripts.lib.setup_path_on_import
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings
from scripts.lib.node_cache import setup_node_modules
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
parser = argparse.ArgumentParser()
parser.add_argument('--prev-deploy', metavar='DIR',
help='a previous deploy from which to reuse files if possible')
parser.add_argument('--authors-not-required', action='store_true', default=False,
help='Authors files need not be updated')
args = parser.parse_args()
prev_deploy = args.prev_deploy
os.chdir(settings.DEPLOY_ROOT)
# Redirect child processes' output to a log file (most recent run only).
subprocess.check_call(["mkdir", "-p", "var/log"])
fp = open('var/log/update-prod-static.log', 'w')
# Install node packages
setup_node_modules(production=True, stdout=fp, stderr=fp)
# Build emoji
subprocess.check_call(['./tools/setup/emoji/build_emoji'],
stdout=fp, stderr=fp)
# Build pygment data
subprocess.check_call(['./tools/setup/build_pygments_data.py'],
stdout=fp, stderr=fp)
# Compile Handlebars templates and minify JavaScript.
subprocess.check_call(['./tools/minify-js'] +
(['--prev-deploy', prev_deploy] if prev_deploy else []),
stdout=fp, stderr=fp)
# Copy the KaTeX files outside node_modules
subprocess.check_call(['mkdir', '-p',
os.path.join(settings.STATIC_ROOT,
'node_modules/katex/dist/')],
stdout=fp, stderr=fp)
subprocess.check_call(['cp', 'node_modules/katex/dist/katex.css',
os.path.join(settings.STATIC_ROOT,
'node_modules/katex/dist/')],
stdout=fp, stderr=fp)
subprocess.check_call(['cp', '-R', 'node_modules/katex/dist/fonts',
os.path.join(settings.STATIC_ROOT,
'node_modules/katex/dist/fonts')],
stdout=fp, stderr=fp)
CSS_FILES = ['node_modules/perfect-scrollbar/dist/css/perfect-scrollbar.css']
# Copy CSS files in node_modules to prod-static/serve
for css_file in CSS_FILES:
subprocess.check_call(['cp', '--parents', css_file, settings.STATIC_ROOT])
# Collect the files that we're going to serve; this creates prod-static/serve.
subprocess.check_call(['./manage.py', 'collectstatic', '--no-default-ignore',
'--noinput', '-i', 'assets', '-i' 'node_modules'],
stdout=fp, stderr=fp)
if not settings.PRODUCTION:
# When building a release tarball, we need to move staticfiles.json
subprocess.check_call(['mv', 'prod-static/serve/staticfiles.json', 'staticfiles.json'],
stdout=fp, stderr=fp)
# Compile translation strings to generate `.mo` files.
subprocess.check_call(['./manage.py', 'compilemessages'],
stdout=fp, stderr=fp)
# Move the source maps out of the serve/ directory and into their
# proper place.
subprocess.check_call(['rm', '-rf', 'prod-static/source-map'],
stdout=fp, stderr=fp)
subprocess.check_call(['mkdir', '-p', 'prod-static'], # Needed if PRODUCTION
stdout=fp, stderr=fp)
subprocess.check_call(['mv', os.path.join(settings.STATIC_ROOT, 'source-map'),
'prod-static/source-map'],
stdout=fp, stderr=fp)
# Move language_options.json to the production release
subprocess.check_call(['cp', '-aT', 'static/locale',
os.path.join(settings.STATIC_ROOT, 'locale')],
stdout=fp, stderr=fp)
# Generate /about page markdown for authors
authors_cmd = ['./tools/update-authors-json']
if os.environ.get("TRAVIS"):
authors_cmd.append("--use-fixture")
if args.authors_not_required:
authors_cmd.append("--not-required")
subprocess.check_call(authors_cmd, stdout=fp, stderr=fp)
fp.close()