From 55d3d9533318db26b3ca0656ca78c6b352b97730 Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:08:53 -0400 Subject: [PATCH 1/4] Add STATICFILES_STORAGE with compressor support --- {{cookiecutter.project_slug}}/config/settings/production.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 3d4f324c..ce381715 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -236,10 +236,12 @@ 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' %} +{%- if cookiecutter.cloud_provider == 'AWS' and cookiecutter.use_whitenoise == 'y' %} COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" -{%- elif cookiecutter.cloud_provider == 'GCP' %} +{%- elif cookiecutter.cloud_provider == 'GCP' and cookiecutter.use_whitenoise == 'y' %} COMPRESS_STORAGE = "storages.backends.gcloud.GoogleCloudStorage" +{%- elif cookiecutter.cloud_provider == 'AWS' or cookiecutter.cloud_provider == 'GCP' %} +COMPRESS_STORAGE = STATICFILES_STORAGE {%- elif cookiecutter.cloud_provider == 'None' %} COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" {%- endif %} From 1cb2a0c98e3d54b4f2e89426e678f73713be94b6 Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:13:40 -0400 Subject: [PATCH 2/4] Set COMPRESS_ROOT to STATIC_ROOT for compressor Django compressor also recommends the `COMPRESS_ROOT` be the STATIC_ROOT. This also makes sure the utils is set up properly so that the CACHE directory is actually publicly available (it'll be inside the static directory as a subdirectory). --- {{cookiecutter.project_slug}}/config/settings/production.py | 1 + 1 file changed, 1 insertion(+) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index ce381715..f64ad1d2 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -242,6 +242,7 @@ COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" COMPRESS_STORAGE = "storages.backends.gcloud.GoogleCloudStorage" {%- elif cookiecutter.cloud_provider == 'AWS' or cookiecutter.cloud_provider == 'GCP' %} COMPRESS_STORAGE = STATICFILES_STORAGE +COMPRESS_ROOT = STATIC_ROOT {%- elif cookiecutter.cloud_provider == 'None' %} COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" {%- endif %} From 148d6c2e29e6095ad2ae451be043dece513836a2 Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:24:51 -0400 Subject: [PATCH 3/4] Added noqa F405 to undefined STATIC_ROOT - flake8 * This is in addition to the PR for compressor support with AWS S3 and Google Cloud buckets --- {{cookiecutter.project_slug}}/config/settings/production.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index f64ad1d2..7a816722 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -242,7 +242,7 @@ COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" COMPRESS_STORAGE = "storages.backends.gcloud.GoogleCloudStorage" {%- elif cookiecutter.cloud_provider == 'AWS' or cookiecutter.cloud_provider == 'GCP' %} COMPRESS_STORAGE = STATICFILES_STORAGE -COMPRESS_ROOT = STATIC_ROOT +COMPRESS_ROOT = STATIC_ROOT # noqa F405 {%- elif cookiecutter.cloud_provider == 'None' %} COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" {%- endif %} From d411ed9b6a43e9fbf7e15eff2d2367f380887920 Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Thu, 13 Aug 2020 18:45:37 -0400 Subject: [PATCH 4/4] Update compressor not check whitenoise condition --- .../config/settings/production.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 7a816722..89049cad 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -235,16 +235,11 @@ 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' and cookiecutter.use_whitenoise == 'y' %} -COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" -{%- elif cookiecutter.cloud_provider == 'GCP' and cookiecutter.use_whitenoise == 'y' %} -COMPRESS_STORAGE = "storages.backends.gcloud.GoogleCloudStorage" -{%- elif cookiecutter.cloud_provider == 'AWS' or cookiecutter.cloud_provider == 'GCP' %} -COMPRESS_STORAGE = STATICFILES_STORAGE -COMPRESS_ROOT = STATIC_ROOT # noqa F405 -{%- elif cookiecutter.cloud_provider == 'None' %} +{%- if cookiecutter.cloud_provider == 'None' %} COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" +{%- elif cookiecutter.cloud_provider in ('AWS', 'GCP') and cookiecutter.use_whitenoise == 'n' %} +# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE +COMPRESS_STORAGE = STATICFILES_STORAGE {%- 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 %}