Skip to content

Use docker compose for debugging production #158

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

Conversation

davidfischer
Copy link
Member

@davidfischer davidfischer commented Jun 1, 2024

  • Add a docker compose environment with Redis and Postgres
  • Add django-storages for storing media files in S3/R2

Branched from #156.

Rationale

While working on #156, I needed a setup a bit closer to production. Specifically I needed a setup that used Postgres and I wanted to use django-storages to store media files instead of the local filesystem.

Testing

With docker and docker-compose installed, you should be able to run

# Builds the docker compose setup with Postgres
make dockerbuild

# Then this will create a dev server (but with Django's DEBUG=False) on http://localhost:8000
make dockerserve

Without setting anything, it will store media in a local media directory that will disappear when you close down the server. The plan is to use cloud storage in production. I plan to use R2 and stay well under the free tier. I tested this out and it seemed to work well.

You still should be able to run the default ./manage.py runserver if you prefer.

Deploying

The environment variables needed for this change are already staged in fly.io. Since there's no code that uses them yet, they're not doing anything. However, if this is merged into prod, the envvars will take effect and media storage should hopefully just work.

- Add a docker compose environment with Redis and Postgres
- Add django-storages for storing media files in S3/R2
- Set both `MEDIA_URL` and `AWS_S3_CUSTOM_DOMAIN`.
  This ensures that both using `MEDIA_URL` or
  using `file.url` work well
@Jer-Pha Jer-Pha mentioned this pull request Jun 1, 2024
@davidfischer davidfischer merged commit cb827a7 into davidfischer/Jer-Pha-organizers Jun 3, 2024
1 check passed
@davidfischer davidfischer deleted the davidfischer/docker-compose-media-storage branch June 3, 2024 23:04
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

Successfully merging this pull request may close these issues.

1 participant