storage: Stop using django-pipeline.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-07-18 02:36:56 -07:00 committed by Tim Abbott
parent fd7803e7f4
commit 2b33822de9
7 changed files with 10 additions and 48 deletions

View File

@ -74,13 +74,11 @@ needs to be accessible from one of the entry points defined in
the compiled JS and CSS. the compiled JS and CSS.
If you want to test minified files in development, look for the If you want to test minified files in development, look for the
`PIPELINE_ENABLED =` line in `zproject/settings.py` and set it to `True` `DEBUG =` line in `zproject/settings.py` and set it to `False`.
-- or just set `DEBUG = False`.
## How it works in production ## How it works in production
You can learn a lot from reading about django-pipeline, but a few A few useful notes are:
useful notes are:
* Zulip installs static assets in production in * Zulip installs static assets in production in
`/home/zulip/prod-static`. When a new version is deployed, before the `/home/zulip/prod-static`. When a new version is deployed, before the
server is restarted, files are copied into that directory. server is restarted, files are copied into that directory.

View File

@ -8,8 +8,7 @@ main third-party CSS library.
Zulip currently does not use any CSS preprocessors, and is organized Zulip currently does not use any CSS preprocessors, and is organized
into several files. For most pages, the CSS is combined into a single into several files. For most pages, the CSS is combined into a single
CSS file by the [static asset pipeline](../subsystems/front-end-build-process.html), CSS file by the [static asset pipeline](../subsystems/front-end-build-process.html).
controlled by the `PIPELINE_CSS` code in `zproject/settings.py`.
The CSS files are: The CSS files are:

View File

@ -5,9 +5,8 @@ from typing import Optional
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
from pipeline.storage import PipelineMixin
if not settings.PIPELINE_ENABLED: if settings.DEBUG:
from django.contrib.staticfiles.finders import find from django.contrib.staticfiles.finders import find
def static_path(path: str) -> str: def static_path(path: str) -> str:
@ -44,8 +43,7 @@ class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage):
return name return name
return super().hashed_name(name, content, filename) return super().hashed_name(name, content, filename)
class ZulipStorage(PipelineMixin, class ZulipStorage(IgnoreBundlesManifestStaticFilesStorage):
IgnoreBundlesManifestStaticFilesStorage):
# This is a hack to use staticfiles.json from within the # This is a hack to use staticfiles.json from within the
# deployment, rather than a directory under STATIC_ROOT. By doing # deployment, rather than a directory under STATIC_ROOT. By doing
# so, we can use a different copy of staticfiles.json for each # so, we can use a different copy of staticfiles.json for each

View File

@ -81,9 +81,6 @@ class TemplateTestCase(ZulipTestCase):
'zerver/emails/compiled/password_reset.html', 'zerver/emails/compiled/password_reset.html',
'corporate/zephyr.html', 'corporate/zephyr.html',
'corporate/zephyr-mirror.html', 'corporate/zephyr-mirror.html',
'pipeline/css.jinja',
'pipeline/inline_js.jinja',
'pipeline/js.jinja',
'zilencer/enterprise_tos_accept_body.txt', 'zilencer/enterprise_tos_accept_body.txt',
'zerver/zulipchat_migration_tos.html', 'zerver/zulipchat_migration_tos.html',
'zilencer/enterprise_tos_accept_body.txt', 'zilencer/enterprise_tos_accept_body.txt',

View File

@ -288,7 +288,6 @@ def home_real(request: HttpRequest) -> HttpResponse:
'avatar_url': avatar_url(user_profile), 'avatar_url': avatar_url(user_profile),
'show_debug': 'show_debug':
settings.DEBUG and ('show_debug' in request.GET), settings.DEBUG and ('show_debug' in request.GET),
'pipeline': settings.PIPELINE_ENABLED,
'search_pills_enabled': settings.SEARCH_PILLS_ENABLED, 'search_pills_enabled': settings.SEARCH_PILLS_ENABLED,
'show_invites': show_invites, 'show_invites': show_invites,
'show_add_streams': show_add_streams, 'show_add_streams': show_add_streams,

View File

