Skip to content

About

Inventory system for the Czechoslovak Video Game Archive

Resources

Stars

1 star

Watchers

3 watching

Forks

Repository files navigation

rhinventory

Kód pro inventář spolku Herní historie.

Nasazení

Dependencies:

  • PostgreSQL database
  • Copy .env_example to .env and fill in variables
  • Copy alembic.ini_example to alembic.ini and fill in PostgreSQL database URL
  • Run:
    uv sync
    uv run playwright install --only-shell chromium  # for rendering labels
    uv run python dbseed.py
    uv run alembic heads
    uv run alembic stamp <revision>

Where <revision> is the latest Alembic revision shown from alembic heads.

Chromium also needs some system libraries. On Debian or Ubuntu, install them with sudo .venv/bin/playwright install-deps chromium.

The first registered user should be given admin permissions.

Run with uv run flask run.

Run rhinventory

uv run flask run --debug

Run rhinventory-api

uv run fastapi dev rhinventory/api/app.py

Jak se Alembic?

    poetry shell

    # Jako git status
    alembic current

    # Udělal jsem novou tabulku, chci aby jí alembic přemigroval
    alembic revision --autogenerate -m "Add File table"

    # omrknu alembic/versions/[nová revize].py, jestli tam je to co chci...

    # Spustím migraci
    alembic upgrade head

Bumping hhfloppy versions

Have you updated events in hhfloppy? Run this to update the dependency:

uv lock --upgrade-package hhfloppy && uv sync

How to deploy

If there are no database migrations: run the script ./ops/deploy.sh

If there are database migrations: run the script ./ops/deploy_with_migration.sh

Embedding

herniarchiv.cz (haweb) shows public rhinventory pages under /inventory/, by loading them in an iframe through its own proxy. The proxy sends these request headers:

  • X-Forwarded-Prefix: /inventory/_frame – path the proxy serves rhinventory at. All URLs must therefore be built with url_for (or the site_url filter for root-relative URLs from elsewhere, such as the database).
  • X-Haweb-Embed: 1 – embed mode: no header or menu (haweb shows its own), staff-only tools hidden, noindex, indexifembedded, and static/embed.css and static/embed.js are loaded (see admin/master.html).
  • X-Haweb-Theme: light|dark – the visitor's theme on. Without it, the system preference applies.

To try it locally:

curl -H 'X-Forwarded-Prefix: /inventory/_frame' -H 'X-Haweb-Embed: 1' http://127.0.0.1:5000/asset/

When HAWEB_INVENTORY_URL is set (https://herniarchiv.cz/inventory in production), visitors who aren't logged in are redirected from rhinventory's pages to the same page on herniarchiv.cz. Its "Log in" link leads to /login/github?next=<path>, which returns them to the page in rhinventory. Files, JSON and other responses that aren't pages are not redirected.

The proxy doesn't serve files. It redirects /inventory/_frame/files/... to rhinventory, so that large downloads don't pass through it.

Serving files

/files/<id>/... checks that the visitor may see the file, and then sends it. Sending a large file from Flask ties up a gunicorn thread for the whole download, so in production nginx sends it instead: rhinventory returns an empty response with an X-Accel-Redirect: /_files/<store>/<path> header, and nginx serves that from an internal location for the store (files/rhbox/sites-hh/rhinventory.retroherna.org.nginx.conf in the infra repo).

X_ACCEL_REDIRECT_LOCATIONS lists which stores nginx serves, e.g. local=/_files/local/,coruscant=/_files/coruscant/. Only list a store once nginx (user www-data) can read its files, or downloads from it will fail with 404 or 403. Files in stores that aren't listed are sent by Flask, as is everything when the setting is empty (the default, and the way to run without nginx).

How to run scripts

PYTHONPATH=. python scripts/script.py

Debugging crashes on prod

Try to check logs with sudo journalctl -u www_rhinventory -e. If that's not enough, run manually with:

sudo systemctl stop rhinventory
cd /var/www/rhinventory
sudo -u flask ./deploy.sh

Once solved:

sudo systemctl start rhinventory

Upgrading hhfloppy

uv lock --upgrade-package hhfloppy && uv sync

Then update the SUPPORTED_EVENT_VERSION in event_store.py.

About

Inventory system for the Czechoslovak Video Game Archive

Resources

Stars

1 star

Watchers

3 watching

Forks

Used by

Contributors

Languages