heroku-buildpack-python icon indicating copy to clipboard operation
heroku-buildpack-python copied to clipboard

Enable Django collectstatic's symlink mode

Open edmorley opened this issue 5 years ago • 3 comments

For Django apps, the buildpack currently runs the Django management command collectstatic automatically as part of the build. This command by default copies the static files provided by any Django packages/the local app into the staticfiles directory.

The collectstatic command has a --link option which enables the use of symlinks instead of file copies: https://docs.djangoproject.com/en/2.2/ref/contrib/staticfiles/#cmdoption-collectstatic-link

Using this option would save duplicating files within the app directory, reducing slug size and speeding up the build (since symlinking is quicker than copying).

This idea was proposed in #1033 - filing this issue to give somewhere to discuss the idea.

Things we'll need to investigate/consider:

  • what versions of Django support --link and are there any known bugs that prevent its use on older versions?
  • are there any scenarios where it's not a drop in replacement (eg alternative staticfiles backends, or ...?)
  • should we make this the default behaviour, or should it be controllable?
  • we should probably ensure the metrics emitted allow determining pass vs fail and duration for link vs standard

In the meantime, anyone wanting to enable symlinks can do so by disabling the built-in collectstatic (by setting the env var DISABLE_COLLECTSTATIC on their app, per docs), then running collectstatic with custom command in a bin/post_compile script (see #1026).

edmorley avatar Sep 01 '20 12:09 edmorley

This issue has been linked to a new work item: W-8031900

git2gus[bot] avatar Sep 01 '20 12:09 git2gus[bot]

This issue has been linked to a new work item: W-8031919

git2gus[bot] avatar Sep 01 '20 12:09 git2gus[bot]