@ -11,7 +11,7 @@ import zerver.views.development.integrations
# These URLs are available only in the development environment # These URLs are available only in the development environment
use_prod_static = getattr(settings, 'PIPELINE_ENABLED', False) use_prod_static = not settings.DEBUG
urls = [ urls = [
# Serve useful development environment resources (docs, coverage reports, etc.) # Serve useful development environment resources (docs, coverage reports, etc.)

View File

@ -576,7 +576,6 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'confirmation', 'confirmation',
'pipeline',
'webpack_loader', 'webpack_loader',
'zerver', 'zerver',
'social_django', 'social_django',
@ -861,7 +860,7 @@ if CAMO_URI != '':
STATIC_URL = '/static/' STATIC_URL = '/static/'
# ZulipStorage is a modified version of PipelineCachedStorage, # ZulipStorage is a modified version of ManifestStaticFilesStorage,
# and, like that class, it inserts a file hash into filenames # and, like that class, it inserts a file hash into filenames
# to prevent the browser from using stale files from cache. # to prevent the browser from using stale files from cache.
# #
@ -869,16 +868,8 @@ STATIC_URL = '/static/'
# STATIC_ROOT even for dev servers. So we only use # STATIC_ROOT even for dev servers. So we only use
# ZulipStorage when not DEBUG. # ZulipStorage when not DEBUG.
# This is the default behavior from Pipeline, but we set it if not DEBUG:
# here so that urls.py can read it.
PIPELINE_ENABLED = not DEBUG
if PIPELINE_ENABLED:
STATICFILES_STORAGE = 'zerver.lib.storage.ZulipStorage' STATICFILES_STORAGE = 'zerver.lib.storage.ZulipStorage'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'pipeline.finders.PipelineFinder',
)
if PRODUCTION: if PRODUCTION:
STATIC_ROOT = '/home/zulip/prod-static' STATIC_ROOT = '/home/zulip/prod-static'
else: else:
@ -893,24 +884,7 @@ FILE_UPLOAD_MAX_MEMORY_SIZE = 0
STATICFILES_DIRS = ['static/'] STATICFILES_DIRS = ['static/']
# To use minified files in dev, set PIPELINE_ENABLED = True. For the full if DEBUG:
# cache-busting behavior, you must also set DEBUG = False.
#
# You will need to run update-prod-static after changing
# static files.
#
# Useful reading on how this works is in
# https://zulip.readthedocs.io/en/latest/subsystems/front-end-build-process.html
PIPELINE = {
'PIPELINE_ENABLED': PIPELINE_ENABLED,
'CSS_COMPRESSOR': 'pipeline.compressors.yui.YUICompressor',
'YUI_BINARY': '/usr/bin/env yui-compressor',
'STYLESHEETS': {},
'JAVASCRIPT': {},
}
if not PIPELINE_ENABLED:
WEBPACK_STATS_FILE = os.path.join('var', 'webpack-stats-dev.json') WEBPACK_STATS_FILE = os.path.join('var', 'webpack-stats-dev.json')
else: else:
WEBPACK_STATS_FILE = 'webpack-stats-production.json' WEBPACK_STATS_FILE = 'webpack-stats-production.json'
@ -942,7 +916,6 @@ base_template_engine_settings = {
'extensions': [ 'extensions': [
'jinja2.ext.i18n', 'jinja2.ext.i18n',
'jinja2.ext.autoescape', 'jinja2.ext.autoescape',
'pipeline.jinja2.PipelineExtension',
'webpack_loader.contrib.jinja2ext.WebpackExtension', 'webpack_loader.contrib.jinja2ext.WebpackExtension',
], ],
'context_processors': [ 'context_processors': [
@ -961,9 +934,7 @@ default_template_engine_settings.update({
# The webhook integration templates # The webhook integration templates
os.path.join(DEPLOY_ROOT, 'zerver', 'webhooks'), os.path.join(DEPLOY_ROOT, 'zerver', 'webhooks'),
# The python-zulip-api:zulip_bots package templates # The python-zulip-api:zulip_bots package templates
os.path.join( os.path.join('static' if DEBUG else STATIC_ROOT, 'generated', 'bots'),
STATIC_ROOT if PIPELINE_ENABLED else 'static', 'generated', 'bots'
),
], ],
'APP_DIRS': True, 'APP_DIRS': True,
}) })