.env에서 서버 바인딩(HOST/PORT/LOG_LEVEL/RELOAD) 받아오기
- config.Settings에 host/port/log_level/reload 필드 추가
- app/main.py에 main() + __main__ 진입점 추가 (python -m app.main)
- Dockerfile: python:3.13-slim 베이스로, CMD를 python -m app.main 으로 변경
- docker-compose: env_file 사용, ports를 ${PORT} 변수화
- 환경변수 PORT=N 으로 override 가능 (uvicorn 직접 실행도 그대로 지원)
This commit is contained in:
1 parent
bc40ace2fd
commit
f31ef142e8
6 files changed
+71
-14
No files matched your search
@@ -7,6 +7,12 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
||||
|
||||
# 서버 바인딩
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
log_level: str = "info" # debug / info / warning / error
|
||||
reload: bool = False # 개발용 자동 재시작
|
||||
|
||||
api_keys: str = "combooks-key-change-me,baikal-key-change-me"
|
||||
engine_version: str = "o2o-plagiarism-2.0.0-pdf-v1.2"
|
||||
reference_corpus_dir: str = "./data/reference"
|
||||
|
||||
+23
@@ -65,3 +65,26 @@ async def root() -> FileResponse:
|
||||
return FileResponse(str(index))
|
||||
from fastapi.responses import JSONResponse
|
||||
return JSONResponse({"service": "o2o-plagiarism-api", "docs": "/docs"})
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""`.env` 의 HOST/PORT/LOG_LEVEL/RELOAD 를 읽어 서버 기동.
|
||||
|
||||
사용법:
|
||||
python -m app.main # .env 따라 실행
|
||||
PORT=9000 python -m app.main # 환경변수 override
|
||||
"""
|
||||
import uvicorn
|
||||
|
||||
settings = get_settings()
|
||||
uvicorn.run(
|
||||
"app.main:app",
|
||||
host=settings.host,
|
||||
port=settings.port,
|
||||
log_level=settings.log_level,
|
||||
reload=settings.reload,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user