From 89f85f1255598578126776372f41ceb8eaa0e5af Mon Sep 17 00:00:00 2001 From: James Williams Date: Tue, 11 Feb 2020 20:17:50 +0000 Subject: [PATCH 1/5] - configure compressor when not using s3 - update django start script to compress if using whitenoise and compress enabled - add to contributors.rst --- CONTRIBUTORS.rst | 1 + .../compose/production/django/start | 6 ++++++ .../config/settings/production.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 86804b69d..043312b03 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -129,6 +129,7 @@ Listed in alphabetical order. Irfan Ahmad `@erfaan`_ @erfaan Isaac12x `@Isaac12x`_ Ivan Khomutov `@ikhomutov`_ + James Williams `@jameswilliams1`_ Jan Van Bruggen `@jvanbrug`_ Jelmer Draaijer `@foarsitter`_ Jerome Caisip `@jeromecaisip`_ diff --git a/{{cookiecutter.project_slug}}/compose/production/django/start b/{{cookiecutter.project_slug}}/compose/production/django/start index 709c1dd04..a3aa1161c 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/start +++ b/{{cookiecutter.project_slug}}/compose/production/django/start @@ -6,4 +6,10 @@ set -o nounset python /app/manage.py collectstatic --noinput +{%- if cookiecutter.use_whitenoise == 'y' and cookiecutter.use_compressor == 'y' %} +if [ "${COMPRESS_ENABLED:-}" = "True" ]; +then + python /app/manage.py compress +fi +{%- endif %} /usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 36667b33a..a3e4b9c27 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -200,9 +200,27 @@ ANYMAIL = { # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True) # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE +{%- if cookiecutter.cloud_provider == 'AWS' %} COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" +{%- elif cookiecutter.cloud_provider == 'GCP' %} +COMPRESS_STORAGE = "storages.backends.gcloud.GoogleCloudStorage" +{%- elif cookiecutter.cloud_provider == 'None' %} +COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" +{%- endif %} # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' or cookiecutter.cloud_provider == 'None' %} # noqa F405{% endif %} +{%- if cookiecutter.use_whitenoise == 'y' %} +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE +COMPRESS_OFFLINE = True # Offline compression is required when using Whitenoise +{%- endif %} +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_FILTERS +COMPRESS_FILTERS = { + "css": [ + "compressor.filters.css_default.CssAbsoluteFilter", + "compressor.filters.cssmin.rCSSMinFilter", + ], + "js": ["compressor.filters.jsmin.JSMinFilter"], +} {% endif %} {%- if cookiecutter.use_whitenoise == 'n' -%} # Collectfast From e1cb30b699460dc8dbdef9587d20c8423d022b1a Mon Sep 17 00:00:00 2001 From: James Williams Date: Fri, 28 Feb 2020 16:08:20 +0000 Subject: [PATCH 2/5] fix broken contributors link --- CONTRIBUTORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 043312b03..beba320bf 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -299,6 +299,7 @@ Listed in alphabetical order. .. _@howiezhao: https://github.com/howiezhao .. _@IanLee1521: https://github.com/IanLee1521 .. _@ikhomutov: https://github.com/ikhomutov +.. _@jameswilliams1: https://github.com/jameswilliams1 .. _@ikkebr: https://github.com/ikkebr .. _@Isaac12x: https://github.com/Isaac12x .. _@iynaix: https://github.com/iynaix From d3db7a867fbf58b80ceea4dc05829a2fcbbdbe60 Mon Sep 17 00:00:00 2001 From: James Williams Date: Fri, 28 Feb 2020 17:04:15 +0000 Subject: [PATCH 3/5] fix compresss offline never runs using environ --- .../compose/production/django/start | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/production/django/start b/{{cookiecutter.project_slug}}/compose/production/django/start index a3aa1161c..4985aeedd 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/start +++ b/{{cookiecutter.project_slug}}/compose/production/django/start @@ -6,9 +6,24 @@ set -o nounset python /app/manage.py collectstatic --noinput -{%- if cookiecutter.use_whitenoise == 'y' and cookiecutter.use_compressor == 'y' %} -if [ "${COMPRESS_ENABLED:-}" = "True" ]; -then +{% if cookiecutter.use_whitenoise == 'y' and cookiecutter.use_compressor == 'y' %} +compress_enabled() { +python << END +import sys + +from environ import Env + +env = Env(COMPRESS_ENABLED=(bool, True)) +if env('COMPRESS_ENABLED'): + sys.exit(0) +else: + sys.exit(1) + +END +} + +if compress_enabled; then + # NOTE this command will fail if django-compressor is disabled python /app/manage.py compress fi {%- endif %} From 090b93c01ebc5333c477cc9f955c6a9924c90bbc Mon Sep 17 00:00:00 2001 From: James Williams <33026008+jameswilliams1@users.noreply.github.com> Date: Sun, 15 Mar 2020 22:16:40 +0000 Subject: [PATCH 4/5] remove setting compress_enabled to null in .django --- {{cookiecutter.project_slug}}/.envs/.production/.django | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.envs/.production/.django b/{{cookiecutter.project_slug}}/.envs/.production/.django index 2c2e94f2d..ae13ee01d 100644 --- a/{{cookiecutter.project_slug}}/.envs/.production/.django +++ b/{{cookiecutter.project_slug}}/.envs/.production/.django @@ -31,11 +31,7 @@ DJANGO_GCP_STORAGE_BUCKET_NAME= # django-allauth # ------------------------------------------------------------------------------ DJANGO_ACCOUNT_ALLOW_REGISTRATION=True -{% if cookiecutter.use_compressor == 'y' %} -# django-compressor -# ------------------------------------------------------------------------------ -COMPRESS_ENABLED= -{% endif %} + # Gunicorn # ------------------------------------------------------------------------------ WEB_CONCURRENCY=4 From a553fa9aafe89a1daec41e7d1a6e509f0b867754 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 16 Mar 2020 12:53:12 -0700 Subject: [PATCH 5/5] Update flake8-isort from 2.8.0 to 2.9.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bc8292a8c..6894fa8f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ binaryornot==0.4.4 # ------------------------------------------------------------------------------ black==19.10b0 flake8==3.7.9 -flake8-isort==2.8.0 +flake8-isort==2.9.0 # Testing # ------------------------------------------------------------------------------