Hacker News new | ask | show | jobs
by danso 4466 days ago
I'm a big fan of "idiot" guides to ops/stack-setups, partially because it's interesting -- and helpful -- to see what authors' assume about the "idiot"...and it's a real art to write something that can appeal to such a wide-variance of non-expert.

That said, let me ask the first idiot-question: is this a precursor to a more complicated stack? Because what's the use-case for setting up Django with an asset-pipeline to S3? I mean, what is the Django instance itself running on? (as I imagine setting up Django on EC@ is generally the harder thing to do)

1 comments

Serving static files from nginx still has overhead on the server and also can be slower that s3. Also, you avoid a whole rake of problems with backups, running out of disk space, sharing static files among servers, etc, by storing files on S3.
Sure...but why Django? If I'm missing something, how do you generate the static pages from the Django app? I see that django-pipeline compiles and generates the asset files, but what about `mydjangoapp.com/books/1`, `mydjangoapp.com/author/smith-jon` and so forth, i.e. the data-pages?

edit: I guess I'm assuming too much...the OP is assuming you have Django app already online and running, and this process moves over the asset files?

Yeah absolutely right, I'm just using the pipeline for my static files (i.e. styles, images, js) not for data pages. One more caveat I forgot to put in the post but should be mentioned is the collectstatic command. If you have a huge collection of static assets, collectstatic is painfully slow copying its files directly to the S3 bucket. In my case, I don't have a huge number of assets so it's not a big issue, but if anyone has any ideas for making collectstatic faster, I'd love to hear them
Checkout something like this.

https://github.com/antonagestam/collectfast

The problem is collectstatic will use modified date. When sending to S3 this means the entire static pipeline is uploaded each time. Packages like collectfast use the hash to look for difference and only uploads those files. Works reasonably well. We have had a few issues along the way that we have had to work through but its a start.

that looks awesome, definitely going to give it a try. Thanks!
You just need to wait for Django 1.7 and its ManifestStaticFilesStorage : https://docs.djangoproject.com/en/dev/ref/contrib/staticfile...
Speaking purely from our deployment pipeline. This is most likely not for serving pure static pages, 'data-pages' I think you are referring to. This is just to serve the images and css from a CDN.

On our deployments we wrap up all the static pages, they get to S3 which goes to cloudfront. The link for cloudfront is generated on the fly and then injected back into wherever that asset was called.

This tutorial gets you a pretty good start and doing just that.

Serving static files from the EC2 instance is also more expensive, once you factor in storage costs, IOPS, etc. Not to mention S3 will be faster.