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

Automatically run Django's collectstatic command #108

Merged
merged 4 commits into from
Sep 13, 2023
Merged

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Sep 12, 2023

The classic Heroku Python buildpack automatically runs the Django collectstatic command:
https://github.com/heroku/heroku-buildpack-python/blob/main/bin/steps/collectstatic

This adds equivalent support, with a couple of improvements:

There is currently no way to force disable the feature (beyond removing django.contrib.staticfiles from INSTALLED_APPS in the app's Django config, or removing the manage.py script). Supporting this depends on us deciding how best to handle buildpack options, so will be added later, in #109.

The build log output and error messages are fairly reasonable already (and a significant improvement over the classic buildpack), and will be further polished as part of the future build output overhaul.

The implementation uses the new utils::run_command_and_capture_output added in #106.

See:

Fixes #5.
GUS-W-9538294.

The classic Heroku Python buildpack automatically runs the
Django `collectstatic` command:
https://github.com/heroku/heroku-buildpack-python/blob/main/bin/steps/collectstatic

This adds equivalent support, with a couple of improvements:
- This implementation performs more checks to see whether
  the app is actually using the static files feature before trying
  to run it (reducing the number of cases where users have to
  manually disable it).
- The collectstatic symlink feature has been enabled, as requested
  in heroku/heroku-buildpack-python#1060.
- Symlinked `manage.py` files are now supported, as requested
  in heroku/heroku-buildpack-python#972.
- The error messages are finer grained/more useful.
- There are many more tests.

There is currently no way to force disable the feature (beyond
removing `django.contrib.staticfiles` from `INSTALLED_APPS`
in the app's Django config). Adding this depends on us deciding
how best to handle buildpack options, so will be added later.

This uses the new `utils::run_command_and_capture_output`
added in #106.

See:
* https://docs.djangoproject.com/en/4.2/howto/static-files/
* https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/
* https://docs.djangoproject.com/en/4.2/ref/settings/#settings-staticfiles

Fixes #5.
GUS-W-9538294.
@edmorley edmorley added the classic buildpack parity Features required for parity with the classic Heroku Python buildpack label Sep 12, 2023
@edmorley edmorley self-assigned this Sep 12, 2023
@edmorley edmorley marked this pull request as ready for review September 12, 2023 13:32
@edmorley edmorley requested a review from a team as a code owner September 12, 2023 13:32
A legacy Django version (1.18, which is EOL) is now tested,
as well as ensuring that env vars are passed to manage.py.
@edmorley edmorley merged commit 64d5c7c into main Sep 13, 2023
5 checks passed
@edmorley edmorley deleted the django-collectstatic branch September 13, 2023 10:23
@heroku-linguist heroku-linguist bot mentioned this pull request Sep 19, 2023
heroku-linguist bot added a commit that referenced this pull request Sep 19, 2023
## heroku/python

### Added

- Django's `collectstatic` command is now automatically run for Django apps that use static files. ([#108](#108))

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
heroku-linguist bot added a commit to heroku/cnb-builder-images that referenced this pull request Sep 19, 2023
## heroku/python

### Added

- Django's `collectstatic` command is now automatically run for Django apps that use static files. ([#108](heroku/buildpacks-python#108))

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
classic buildpack parity Features required for parity with the classic Heroku Python buildpack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically run Django's collectstatic command
2 participants