- Deploys Paper MC Minecraft Java server in offline-mode on host port 25565. - Deploys a FastAPI-based Web Admin panel on minecraft.arch-services.mywire.org (port 80/443). - Implements a layered FastAPI architecture (routers, schemas, services, database models). - Calculates deterministic version 3 Minecraft player UUIDs for player responses. - Resolves cross-container permission deadlocks by running the web container as UID 1000:1000. - Implements Write-Ahead Logging (WAL) and busy timeout to prevent SQLite concurrency lockouts. - Adds asynchronous database polling and API readiness middleware to prevent DB file initialization races. - Injects JWT_SECRET to persist administrator web sessions across restarts. - Integrates Minecraft service commands into the appctl shell management script. - Documents all containerization decisions in minecraft/adr.md.
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import os
|
|
import asyncio
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.responses import HTMLResponse, JSONResponse
|
|
import database
|
|
from routers import auth, users, admin
|
|
|
|
app = FastAPI(title="Minecraft Identity Manager API")
|
|
|
|
# Include Routers
|
|
app.include_router(auth.router)
|
|
app.include_router(users.router)
|
|
app.include_router(admin.router)
|
|
|
|
# Readiness middleware to block API requests until database is ready
|
|
@app.middleware("http")
|
|
async def db_readiness_middleware(request: Request, call_next):
|
|
# Only intercept /api/ requests
|
|
if request.url.path.startswith("/api/") and not database.DB_READY:
|
|
return JSONResponse(
|
|
status_code=503,
|
|
content={"detail": "Authentication system is initializing, please try again shortly."}
|
|
)
|
|
return await call_next(request)
|
|
|
|
# Asynchronous background loop to poll database readiness
|
|
async def database_polling_loop():
|
|
while not database.check_db_ready():
|
|
await asyncio.sleep(2)
|
|
|
|
@app.on_event("startup")
|
|
async def on_startup():
|
|
asyncio.create_task(database_polling_loop())
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
def index():
|
|
templates_dir = "/app/templates"
|
|
with open(os.path.join(templates_dir, "index.html"), "r") as f:
|
|
return f.read()
|