Repository: cookiecutter/cookiecutter-django

Issue:
Broken setup with use_whitenoise=y, use_compressor=y and cloud_provider=none
## What happened?
Multiple things:
- Altough, we set cloud_provider to None, follwing is set in `config/settings/production.py`:
`COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"`
- Compressed static files are not available via Whitenoise, giving an error on page:

`compressor.exceptions.OfflineGenerationError: You have offline compression enabled but key "..." is missing from offline manifest. You may need to run "python manage.py compress"`




## What should've happened instead?
- Compress storage should be set to local configuration:
`COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage"`
- `compose/production/django/start` should be extended to this:
```
python /app/manage.py collectstatic --noinput
python /app/manage.py compress --force
python /app/manage.py collectstatic --noinput
```

See https://stackoverflow.com/questions/58712195/django-whitenoise-with-compressed-staticfiles for further information

## Steps to reproduce
Set up project with following settings:
- use_docker=y
- use_whitenoise=y
- use_compressor=y
- cloud_provider=3 (None)


Discussion:
Just came here to post the same thing (used the same options as above). I think the things that need changing to fix this are:
#### config/settings/production.py
```python
COMPRESS_OFFLINE = env.bool("COMPRESS_OFFLINE", default=True)
COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage"
```
(Brotli also works well for me here, but requires another package, IMO it's worth it as most browsers now support this.)
Additionally I think the following makes a good speed improvement without any more dependencies:
```python
COMPRESS_FILTERS = {
    "css": [
        "compressor.filters.css_default.CssAbsoluteFilter",
        "compressor.filters.cssmin.rCSSMinFilter",
    ],
    "js": ["compressor.filters.jsmin.JSMinFilter"],
}
```
#### compose/production/django/start
```bash
#!/bin/bash

set -euo pipefail

python /app/manage.py collectstatic --noinput
python /app/manage.py compress
python /app/manage.py migrate
/usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app
```

I'm currently using these settings for a site after spending ages trying to work out the compressor errors and I agree something like the above should be the default when saying no to cloud providers.

I have to admit I've never had the occasion to use `django-compressor` properly, so I'm not very familiar with its settings. Pull request to fix our setup is welcome 👍 
> I have to admit I've never had the occasion to use `django-compressor` properly, so I'm not very familiar with its settings. Pull request to fix our setup is welcome +1

I'll open one this weekend.

Resolving patch:
diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py
--- a/{{cookiecutter.project_slug}}/config/settings/production.py
+++ b/{{cookiecutter.project_slug}}/config/settings/production.py
@@ -200,9 +200,27 @@ class MediaRootGoogleCloudStorage(GoogleCloudStorage):
 # 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


Test patch: