Running Django + Gunicorn, I’ve switched to DEBUG=False and realized I’m going to need a way to host my static and media files. The static files were fine, I use:
But media is dynamic, therefore I can’t as they should be present in the image. I’ve create a volume which is mounted via:
[mounts]
destination = "/data"
source = "data"
In a traditional setup I would use Nginx to serve these files. Because Fly.io is acting as my Nginx in this case, is there a way to do this via the UI? Is there a way to easily serve media files without needing another server? There seems to be a lack of documentation for what should be a core part of using Django on Fly.io! How has everyone else got around this? Ideally I keep all my infrastructure on site, without needing an S3 bucket or seperate hosting provider.
Correct @czue, WhiteNoise is only for static files. You’d normally use django-storages for media files and can host anywhere though S3 is commonly used.
Oh, interesting. Hmm… makes sense around exposure. Honestly django-storages plus S3/Netlify/whatever works so well that I’m not sure how deep down this rabbit hole I’m motivated to go personally. Though I am curious technically what’s possible! Maybe someone from Fly will weigh in around exposing volumes in a safe way
I found a solution for this issue.
First, I created a volume for each machine, used the same volume name, did it according to the docs on Fly.io.
Then I mounted the volume in my toml file, to make sure my media folder points to the volume, like this:
After that I just experimented a bit by adding the following code to my toml file as inspired by reading Fly documentation (there was already a similar section for statics, I just added one more):