Skip to content

Commit 6ae5eda

Browse files
committed
fix: port 변경 및 workflow 추가
1 parent 83d5e9e commit 6ae5eda

File tree

7 files changed

+84
-14
lines changed

7 files changed

+84
-14
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MONGODB_DB_NAME=langgraph_db
4545
# API 서버 설정
4646
# ============================================
4747
API_HOST=0.0.0.0
48-
API_PORT=8123
48+
API_PORT=8000
4949

5050
# CORS 허용 Origin (쉼표로 구분)
5151
CORS_ORIGINS=http://localhost:3000,http://localhost:8000

.github/workflows/deploy.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy to AWS EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Copy files to EC2
18+
uses: appleboy/scp-action@v0.1.7
19+
with:
20+
host: ${{ secrets.EC2_HOST }}
21+
username: ubuntu
22+
key: ${{ secrets.EC2_SSH_KEY }}
23+
source: "."
24+
target: "/home/ubuntu/gitfit-ai"
25+
overwrite: true
26+
27+
- name: Build and Deploy on EC2
28+
uses: appleboy/ssh-action@v1.0.3
29+
with:
30+
host: ${{ secrets.EC2_HOST }}
31+
username: ubuntu
32+
key: ${{ secrets.EC2_SSH_KEY }}
33+
script: |
34+
cd /home/ubuntu/gitfit-ai
35+
36+
# 기존 컨테이너 중지 및 삭제
37+
docker stop gitfit-ai || true
38+
docker rm gitfit-ai || true
39+
40+
# Docker 이미지 빌드
41+
docker build -t gitfit-ai:latest .
42+
43+
# 새 컨테이너 실행
44+
docker run -d \
45+
--name gitfit-ai \
46+
--restart unless-stopped \
47+
-p 8000:8000 \
48+
--env-file /home/ubuntu/.env \
49+
gitfit-ai:latest
50+
51+
# 사용하지 않는 이미지 정리
52+
docker image prune -f

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ COPY src /app/src
2424

2525
RUN uv pip install --system .
2626

27-
EXPOSE 8123
27+
EXPOSE 8000
2828

2929
ENV PYTHONPATH=/app:/app/src
3030
ENV PYTHONUNBUFFERED=1
3131

3232
HEALTHCHECK --interval=180s --timeout=10s --start-period=40s --retries=3 \
33-
CMD python -c "import requests; requests.get('http://localhost:8123/health')" || exit 1
33+
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
3434

35-
CMD ["uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8123"]
35+
CMD ["uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000"]

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ langgraph-init/
7979
## 🏗️ 아키텍처
8080

8181
### 계층 구조
82+
8283
```
8384
┌─────────────────────────────────────────┐
8485
│ FastAPI Controller │ # HTTP 엔드포인트
@@ -97,7 +98,9 @@ langgraph-init/
9798
```
9899

99100
### BaseNode 패턴
101+
100102
모든 노드는 `BaseNode`를 상속받아 일관된 인터페이스 제공:
103+
101104
- 자동 로깅 (시작/종료, 소요시간)
102105
- 예외 처리 (ValueError → 400, Exception → 500)
103106
- 비동기 실행 (`async def execute()`)
@@ -132,6 +135,7 @@ cp .env.example .env
132135
```
133136

134137
**.env 예시:**
138+
135139
```bash
136140
# === 모델 설정 ===
137141
CHAT_MODEL=gpt-4o-mini
@@ -150,7 +154,7 @@ MONGODB_DB_NAME=langgraph_db
150154

151155
# === API 서버 ===
152156
API_HOST=0.0.0.0
153-
API_PORT=8123
157+
API_PORT=8000
154158
CORS_ORIGINS=http://localhost:3000,http://localhost:8000
155159

156160
# === 로깅 ===
@@ -170,17 +174,17 @@ TZ=Asia/Seoul
170174
python main.py
171175

172176
# 또는 uvicorn 직접 실행
173-
uvicorn main:app --reload --host 0.0.0.0 --port 8123
177+
uvicorn main:app --reload --host 0.0.0.0 --port 8000
174178
```
175179

176180
### 4. API 테스트
177181

178182
```bash
179183
# 헬스 체크
180-
curl http://localhost:8123/api/v1/health
184+
curl http://localhost:8000/api/v1/health
181185

182186
# 채팅 요청
183-
curl -X POST http://localhost:8123/api/v1/chat \
187+
curl -X POST http://localhost:8000/api/v1/chat \
184188
-H "Content-Type: application/json" \
185189
-d '{
186190
"user_id": "user123",
@@ -194,12 +198,14 @@ curl -X POST http://localhost:8123/api/v1/chat \
194198
### 5. API 문서 확인
195199

