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

Use Django staticfiles #229

Closed
jaylett opened this issue Jul 26, 2015 · 10 comments
Closed

Use Django staticfiles #229

jaylett opened this issue Jul 26, 2015 · 10 comments

Comments

@jaylett
Copy link
Member

jaylett commented Jul 26, 2015

Currently we don't, resulting in string concatenation to create URLs. We may be able to address #72 at the same time by building a proper asset pipeline.

@georgebrock
Copy link
Member

This is work in progress on the george/static-files branch.

  • Remove FIXED_STATIC_URL settings, they're redundant.
  • Stop directly using STATIC_URL and MISSIONS_STATIC_URL to build asset URLs.
  • Configure django.contrib.staticfiles.
  • Only collect built CSS, not SCSS source.
  • Only collect mission images, not all mission files.
  • Use CachedStaticFilesStorage, but somehow preserve permanent URLs for assets we pass to the open graph (anything that used to use FIXED_STATIC_URL)

@georgebrock
Copy link
Member

Once all of this is finished, it'll require some changes to the img-origin.spacelog.org virtual host config:

  • All of the static files will be collected in one place, so there'll be no need to configure /missions separately.
  • Everything will be in a new collected directory (or similar), rather than serving directly from the static directory.

@jaylett
Copy link
Member Author

jaylett commented Nov 22, 2015

I strongly recommend not using CachedStaticFilesStorage; it has a poor deploy/rollback experience. The Manifest variant is better, although still not ideal. I plan to fix this properly, but I can't commit to a timeframe.

I wonder if we should have a (local) variant of {% static %} which allows us to specify which of a number of storage backends should be used, or just an unhashed variant of {% static %} to use for the fixed URLs. That way we could have un-hashed URLs and hashed URLs served (from the same URL & file spaces, since collectstatic first copies unhashed then post-processes to generate the hashed versions).

@georgebrock
Copy link
Member

We're currently on Django 1.4, so CachedStaticFilesStorage is the best we have without an upgrade. The answer to this might be an upgrade.

@jaylett
Copy link
Member Author

jaylett commented Nov 22, 2015

An upgrade is a good idea anyway, since 1.4 is pretty old now. If we can get onto 1.8 we get a lot of time before we have to upgrade again.

Alternatively, we could probably suffer through the problems with cached in the short term given we don't often need to roll out changes to the static files. I assume you were thinking of using a redis-backed cache? (The implementation is pretty good from what I remember.)

@georgebrock
Copy link
Member

I've solved the SCSS problem by adding a make target to run collectstatic with --ignore=*.scss. I've also re-defined the STATICFILES_DIRS entries for the missions to point to their images directory, since those are currently the only static assets a mission has.

There might be more elegant options, but this will work for now. The consequences of getting these bits wrong aren't really all that serious, we'll just that we have redundant URLs that aren't linked from anywhere serving files that are already under a public domain license.

Just the cached or manifest file storage to go.

@jaylett
Copy link
Member Author

jaylett commented Nov 23, 2015

Doesn't that mean that mission assets are going to be flattened? Actually, I think that was true beforehand, so I suspect this will only work for one (probably the last in lexical order?) mission. I should have caught that sooner, sorry.

@georgebrock
Copy link
Member

It should be fine: I'm giving each mission's STATICFILES_DIRS a prefix (e.g. ('missions/a8/images', '/path/to/missions/a8/images')) which seems to work. I see working images for all the missions on the development server, and when I run collectstatic I get a collected/missions directory with a subdirectory for each mission.

@jaylett
Copy link
Member Author

jaylett commented Nov 23, 2015

Ah, cool. I'd forgotten about prefixes for STATICFILES_DIRS :-)

@georgebrock
Copy link
Member

Closing in favour of #232

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

No branches or pull requests

2 participants