diff --git a/backend/Dockerfile b/backend/Dockerfile index a672786..f659e6a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -16,4 +16,4 @@ RUN mkdir -p /app/geo COPY geo/ /app/geo/ EXPOSE 8000 -CMD ["gunicorn", "app.main:app", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000", "--workers", "2", "--timeout", "120"] +CMD ["gunicorn", "app.main:app", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000", "--workers", "1", "--timeout", "120"] diff --git a/backend/app/main.py b/backend/app/main.py index cc4701f..81f0db4 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -106,7 +106,13 @@ async def lifespan(app: FastAPI): # Create tables on startup, then patch any missing columns async with engine.begin() as conn: await conn.run_sync(_cleanup_orphaned_sequences) - await conn.run_sync(Base.metadata.create_all) + try: + await conn.run_sync(Base.metadata.create_all) + except Exception as e: + if "duplicate" in str(e).lower(): + print(f" → Tables already exist (partial creation from prior restart): {e}") + else: + raise await conn.run_sync(_migrate_add_missing_columns) # Auto-seed if database is empty @@ -117,7 +123,7 @@ async def lifespan(app: FastAPI): print(" → Database is empty — running seed...") from seed import seed as run_seed await run_seed() - return # Full seed already included station config + print(" ✓ Full seed completed (skipping station config check)") # Ensure station config exists (runs even if DB already had data) async with async_session() as session: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index dfdb8fc..c2f7d6e 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,6 +2,9 @@ # Render config templates with environment variables, then start nginx. set -e +# Ensure nginx can write to the shared logs directory +mkdir -p /logs && chown nginx:nginx /logs + sed "s|__API_UPSTREAM__|${API_UPSTREAM}|g" /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf envsubst '${API_PUBLIC_URL}' < /usr/share/nginx/html/config.json.template > /usr/share/nginx/html/config.json