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
|
2013-01-30 23:11:34 +01:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
# Updates static files for production.
|
2013-01-30 23:11:34 +01:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
|
|
|
|
import os
|
2016-08-29 00:56:05 +02:00
|
|
|
import argparse
|
2018-07-18 23:50:16 +02:00
|
|
|
import shutil
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
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__), '..'))
|
2016-07-19 08:57:12 +02:00
|
|
|
import scripts.lib.setup_path_on_import
|
2013-08-06 22:51:47 +02:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
from django.conf import settings
|
2016-08-18 13:55:13 +02:00
|
|
|
from scripts.lib.node_cache import setup_node_modules
|
2018-06-01 01:45:18 +02:00
|
|
|
from scripts.lib.zulip_tools import run
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
|
2017-02-07 20:49:12 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2016-08-29 00:56:05 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--prev-deploy', metavar='DIR',
|
2016-12-11 14:30:45 +01:00
|
|
|
help='a previous deploy from which to reuse files if possible')
|
2017-01-24 07:19:25 +01:00
|
|
|
parser.add_argument('--authors-not-required', action='store_true', default=False,
|
|
|
|
help='Authors files need not be updated')
|
2016-08-29 00:56:05 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
prev_deploy = args.prev_deploy
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
|
|
|
|
os.chdir(settings.DEPLOY_ROOT)
|
2013-01-30 23:11:34 +01:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
# Redirect child processes' output to a log file (most recent run only).
|
2018-07-18 23:50:16 +02:00
|
|
|
os.makedirs("var/log", exist_ok=True)
|
2016-07-19 15:52:15 +02:00
|
|
|
fp = open('var/log/update-prod-static.log', 'w')
|
2013-06-27 18:56:02 +02:00
|
|
|
|
2015-10-26 17:16:26 +01:00
|
|
|
# Install node packages
|
2017-07-22 01:19:53 +02:00
|
|
|
setup_node_modules(production=True, stdout=fp, stderr=fp)
|
2015-10-26 17:16:26 +01:00
|
|
|
|
2017-01-28 21:12:01 +01:00
|
|
|
# Build emoji
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['./tools/setup/emoji/build_emoji'], stdout=fp, stderr=fp)
|
2017-01-28 21:12:01 +01:00
|
|
|
|
2017-09-16 14:30:57 +02:00
|
|
|
# Inline CSS in emails
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['./tools/inline-email-css'], stdout=fp, stderr=fp)
|
2017-09-16 14:30:57 +02:00
|
|
|
|
2017-09-17 02:14:56 +02:00
|
|
|
# Copy over static files from the zulip_bots package
|
2018-12-09 16:13:46 +01:00
|
|
|
run(['./tools/setup/generate_zulip_bots_static_files.py'], stdout=fp, stderr=fp)
|
2017-09-17 02:14:56 +02:00
|
|
|
|
2017-11-12 10:13:09 +01:00
|
|
|
# Generate custom icon webfont
|
2018-08-10 00:32:21 +02:00
|
|
|
run(['./tools/setup/generate-custom-icon-webfont'], stdout=fp, stderr=fp)
|
2017-11-12 10:13:09 +01:00
|
|
|
|
2017-04-26 09:32:46 +02:00
|
|
|
# Build pygment data
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['./tools/setup/build_pygments_data'], stdout=fp, stderr=fp)
|
2017-04-26 09:32:46 +02:00
|
|
|
|
2015-10-26 17:16:26 +01:00
|
|
|
# Compile Handlebars templates and minify JavaScript.
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['./tools/minify-js'] + (['--prev-deploy', prev_deploy] if prev_deploy else []),
|
|
|
|
stdout=fp, stderr=fp)
|
2013-01-30 23:11:34 +01:00
|
|
|
|
2017-03-20 16:56:39 +01:00
|
|
|
# Copy the KaTeX files outside node_modules
|
2018-07-18 23:50:16 +02:00
|
|
|
os.makedirs(os.path.join(settings.STATIC_ROOT, 'node_modules/katex/dist/'),
|
|
|
|
exist_ok=True)
|
2017-03-20 16:56:39 +01:00
|
|
|
|
2018-07-18 23:50:16 +02:00
|
|
|
shutil.copy('node_modules/katex/dist/katex.css',
|
|
|
|
os.path.join(settings.STATIC_ROOT, 'node_modules/katex/dist/'))
|
2017-03-20 16:56:39 +01:00
|
|
|
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['cp', '-R', 'node_modules/katex/dist/fonts',
|
|
|
|
os.path.join(settings.STATIC_ROOT, 'node_modules/katex/dist/fonts')],
|
|
|
|
stdout=fp, stderr=fp)
|
2017-03-20 16:56:39 +01:00
|
|
|
|
2018-01-12 23:15:17 +01:00
|
|
|
CSS_FILES = [
|
2017-09-02 19:17:24 +02:00
|
|
|
'node_modules/simplebar/dist/simplebar.css',
|
2018-01-12 23:15:17 +01:00
|
|
|
'node_modules/flatpickr/dist/flatpickr.css',
|
|
|
|
'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.css',
|
|
|
|
]
|
2017-03-11 08:09:30 +01:00
|
|
|
|
|
|
|
# Copy CSS files in node_modules to prod-static/serve
|
|
|
|
for css_file in CSS_FILES:
|
2018-07-18 23:50:16 +02:00
|
|
|
os.makedirs(os.path.join(settings.STATIC_ROOT, os.path.dirname(css_file)), exist_ok=True)
|
|
|
|
shutil.copyfile(css_file, os.path.join(settings.STATIC_ROOT, css_file))
|
2017-03-11 08:09:30 +01:00
|
|
|
|
2017-01-07 05:09:10 +01:00
|
|
|
# Collect the files that we're going to serve; this creates prod-static/serve.
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['./manage.py', 'collectstatic', '--no-default-ignore',
|
2019-03-04 17:28:45 +01:00
|
|
|
'--noinput', '-i', 'assets', '-i', 'node_modules', '-i', 'styles', '-i', 'templates'],
|
2018-06-01 01:45:18 +02:00
|
|
|
stdout=fp, stderr=fp)
|
|
|
|
|
2017-02-06 22:12:03 +01:00
|
|
|
if not settings.PRODUCTION:
|
|
|
|
# When building a release tarball, we need to move staticfiles.json
|
2018-07-18 23:50:16 +02:00
|
|
|
shutil.move('prod-static/serve/staticfiles.json', 'staticfiles.json')
|
2013-02-16 11:17:23 +01:00
|
|
|
|
2016-05-02 10:20:00 +02:00
|
|
|
# Compile translation strings to generate `.mo` files.
|
2018-06-01 01:45:18 +02:00
|
|
|
run(['./manage.py', 'compilemessages'], stdout=fp, stderr=fp)
|
2016-05-02 10:20:00 +02:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
# Move the source maps out of the serve/ directory and into their
|
|
|
|
# proper place.
|
2018-07-18 23:50:16 +02:00
|
|
|
if os.path.exists('prod-static/source-map'):
|
|
|
|
shutil.rmtree('prod-static/source-map')
|
2018-06-01 01:45:18 +02:00
|
|
|
|
|
|
|
# Needed if PRODUCTION
|
2018-07-18 23:50:16 +02:00
|
|
|
os.makedirs('prod-static', exist_ok=True)
|
2018-06-01 01:45:18 +02:00
|
|
|
|
2018-07-18 23:50:16 +02:00
|
|
|
shutil.move(os.path.join(settings.STATIC_ROOT, 'source-map'), 'prod-static/source-map')
|
2016-07-13 06:33:36 +02:00
|
|
|
|
2017-10-31 20:08:32 +01:00
|
|
|
# Generate /team page markdown for authors
|
2017-01-17 22:42:37 +01:00
|
|
|
authors_cmd = ['./tools/update-authors-json']
|
|
|
|
if os.environ.get("TRAVIS"):
|
|
|
|
authors_cmd.append("--use-fixture")
|
2017-01-24 07:19:25 +01:00
|
|
|
if args.authors_not_required:
|
|
|
|
authors_cmd.append("--not-required")
|
2018-06-01 01:45:18 +02:00
|
|
|
run(authors_cmd, stdout=fp, stderr=fp)
|
2017-01-06 18:56:36 +01:00
|
|
|
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
fp.close()
|