diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 86804b69..043312b0 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 709c1dd0..a3aa1161 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 36667b33..a3e4b9c2 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