diff --git a/Dockerfile b/Dockerfile index 81252b1..8c7e32a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ -FROM python:3.9.15-slim-bullseye +FROM python:3.14.6-slim-bookworm -RUN apt update && apt install default-libmysqlclient-dev build-essential libtk nodejs npm pkg-config -y +RUN apt update && apt install default-libmysqlclient-dev gcc libmemcached-dev -y WORKDIR /app + COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt -RUN npm i -g nodemon COPY entrypoint.sh entrypoint.sh RUN chmod +x entrypoint.sh +RUN mkdir logs COPY index.py index.py COPY dbutils.py dbutils.py COPY read.py read.py ADD core core ADD titles titles -ADD logs logs ADD cert cert ENTRYPOINT [ "/app/entrypoint.sh" ] diff --git a/core/allnet.py b/core/allnet.py index 25581fd..28eebeb 100644 --- a/core/allnet.py +++ b/core/allnet.py @@ -25,7 +25,7 @@ import os from os import path, environ, mkdir, access, W_OK from .config import CoreConfig -from .utils import Utils +from .utils import Utils, create_lifespan from .data import Data from .const import * from .title import TitleServlet @@ -1206,7 +1206,7 @@ app_billing = Starlette( Route("/request", billing.handle_billing_request, methods=["POST"]), Route("/request/", billing.handle_billing_request, methods=["POST"]), ], - on_startup=[billing.startup] + lifespan=create_lifespan(billing.startup), ) allnet = AllnetServlet(cfg, cfg_dir) @@ -1229,5 +1229,5 @@ if cfg.allnet.allow_online_updates: app_allnet = Starlette( cfg.server.is_develop, route_lst, - on_startup=[allnet.startup] + lifespan=create_lifespan(allnet.startup) ) diff --git a/core/config.py b/core/config.py index 3a66e4b..0ba05db 100644 --- a/core/config.py +++ b/core/config.py @@ -555,6 +555,7 @@ class CoreConfig(dict): if envKey.endswith("_"): envKey = envKey[:-1] + envKey = envKey.upper() if envKey in os.environ: return os.environ.get(envKey) diff --git a/core/frontend.py b/core/frontend.py index 75528d9..7ddd065 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -20,6 +20,7 @@ from os import path, environ, mkdir, W_OK, access from core import CoreConfig, Utils from core.data import Data from core.const import AllnetCountryCode +from core.utils import create_lifespan # A-HJ-NP-Z SERIAL_LETTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] @@ -1209,4 +1210,4 @@ if not access(cfg.server.log_dir, W_OK): exit(1) fe = FrontendServlet(cfg, cfg_dir) -app = Starlette(cfg.server.is_develop, fe.get_routes(), on_startup=[fe.startup]) +app = Starlette(cfg.server.is_develop, fe.get_routes(), lifespan=create_lifespan(fe.startup)) diff --git a/core/utils.py b/core/utils.py index 92f9bf5..b8b5b12 100644 --- a/core/utils.py +++ b/core/utils.py @@ -6,6 +6,7 @@ from os import walk from types import ModuleType from typing import Any, Dict, Optional import math +from contextlib import asynccontextmanager import jwt from starlette.requests import Request @@ -153,3 +154,12 @@ def decode_sega_auth_key( except Exception as e: logger.error(f"Unknown exception occoured when decoding Sega Auth Key! {e}") return None + + +def create_lifespan(on_startup): + @asynccontextmanager + async def lifespan(app): + on_startup() + yield + + return lifespan diff --git a/docker-compose.yml b/docker-compose.yml index beab3a7..8e2257d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: environment: CFG_DEV: 1 + CFG_CORE_SERVER_LISTEN_ADDRESS: 0.0.0.0 CFG_CORE_SERVER_HOSTNAME: 0.0.0.0 CFG_CORE_DATABASE_HOST: ma.db CFG_CORE_MEMCACHED_HOSTNAME: ma.memcached @@ -31,7 +32,7 @@ services: db: hostname: ma.db - image: yobasystems/alpine-mariadb:10.11.5 + image: yobasystems/alpine-mariadb:11.4.9 environment: MYSQL_DATABASE: aime MYSQL_USER: aime diff --git a/entrypoint.sh b/entrypoint.sh index aa95ca8..87b1ff8 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,10 +2,10 @@ if [[ -z "${CFG_DEV}" ]]; then echo Production mode - python3 index.py + exec python3 index.py else echo Development mode python3 dbutils.py create - nodemon -w aime --legacy-watch index.py + exec python3 index.py fi diff --git a/requirements.txt b/requirements.txt index 4a10c44..44f1c26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ mypy wheel pytz pyyaml -sqlalchemy==1.4.46 +sqlalchemy<2.0 aiomysql pyopenssl service_identity