From 941a137aadcd11e15d07b543a747ebe5766886d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=80=EC=A7=80?= Date: Sun, 24 Aug 2025 14:50:22 +0900 Subject: [PATCH] feat: add FastAPI app & MySQL docker setup --- .gitignore | 17 ++++++ Dockerfile | 11 ++++ docker-compose.yml | 27 ++++++++++ .../.github}/ISSUE_TEMPLATE/bug_report.md | 0 .../ISSUE_TEMPLATE/feature_request.md | 0 README.md => model/README.md | 0 model/app/core/config.py | 16 ++++++ model/app/db/session.py | 13 +++++ model/app/main.py | 9 ++++ model/mysql/my.cnf | 10 ++++ requirements.txt | 53 +++++++++++++++++++ 11 files changed, 156 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml rename {.github => model/.github}/ISSUE_TEMPLATE/bug_report.md (100%) rename {.github => model/.github}/ISSUE_TEMPLATE/feature_request.md (100%) rename README.md => model/README.md (100%) create mode 100644 model/app/core/config.py create mode 100644 model/app/db/session.py create mode 100644 model/app/main.py create mode 100644 model/mysql/my.cnf create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7b4eb0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# 가상환경 +ict_2025/ +venv/ + +# Python +__pycache__/ +*.pyc +*.pyo + +# 환경파일 +.env + +# OS 파일 +.DS_Store + +# MySQL 데이터 +model/mysql/data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..801e713 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.10.5 + +RUN pip install --upgrade pip +WORKDIR /code + +COPY ./requirements.txt /code/requirements.txt +RUN pip install --no-cache-dir -r /code/requirements.txt + +COPY ./model /code/model + +CMD ["uvicorn", "model.app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..39d25c8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3.8" + +services: + db: + image: mysql:8.0.29 + container_name: mysql8029 + ports: + - "3307:3306" + volumes: + - ./mysql/conf.d:/etc/mysql/conf.d + - ./mysql/data:/var/lib/mysql + env_file: .env + environment: + TZ: Asia/Seoul + restart: always + + server: + build: + context: . + dockerfile: ./Dockerfile + container_name: fastapi-server + ports: + - "8000:8000" + env_file: .env + depends_on: + - db + restart: always diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/model/.github/ISSUE_TEMPLATE/bug_report.md similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_report.md rename to model/.github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/model/.github/ISSUE_TEMPLATE/feature_request.md similarity index 100% rename from .github/ISSUE_TEMPLATE/feature_request.md rename to model/.github/ISSUE_TEMPLATE/feature_request.md diff --git a/README.md b/model/README.md similarity index 100% rename from README.md rename to model/README.md diff --git a/model/app/core/config.py b/model/app/core/config.py new file mode 100644 index 0000000..a8a48ac --- /dev/null +++ b/model/app/core/config.py @@ -0,0 +1,16 @@ +from pydantic import BaseSettings +from functools import lru_cache + +class Settings(BaseSettings): + MYSQL_USER: str + MYSQL_PASSWORD: str + MYSQL_HOST: str + MYSQL_PORT: int + MYSQL_DATABASE: str + + class Config: + env_file = ".env" + +@lru_cache() +def get_setting(): + return Settings() diff --git a/model/app/db/session.py b/model/app/db/session.py new file mode 100644 index 0000000..ef0b7ae --- /dev/null +++ b/model/app/db/session.py @@ -0,0 +1,13 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from ..core.config import get_setting + +settings = get_setting() + +SQLALCHEMY_DATABASE_URL = ( + f"mysql+pymysql://{settings.MYSQL_USER}:{settings.MYSQL_PASSWORD}" + f"@{settings.MYSQL_HOST}:{settings.MYSQL_PORT}/{settings.MYSQL_DATABASE}" +) + +engine = create_engine(SQLALCHEMY_DATABASE_URL) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) diff --git a/model/app/main.py b/model/app/main.py new file mode 100644 index 0000000..ee6e094 --- /dev/null +++ b/model/app/main.py @@ -0,0 +1,9 @@ +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +async def root(): + return {"message": "Hello FastAPI"} + + diff --git a/model/mysql/my.cnf b/model/mysql/my.cnf new file mode 100644 index 0000000..dd62716 --- /dev/null +++ b/model/mysql/my.cnf @@ -0,0 +1,10 @@ +[client] +default-character-set = utf8mb4 + +[mysql] +default-character-set = utf8mb4 + +[mysqld] +character-set-client-handshake = FALSE +character-set-server = utf8mb4 +collation-server = utf8mb4_unicode_ci \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6ae747a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,53 @@ +# FastAPI 기본 +fastapi>=0.112.0 +uvicorn[standard]>=0.30.0 +python-dotenv>=1.0.1 +pydantic>=2.7.0 +python-multipart>=0.0.9 + +# DB 연동 +sqlalchemy>=2.0.30 +pymysql>=1.1.0 + +# OpenAI & LangChain +openai>=1.40.0 +tiktoken>=0.7.0 +langchain>=0.2.10 +langchain-community>=0.2.10 +langchain-openai>=0.1.20 +langchain-core==0.3.74 +langchain-google-genai==2.1.9 +langchain-google-vertexai==2.0.28 +langchain-text-splitters==0.3.9 +langsmith==0.4.14 + +# Vector DB & NLP +faiss-cpu>=1.8.0.post1 +sentence-transformers>=3.0.1 +chromadb>=0.5.5 +pinecone-client>=4.1.0 +qdrant-client>=1.9.1 +pymilvus>=2.4.4 + +# 문서 처리 +pypdf>=4.2.0 +pdfplumber>=0.11.0 +python-docx>=1.1.0 + +# 데이터 분석 +numpy>=1.26.4 +pandas>=2.2.2 +scikit-learn>=1.5.1 + +# 오디오/비디오 처리 +pydub>=0.25.1 +soundfile>=0.12.1 +ffmpeg-python>=0.2.0 +faster-whisper>=1.0.0 + +# NLP 추가 +sacrebleu>=2.4.0 +nltk>=3.9 + +# 유틸 +requests==2.32.4