From b6db14dacd9de662839ef361be9abdb7e95b8cb8 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Sun, 14 Nov 2021 13:42:06 -0500 Subject: [PATCH] Switching from Jammit to django-pipeline. Doesn't work yet, needs compressor hooked up and assets checked. --- ansible/deploy.yml | 2 +- config/requirements.txt | 1 + docker/newsblur_base_image.Dockerfile | 1 - newsblur_web/settings.py | 64 +++++++++++++++++++++++++-- node/favicons.js | 2 +- node/log.js | 2 +- node/newsblur.js | 2 +- node/original_page.js | 2 +- node/original_text.js | 2 +- node/unread_counts.js | 2 +- templates/base.html | 5 ++- utils/templatetags/utils_tags.py | 19 ++++---- 12 files changed, 82 insertions(+), 22 deletions(-) diff --git a/ansible/deploy.yml b/ansible/deploy.yml index 2a4d83ea0..652a830e1 100644 --- a/ansible/deploy.yml +++ b/ansible/deploy.yml @@ -1,6 +1,6 @@ --- - import_playbook: playbooks/deploy_app.yml - when: "'app' in group_names" + when: "'app' in group_names or 'staging' in group_names" - import_playbook: playbooks/deploy_www.yml when: "'haproxy' in group_names" - import_playbook: playbooks/deploy_node.yml diff --git a/config/requirements.txt b/config/requirements.txt index d67419bbd..4feebdffa 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -27,6 +27,7 @@ django-nose==1.4.7 django-oauth-toolkit==1.3.3 django-paypal==1.0.0 django-qurl==0.1.1 +django-pipeline>=2,<3 django-redis-cache==3.0.0 django-redis-sessions==0.6.1 django-ses==1.0.3 diff --git a/docker/newsblur_base_image.Dockerfile b/docker/newsblur_base_image.Dockerfile index f75d2c271..2827924bb 100644 --- a/docker/newsblur_base_image.Dockerfile +++ b/docker/newsblur_base_image.Dockerfile @@ -10,7 +10,6 @@ RUN set -ex \ && buildDeps=' \ patch \ gfortran \ - lib32ncurses5-dev \ libblas-dev \ libffi-dev \ libjpeg-dev \ diff --git a/newsblur_web/settings.py b/newsblur_web/settings.py index 0e563418a..7d095b1b6 100644 --- a/newsblur_web/settings.py +++ b/newsblur_web/settings.py @@ -1,5 +1,6 @@ import sys import os +import yaml # =========================== # = Directory Declaractions = @@ -35,7 +36,6 @@ import django.http import re from mongoengine import connect import boto3 -from utils import jammit # =================== # = Server Settings = @@ -80,10 +80,8 @@ MEDIA_URL = '/media/' if DEBUG: STATIC_URL = '/static/' - STATIC_ROOT = '/static/static_root/' else: STATIC_URL = '/media/' - STATIC_ROOT = '/media/' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a @@ -311,6 +309,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.messages', + 'django.contrib.staticfiles', 'django_extensions', 'paypal.standard.ipn', 'apps.rss_feeds', @@ -335,6 +334,7 @@ INSTALLED_APPS = ( 'anymail', 'oauth2_provider', 'corsheaders', + 'pipeline', ) # ========== @@ -777,7 +777,63 @@ accept_content = ['pickle', 'json', 'msgpack', 'yaml'] # = Assets = # ========== -JAMMIT = jammit.JammitAssets(ROOT_DIR) +STATICFILES_STORAGE = 'pipeline.storage.PipelineManifestStorage' +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'pipeline.finders.PipelineFinder', +) +STATICFILES_DIRS = ( + MEDIA_ROOT, +) +with open(os.path.join(ROOT_DIR, 'assets.yml')) as stream: + assets = yaml.safe_load(stream) + +PIPELINE = { + 'PIPELINE_ENABLED': not DEBUG_ASSETS, + 'CSS_COMPRESSOR': 'pipeline.compressors.NoopCompressor', + 'JS_COMPRESSOR': 'pipeline.compressors.NoopCompressor', + 'JAVASCRIPT': { + 'common': { + 'source_filenames': assets['javascripts']['common'], + 'output_filename': 'static/js/common.js', + }, + 'statistics': { + 'source_filenames': assets['javascripts']['statistics'], + 'output_filename': 'static/js/statistics.js', + }, + 'payments': { + 'source_filenames': assets['javascripts']['payments'], + 'output_filename': 'static/js/payments.js', + }, + 'bookmarklet': { + 'source_filenames': assets['javascripts']['bookmarklet'], + 'output_filename': 'static/js/bookmarklet.js', + }, + 'blurblog': { + 'source_filenames': assets['javascripts']['blurblog'], + 'output_filename': 'static/js/blurblog.js', + }, + }, + 'STYLESHEETS': { + 'common': { + 'source_filenames': assets['stylesheets']['common'], + 'output_filename': 'static/css/common.css', + }, + 'mobile': { + 'source_filenames': assets['stylesheets']['mobile'], + 'output_filename': 'static/css/mobile.css', + }, + 'bookmarklet': { + 'source_filenames': assets['stylesheets']['bookmarklet'], + 'output_filename': 'static/css/bookmarklet.css', + }, + 'blurblog': { + 'source_filenames': assets['stylesheets']['blurblog'], + 'output_filename': 'static/css/blurblog.css', + }, + } +} # ======= # = AWS = diff --git a/node/favicons.js b/node/favicons.js index f03b3fafe..bee28e0c7 100644 --- a/node/favicons.js +++ b/node/favicons.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.6.1 (function() { var favicons, log, mongo; diff --git a/node/log.js b/node/log.js index 885921c48..25bdb0b36 100644 --- a/node/log.js +++ b/node/log.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.6.1 (function() { var debug, info; diff --git a/node/newsblur.js b/node/newsblur.js index 341c105fa..c71da6594 100644 --- a/node/newsblur.js +++ b/node/newsblur.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.6.1 (function() { var ENV_DEV, ENV_DOCKER, ENV_PROD, Sentry, Tracing, app, envresult, favicons, log, original_page, original_text, server, unread_counts; diff --git a/node/original_page.js b/node/original_page.js index 35789da05..5c611cbeb 100644 --- a/node/original_page.js +++ b/node/original_page.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.6.1 (function() { var busboy, fs, log, mkdirp, original_page, path; diff --git a/node/original_text.js b/node/original_text.js index c036cf273..437565464 100644 --- a/node/original_text.js +++ b/node/original_text.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.6.1 (function() { var Mercury, log, original_text; diff --git a/node/unread_counts.js b/node/unread_counts.js index e69e99f4d..a9874544e 100644 --- a/node/unread_counts.js +++ b/node/unread_counts.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.6.1 (function() { var fs, log, redis, unread_counts; diff --git a/templates/base.html b/templates/base.html index 6f96e89bb..25cdaf36e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,5 +1,6 @@ {% load utils_tags %} -{% load static%} +{% load static %} +{% load pipeline %} {% autoescape off %} @@ -118,7 +119,7 @@ NEWSBLUR.app = {}; - {% include_stylesheets "common" %} + {% stylesheet "common" %} {% if debug %} diff --git a/utils/templatetags/utils_tags.py b/utils/templatetags/utils_tags.py index cabfaf409..7bd0a55d2 100644 --- a/utils/templatetags/utils_tags.py +++ b/utils/templatetags/utils_tags.py @@ -8,6 +8,7 @@ from apps.social.models import MSocialProfile from vendor.timezones.utilities import localtime_for_timezone from utils.user_functions import get_user from django.utils.safestring import mark_safe +from pipeline.templatetags.pipeline import stylesheet, javascript register = template.Library() @@ -212,15 +213,17 @@ def commify(n): return out -@register.simple_tag -def include_javascripts(asset_package): +@register.tag +def include_javascripts(parser, token): """Prints out a template of