zulip/tools/update-prod-static
Daniil Fadeev 2f203f4de1 emails: Inline CSS in emails in build_email.
Previously, we had an architecture where CSS inlining for emails was
done at provision time in inline_email_css.py. This was necessary
because the library we were using for this, Premailer, was extremely
slow, and doing the inlining for every outgoing email would have been
prohibitively expensive.

Now that we've migrated to a more modern library that inlines the
small amount of CSS we have into emails nearly instantly, we are able
to remove the complex architecture built to work around Premailer
being slow and just do the CSS inlining as the final step in sending
each individual email.

This has several significant benefits:

* Removes a fiddly provisioning step that made the edit/refresh cycle
  for modifying email templates confusing; there's no longer a CSS
  inlining step that, if you forget to do it, results in your testing a
  stale variant of the email templates.
* Fixes internationalization problems related to translators working
  with pre-CSS-inlined emails, and then Django trying to apply the
  translators to the post-CSS-inlined version.
* Makes the send_custom_email pipeline simpler and easier to improve.

Signed-off-by: Daniil Fadeev <fadeevd@zulip.com>
2023-04-05 12:22:29 -07:00

56 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Updates static files for production.
import os
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__), ".."))
from scripts.lib.setup_path import setup_path
setup_path()
# check for the venv
from tools.lib import sanity_check
sanity_check.check_venv(__file__)
os.environ["DJANGO_SETTINGS_MODULE"] = "zproject.settings"
os.environ["ZULIP_COLLECTING_STATIC"] = "1"
from django.conf import settings
from scripts.lib.node_cache import setup_node_modules
from scripts.lib.zulip_tools import assert_not_running_as_root, run
assert_not_running_as_root()
os.chdir(settings.DEPLOY_ROOT)
# Install node packages
setup_node_modules(production=True)
# Build emoji
run(["./tools/setup/emoji/build_emoji"])
# Copy over static files from the zulip_bots package
run(["./tools/setup/generate_zulip_bots_static_files.py"])
# Build pygments data
run(["./tools/setup/build_pygments_data"])
# Build time zone data
run(["./tools/setup/build_timezone_values"])
# Create webpack bundle
run(["./tools/webpack", "--quiet"])
# Collect the files that we're going to serve; this creates prod-static/serve.
run(["./manage.py", "collectstatic", "-v0", "--noinput"])
# Compile translation strings to generate `.mo` files.
run(["./manage.py", "compilemessages", "-v0"])
# Needed if PRODUCTION
os.makedirs("prod-static", exist_ok=True)