thunderstore-io / Thunderstore

Thunderstore is a mod database and API for downloading mods. Thunderstore Discord: https://discord.thunderstore.io/
https://thunderstore.io/
GNU Affero General Public License v3.0
138 stars 28 forks source link
api cdn hacktoberfest mod mod-database modding rest risk-of-rain risk-of-rain-2 ror2 thunderstore

Thunderstore

codecov

Thunderstore is a mod database and API for downloading mods.

Setup guide for development

from django.contrib.sites.models import Site
Site.objects.create(domain="thunderstore.localhost", name="Thunderstore")

Make sure to substitute localhost with what you use to connect to the site! In general, you should use thunderstore.localhost as the main domain to handle auth-scoping correctly (see SESSION_COOKIE_DOMAIN later on)

You will also need to navigate to the admin panel (/djangoadmin) and configure a mapping from a site to a community. You can create a superuser account with the createsuperuser Django management command (akin to how migrate was run) to gain access to the admin panel.

To connect a site to a community, you will need to:

  1. Make sure at least one Community object exists or create one (Risk of Rain 2 should be created automatically)
  2. Make sure at least one Site object exists or create one
  3. Make the site object's domain name attribute match what you use for connecting to your development environment
  4. Create a new Community Site object, linking the two together

Test data population

There's a script for populating the local database with test data. You can run it as follows:

docker compose exec django python manage.py create_test_data

Minio

In local development, minio is used for S3 compatible file storage. You can access it via http://localhost:9000/ with thunderstore:thunderstore credentials

REST API docs

The REST API swagger documentation can be viewed from /api/docs/.

At the current moment, the only relevant API is /api/v1/package/, which lists all the active mods in the database. A specific mod can also be fetched if necessary with the /api/v1/package/{uuid4}/ endpoint, where {uuid4} is replaced with the mod's uuid4 value.

Admin site

The admin site can be accessed from /djangoadmin/. To view the admin site, you need an admin account.

Assuming docker is being used, the admin account can be created as follows:

docker compose exec django python manage.py createsuperuser

Do note that if you're running on Windows, you will need to use winpty for running that command.

Environment variable configuration for production

General variables

Gunicorn

Django

For local testing, recommended values are:

Make sure also to have the Site objects point to thunderstore.localhost or some of its subdomains, such as test.thunderstore.localhost.

Social Auth

For local testing, recommended values are:

GitHub OAuth

To set up GitHub OAuth, head to settings on GitHub (either personal or organization settings), and from under Developer Settings select OAuth Apps.

Create a new OAuth Application, and use {AUTH_EXCLUSIVE_HOST}/auth/complete/github/ as the Authorization callback URL, where {AUTH_EXCLUSIVE_HOST} is replaced with the value that was used for the AUTH_EXCLUSIVE_HOST setting. For example for local you could use http://auth.localhost/auth/complete/github/, whereas for a live environment https://auth.thunderstore.dev/auth/complete/github/

After creating the OAuth application, you must also provide the following environment variables to the application:

Discord OAuth

To set up a Discord OAuth, head to the Discord developer panel, and create a new OAuth application. Add a callback URL to {AUTH_EXCLUSIVE_HOST}/auth/complete/discord/, where {AUTH_EXCLUSIVE_HOST} is replaced with the value that was used for the AUTH_EXCLUSIVE_HOST setting. For example for local you could use http://auth.localhost/auth/complete/discord/, whereas for a live environment https://auth.thunderstore.dev/auth/complete/discord/

Storage

The AWS S3 / Boto3 protocol is supported by multiple vendors and services, and such the implementation may vary depending on the provider.

Refer to https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html for more details on the implementation. Also see thunderstore/core/settings.py for what environment variables are currently implemented.

At the very least set the following variables:

Usermedia storage

The usermedia APIs work by leveraging S3-compatible storage presigned URLs to handle the actual upload. As such, the usermedia backend must also be a S3 compatible storage backend. Likewise, the usermedia storage backend can be configured with environment variables:

The largest difference compared to the AWS S3 configuration is the addition of a USERMEDIA_S3_SIGNING_ENDPOINT_URL. If provided, this will be used when generating pre-signed URLs. Can be used to bypass the CDN domain for example.

Database

Database configuration is pretty straight forward if using a local database where no SSL is required, but remote database via SSL connections is also supported.

The default local database configured in docker-compose.yml can be accessed:

Redis caching

You can enable caching to the redis backend by supplying a redis URL

Testing

Tests can be run with this command: docker compose exec django pytest If you need to recreate to database, use the following: docker compose exec django pytest --create-db --migrations

The CI pipeline checks that new PRs don't lower the test coverage. Since this process is rather slow, you might want to check the coverage locally before submitting a PR.

Test duration estimates

The test run is split across multiple workers on the CI pipeline, and the split aims to balance test across all the available workers in equal amounts of time consumption.

To be able to do so accurately, the test duration database has to be up to date. As such it's a good idea to update the test duration database every now and then.

The test duration database can be updated by running the full test suite with the --store-durations flag. So a full command example would be

docker compose exec django pytest --store-durations