196200
서버 실행 후 브라우저에서:
197-
- **Swagger UI**: http://localhost:8123/docs
198-
- **ReDoc**: http://localhost:8123/redoc
201+
202+
- **Swagger UI**: http://localhost:8000/docs
203+
- **ReDoc**: http://localhost:8000/redoc
199204

200205
## 🔧 지원하는 모델
201206

202207
### 채팅 모델
208+
203209
```bash
204210
# OpenAI
205211
CHAT_MODEL=gpt-4o
@@ -217,6 +223,7 @@ CHAT_MODEL=gemini-1.5-flash
217223
```
218224

219225
### 임베딩 모델
226+
220227
```bash
221228
# OpenAI
222229
EMBEDDING_MODEL=text-embedding-3-large
@@ -263,6 +270,7 @@ logger.error("에러 메시지")
263270
```
264271

265272
**로그 출력 예시:**
273+
266274
```
267275
2025-10-29 14:30:25 KST [DEBUG] agents.nodes.example - [example] 노드 실행 시작
268276
2025-10-29 14:30:25 KST [DEBUG] agents.nodes.example - 입력 메시지 수: 1
@@ -298,12 +306,13 @@ docker-compose down
298306

299307
# 개별 빌드
300308
docker build -t langgraph-app .
301-
docker run -p 8123:8123 --env-file .env langgraph-app
309+
docker run -p 8000:8000 --env-file .env langgraph-app
302310
```
303311

304312
## 🎯 주요 개발 패턴
305313

306314
### 1. DTO 기반 API 통신
315+
307316
```python
308317
# Request DTO
309318
class ChatRequestDTO(BaseModel):
@@ -321,6 +330,7 @@ class ChatResponseDTO(BaseModel):
321330
```
322331

323332
### 2. Service 계층 패턴
333+
324334
```python
325335
class ChatService:
326336
async def process_chat(self, request: ChatRequestDTO) -> ChatResponseDTO:
@@ -333,6 +343,7 @@ class ChatService:
333343
```
334344

335345
### 3. Repository 패턴
346+
336347
```python
337348
class ChatHistoryRepository:
338349
async def save_chat(self, chat_history, message_pair):
@@ -347,13 +358,15 @@ class ChatHistoryRepository:
347358
## 💡 개발 팁
348359

349360
### 모델 교체
361+
350362
```bash
351363
# 환경변수만 변경하면 자동으로 다른 모델 사용
352364
export CHAT_MODEL=claude-3-5-sonnet-20241022
353365
export ANTHROPIC_API_KEY=sk-ant-...
354366
```
355367

356368
### 새로운 도구 추가
369+
357370
```python
358371
# src/agents/tools/my_tool.py
359372
from langchain_core.tools import tool
@@ -365,6 +378,7 @@ def my_custom_tool(query: str) -> str:
365378
```
366379

367380
### 프롬프트 관리
381+
368382
```python
369383
# src/agents/prompts/prompt_provider.py 활용
370384
class PromptProvider:
@@ -379,4 +393,3 @@ class PromptProvider:
379393
- [FastAPI 공식 문서](https://fastapi.tiangolo.com/)
380394
- [MongoDB Python Driver](https://www.mongodb.com/docs/drivers/motor/)
381395
- [Pydantic](https://docs.pydantic.dev/)
382-

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
dockerfile: Dockerfile
3232
container_name: langgraph-app-server
3333
ports:
34-
- "8123:8123"
34+
- "8000:8000"
3535
env_file:
3636
- ./.env
3737
# .env 파일의 MONGODB_URI (Atlas) 사용

src/api/config/server_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def create_app() -> FastAPI:
5757
# 라우터 등록
5858
app.include_router(report_router)
5959

60+
# Health check 엔드포인트
61+
@app.get("/health", tags=["health"])
62+
async def health_check():
63+
return {"status": "healthy"}
64+
6065
logger.info("FastAPI 앱이 성공적으로 생성되었습니다")
6166

6267
return app

src/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Settings:
4242

4343
# === API 서버 설정 ===
4444
API_HOST: str = os.getenv("API_HOST", "0.0.0.0")
45-
API_PORT: int = int(os.getenv("API_PORT", "8123"))
45+
API_PORT: int = int(os.getenv("API_PORT", "8000"))
4646
CORS_ORIGINS: list[str] = os.getenv("CORS_ORIGINS", "").split(",") if os.getenv("CORS_ORIGINS") else []
4747

4848
# === 로깅 설정 ===

0 commit comments

Comments
 (0)