Merge pull request #352 from zurdi15/environment-cleanup

Clarify some environment variables
This commit is contained in:
Zurdi
2023-08-26 11:07:15 +02:00
committed by GitHub
10 changed files with 46 additions and 35 deletions

View File

@@ -77,9 +77,9 @@ Inspired by [Jellyfin](https://jellyfin.org/), allows you to manage all your gam
Docker should be installed and set up before running the [image](https://hub.docker.com/r/zurdi15/romm/tags).
1. Generate an API key for [IGDB](https://www.igdb.com/), and set the `CLIENT_ID` and `CLIENT_SECRET` variables. _This is required to run a library scan._ Instructions on generating the ID and Secret are [here](https://api-docs.igdb.com/#about). Note that IDGB requires a Twitch account with 2FA enabled to generate the ID and Secret.
1. Generate an API key for [IGDB](https://www.igdb.com/), and set the `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET` variables. _This is required to run a library scan._ Instructions on generating the ID and Secret are [here](https://api-docs.igdb.com/#about). Note that IDGB requires a Twitch account with 2FA enabled to generate the ID and Secret.
2. Verify that your library folder structure matches one of the options listed in the [following section](#folder-structure).
3. Create a docker-compose file. See the following example [docker-compose.yml](https://github.com/zurdi15/romm/blob/master/examples/docker-compose.example.yml) file for reference. Customize for your setup and include the `CLIENT_ID` and `CLIENT_SECRET` vareiables where indicated in the environment section of the file.
3. Create a docker-compose file. See the following example [docker-compose.yml](https://github.com/zurdi15/romm/blob/master/examples/docker-compose.example.yml) file for reference. Customize for your setup and include the `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET` vareiables where indicated in the environment section of the file.
4. Launch the container:
```bash

View File

@@ -37,13 +37,19 @@ DB_PASSWD: Final = os.environ.get("DB_PASSWD")
DB_NAME: Final = os.environ.get("DB_NAME", "romm")
# REDIS
ENABLE_EXPERIMENTAL_REDIS: Final = os.environ.get("ENABLE_EXPERIMENTAL_REDIS", "false") == "true"
ENABLE_EXPERIMENTAL_REDIS: Final = (
os.environ.get("ENABLE_EXPERIMENTAL_REDIS", "false") == "true"
)
REDIS_HOST: Final = os.environ.get("REDIS_HOST", "localhost")
REDIS_PORT: Final = os.environ.get("REDIS_PORT", "6379")
# IGDB
CLIENT_ID: Final = os.environ.get("CLIENT_ID", "")
CLIENT_SECRET: Final = os.environ.get("CLIENT_SECRET", "")
IGDB_CLIENT_ID: Final = os.environ.get(
"IGDB_CLIENT_ID", os.environ.get("CLIENT_ID", "")
)
IGDB_CLIENT_SECRET: Final = os.environ.get(
"IGDB_CLIENT_SECRET", os.environ.get("CLIENT_SECRET", "")
)
# STEAMGRIDDB
STEAMGRIDDB_API_KEY: Final = os.environ.get("STEAMGRIDDB_API_KEY", "")

View File

@@ -3,14 +3,14 @@ import socketio # type: ignore
from rq import Queue
from logger.logger import log
from config import ENABLE_EXPERIMENTAL_REDIS
from utils import fs, fastapi
from exceptions.fs_exceptions import PlatformsNotFoundException, RomsNotFoundException
from handler import dbh
from utils.socket import socket_server
from utils.cache import redis_client, redis_url, redis_connectable
from utils.cache import redis_client, redis_url
from endpoints.platform import PlatformSchema
from endpoints.rom import RomSchema
from config import ENABLE_EXPERIMENTAL_REDIS
scan_queue = Queue(connection=redis_client)
@@ -21,7 +21,7 @@ async def scan_platforms(
# Connect to external socketio server
sm = (
socketio.AsyncRedisManager(redis_url, write_only=True)
if redis_connectable
if ENABLE_EXPERIMENTAL_REDIS
else socket_server
)
@@ -89,7 +89,7 @@ async def scan_handler(_sid: str, options: dict):
selected_roms = options.get("roms", [])
# Run in worker if redis is available
if redis_connectable and ENABLE_EXPERIMENTAL_REDIS:
if ENABLE_EXPERIMENTAL_REDIS:
return scan_queue.enqueue(
scan_platforms, platform_slugs, complete_rescan, selected_roms
)

View File

@@ -8,7 +8,7 @@ from unidecode import unidecode as uc
from requests.exceptions import HTTPError, Timeout
from typing import Final
from config import CLIENT_ID, CLIENT_SECRET
from config import IGDB_CLIENT_ID, IGDB_CLIENT_SECRET
from utils import get_file_name_with_no_tags as get_search_term
from logger.logger import log
from utils.cache import cache
@@ -29,7 +29,7 @@ class IGDBHandler:
self.screenshots_url = "https://api.igdb.com/v4/screenshots/"
self.twitch_auth = TwitchAuth()
self.headers = {
"Client-ID": CLIENT_ID,
"Client-ID": IGDB_CLIENT_ID,
"Authorization": f"Bearer {self.twitch_auth.get_oauth_token()}",
"Accept": "application/json",
}
@@ -206,8 +206,8 @@ class TwitchAuth:
res = requests.post(
url="https://id.twitch.tv/oauth2/token",
params={
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"client_id": IGDB_CLIENT_ID,
"client_secret": IGDB_CLIENT_SECRET,
"grant_type": "client_credentials",
},
timeout=30,

View File

@@ -1,15 +1,10 @@
from redis import Redis, ConnectionError
from redis import Redis
from config import REDIS_HOST, REDIS_PORT
from config import REDIS_HOST, REDIS_PORT, ENABLE_EXPERIMENTAL_REDIS
redis_client = Redis(host=REDIS_HOST, port=int(REDIS_PORT), db=0)
redis_url = f"redis://{REDIS_HOST}:{REDIS_PORT}"
try:
redis_connectable = redis_client.ping()
except ConnectionError:
redis_connectable = False
class FallbackCache:
def __init__(self) -> None:
@@ -42,4 +37,4 @@ _cache_client = Redis(
host=REDIS_HOST, port=int(REDIS_PORT), db=0, decode_responses=True
)
_fallback_cache = FallbackCache()
cache = _cache_client if redis_connectable else _fallback_cache
cache = _cache_client if ENABLE_EXPERIMENTAL_REDIS else _fallback_cache

View File

@@ -1,6 +1,7 @@
import socketio # type: ignore
from utils.cache import redis_url, redis_connectable
from utils.cache import redis_url
from config import ENABLE_EXPERIMENTAL_REDIS
socket_server = socketio.AsyncServer(
@@ -8,7 +9,9 @@ socket_server = socketio.AsyncServer(
async_mode="asgi",
logger=False,
engineio_logger=False,
client_manager=socketio.AsyncRedisManager(redis_url) if redis_connectable else None,
client_manager=socketio.AsyncRedisManager(redis_url)
if ENABLE_EXPERIMENTAL_REDIS
else None,
)
socket_app = socketio.ASGIApp(socket_server)

View File

@@ -2,13 +2,13 @@ import sys
from rq import Worker, Queue, Connection
from config import ENABLE_EXPERIMENTAL_REDIS
from utils.cache import redis_client, redis_connectable
from utils.cache import redis_client
listen = ["high", "default", "low"]
if __name__ == "__main__":
# Exit if Redis is not connectable
if not redis_connectable or not ENABLE_EXPERIMENTAL_REDIS:
# Exit if Redis is not enabled
if not ENABLE_EXPERIMENTAL_REDIS:
sys.exit(0)
with Connection(redis_client):

View File

@@ -2,8 +2,8 @@ ROMM_BASE_PATH=/path/to/romm_mock
VITE_BACKEND_DEV_PORT=5000
# IGDB credentials
CLIENT_ID=
CLIENT_SECRET=
IGDB_CLIENT_ID=
IGDB_CLIENT_SECRET=
# STEAMGRIDDB API key
STEAMGRIDDB_API_KEY=

View File

@@ -14,8 +14,8 @@ services:
- DB_NAME=romm # Should match the MYSQL_DATABASE value in the mariadb container
- DB_PASSWD=<database password>
# [Optional] Used to fetch metadata from IGDB
- CLIENT_ID=<IGDB client id>
- CLIENT_SECRET=<IGDB client secret>
- IGDB_CLIENT_ID=<IGDB client id>
- IGDB_CLIENT_SECRET=<IGDB client secret>
# [Optional] Use SteamGridDB as a source for covers
- STEAMGRIDDB_API_KEY=<SteamGridDB api key>
# [Optional] Will enable user management and require authentication to access the interface (default to false)
@@ -44,10 +44,10 @@ services:
image: mariadb:latest
container_name: mariadb
environment:
- MYSQL_ROOT_PASSWORD=RootPasswordChangeMe
- MYSQL_ROOT_PASSWORD=<root password>
- MYSQL_DATABASE=romm
- MYSQL_USER=romm-user
- MYSQL_PASSWORD=change-me
- MYSQL_PASSWORD=<database password>
volumes:
- mysql_data:/var/lib/mysql # Can also be mounted locally
ports:

View File

@@ -33,12 +33,19 @@
<Config Name="Resources" Target="/romm/resources/" Default="" Mode="rw" Description="Metadata storage (covers, screenshots, etc.)" Type="Path" Display="always" Required="false" Mask="false">/mnt/user/appdata/romm/resources</Config>
<Config Name="Logs" Target="/romm/logs" Default="" Mode="rw" Description="Log file storage" Type="Path" Display="always" Required="false" Mask="false">/mnt/user/appdata/romm/logs</Config>
<Config Name="Database" Target="/romm/database" Default="" Mode="rw" Description="Only needed if using SQLite" Type="Path" Display="always" Required="false" Mask="false">/mnt/user/appdata/romm/database</Config>
<Config Name="CLIENT_ID" Target="CLIENT_ID" Default="" Mode="" Description="IGDB Client ID" Type="Variable" Display="always" Required="true" Mask="false"/>
<Config Name="CLIENT_SECRET" Target="CLIENT_SECRET" Default="" Mode="" Description="IGDB Client Secret" Type="Variable" Display="always" Required="true" Mask="true"/>
<Config Name="IGDB_CLIENT_ID" Target="IGDB_CLIENT_ID" Default="" Mode="" Description="IGDB Client ID" Type="Variable" Display="always" Required="true" Mask="false"/>
<Config Name="IGDB_CLIENT_SECRET" Target="IGDB_CLIENT_SECRET" Default="" Mode="" Description="IGDB Client Secret" Type="Variable" Display="always" Required="true" Mask="true"/>
<Config Name="DB_DRIVER" Target="DB_DRIVER" Default="sqlite" Mode="" Description="Database driver (mariadb or sqlite)" Type="always" Display="always" Required="false" Mask="false"/>
<Config Name="DB_HOST" Target="DB_HOST" Default="mariadb" Mode="" Description="Database host" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_PORT" Target="DB_PORT" Default="3306" Mode="" Description="Database port" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_USER" Target="DB_USER" Default="romm" Mode="" Description="Database user" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_NAME" Target="DB_NAME" Default="romm" Mode="" Description="Database name" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_PASSWD" Target="DB_PASSWD" Default="" Mode="" Description="Database password for DB_USER" Type="Variable" Display="advanced" Required="false" Mask="true"/>
</Container>
<Config Name="ENABLE_EXPERIMENTAL_REDIS" Target="ENABLE_EXPERIMENTAL_REDIS" Default="false" Mode="" Description="Enable Redis (experimental)" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="REDIS_HOST" Target="REDIS_HOST" Default="127.0.0.1" Mode="" Description="Redis host" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="REDIS_PORT" Target="REDIS_PORT" Default="6379" Mode="" Description="Redis port" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="ROMM_AUTH_ENABLED" Target="ROMM_AUTH_ENABLED" Default="false" Mode="" Description="Enable authentication" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="ROMM_AUTH_USERNAME" Target="ROMM_AUTH_USERNAME" Default="admin" Mode="" Description="Default admin username" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="ROMM_AUTH_PASSWORD" Target="ROMM_AUTH_PASSWORD" Default="" Mode="" Description="Default admin password" Type="Variable" Display="advanced" Required="false" Mask="true"/>
<Config Name="ROMM_AUTH_SECRET_KEY" Target="ROMM_AUTH_SECRET_KEY" Default="" Mode="" Description="Generate a key with `openssl rand -hex 32`" Type="Variable" Display="advanced" Required="false" Mask="true"/>
</Container>