Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting Whitenoise and AWS as cloud provider overrides STATIC_URL in a way that assumes Collectfast #4925

Closed
jskitz opened this issue Mar 14, 2024 · 3 comments · Fixed by #5057
Labels

Comments

@jskitz
Copy link

jskitz commented Mar 14, 2024

What happened?

I had selected Whitenoise as my static asset solution, but also chose AWS as my cloud provider. This is because I want to use Whitenoise for static assets, but AWS for uploaded media. But essentially, these two selections halfway implemented Collectfast with AWS, but did not fully make the solution work. Neither Whitenoise or Cloud static assets worked when both are selected.

What should've happened instead?

If Whitenoise is selected, AWS should only apply to media instead of static assets. Or, alternatively, by choosing AWS, it should also setup Collectfast so that this solution works. By choosing both Whitenoise and AWS, static asset generation is completely broken.

By choosing both, this is what production.py settings are generated:

# STATIC & MEDIA
# ------------------------
STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
    },
}
MEDIA_URL = f"https://{aws_s3_domain}/media/"
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
STATIC_URL = f"https://{aws_s3_domain}/static/"

But Collectfast is not installed because Whitenoise was selected.

Additional details

  • Host system configuration:

    • Cookiecutter 2.5.0
    • This was found on a Heroku deployment when static assets were not working correctly.
    • Python 3.11.4
{
  "cookiecutter": {
    "project_name": "Project",
    "project_slug": "project_slug",
    "description": "This project is a website.",
    "author_name": "Jason",
    "domain_name": "example.com",
    "email": "jason@example.com",
    "version": "0.1.0",
    "open_source_license": "Not open source",
    "username_type": "email",
    "timezone": "UTC",
    "windows": "n",
    "editor": "VS Code",
    "use_docker": "n",
    "postgresql_version": "12",
    "cloud_provider": "AWS",
    "mail_service": "Mailgun",
    "use_async": "n",
    "use_drf": "y",
    "frontend_pipeline": "Gulp",
    "use_celery": "n",
    "use_mailpit": "n",
    "use_sentry": "y",
    "use_whitenoise": "y",
    "use_heroku": "y",
    "ci_tool": "Github",
    "keep_local_envs_in_vcs": "y",
    "debug": "n",
    "_template": "gh:cookiecutter/cookiecutter-django",
    "_output_dir": "/Users/jason/Sites",
    "_repo_dir": "/Users/jason/.cookiecutters/cookiecutter-django",
    "_checkout": null
  }
@jskitz jskitz added the bug label Mar 14, 2024
@browniebroke
Copy link
Member

Sounds like a bug indeed, agree that it is not expected. Would you like to send us a pull request to fix it?

@foarsitter
Copy link
Collaborator

Hit this issue also, should be easy to fix.

@jkaeske
Copy link
Contributor

jkaeske commented May 7, 2024

I created a PR for this issue, since I ran into the same problem.
Would be nice if someone could have a look :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants