diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index d2418f8a9..f33313d93 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -131,6 +131,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`_ @@ -301,6 +302,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 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 # ------------------------------------------------------------------------------ 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 diff --git a/{{cookiecutter.project_slug}}/compose/production/django/start b/{{cookiecutter.project_slug}}/compose/production/django/start index 709c1dd04..4985aeedd 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/start +++ b/{{cookiecutter.project_slug}}/compose/production/django/start @@ -6,4 +6,25 @@ set -o nounset python /app/manage.py collectstatic --noinput +{% 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 %} /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 73ce4d648..a027eca17 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -201,9 +201,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