Skip to content

Commit 151c7e2

Browse files
배포 용 fastapi 세팅
0 parents  commit 151c7e2

File tree

10 files changed

+709
-0
lines changed

10 files changed

+709
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
env/
8+
build/
9+
develop-eggs/
10+
dist/
11+
downloads/
12+
eggs/
13+
.eggs/
14+
lib/
15+
lib64/
16+
parts/
17+
sdist/
18+
var/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual Environment
24+
venv/
25+
ENV/
26+
.env
27+
28+
# IDE
29+
.idea/
30+
.vscode/
31+
*.swp
32+
*.swo
33+
34+
# OS
35+
.DS_Store
36+
Thumbs.db

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM python:3.9-slim
2+
3+
# 시스템 패키지 업데이트 및 필요한 의존성 설치
4+
RUN apt-get update && apt-get install -y \
5+
build-essential \
6+
curl \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
WORKDIR /app
10+
11+
# Poetry 설치 시 네트워크 타임아웃 설정 추가
12+
ENV POETRY_HTTP_TIMEOUT=120
13+
14+
# Poetry 설치 및 PATH 설정
15+
RUN curl -sSL https://install.python-poetry.org | python3 - && \
16+
ln -s /root/.local/bin/poetry /usr/local/bin/poetry
17+
18+
# Poetry 설정
19+
RUN poetry config virtualenvs.create false
20+
21+
# 의존성 파일 복사 및 설치
22+
COPY pyproject.toml poetry.lock* ./
23+
RUN poetry install --only main --no-root --no-interaction
24+
25+
# 애플리케이션 코드 복사
26+
COPY . .
27+
28+
EXPOSE 8000
29+
30+
# Python 경로에 현재 디렉토리 추가
31+
ENV PYTHONPATH=/app
32+
33+
# 전체 경로로 uvicorn 실행
34+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# FastAPI 배포 연습 프로젝트
2+
3+
간단한 FastAPI 애플리케이션 배포 연습을 위한 프로젝트입니다. Poetry를 사용하여 의존성을 관리합니다.
4+
5+
## 프로젝트 구조
6+
7+
```
8+
fastapi_deploy_tutorial/
9+
├── app/ # 애플리케이션 패키지
10+
│ ├── api/ # API 엔드포인트
11+
│ │ ├── hello.py # Hello World 엔드포인트
12+
│ │ └── router.py # API 라우터 모음
13+
│ └── main.py # FastAPI 애플리케이션 정의
14+
├── pyproject.toml # Poetry 의존성 정의
15+
└── Dockerfile # Docker 이미지 정의
16+
```
17+
18+
## 개발 환경 설정
19+
20+
1. Poetry 설치 (아직 설치하지 않은 경우):
21+
22+
```bash
23+
curl -sSL https://install.python-poetry.org | python3 -
24+
```
25+
26+
2. 의존성 설치:
27+
28+
```bash
29+
poetry install
30+
```
31+
32+
## 로컬에서 실행하기
33+
34+
1. 애플리케이션 실행:
35+
36+
```bash
37+
uvicorn app.main:app --reload
38+
```
39+
40+
2. 브라우저에서 확인:
41+
- API 문서: http://localhost:8000/docs
42+
- 엔드포인트: http://localhost:8000/

app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# app 패키지 초기화

app/api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# api 패키지 초기화

app/api/hello.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()
4+
5+
@router.get("/")
6+
async def hello_world():
7+
return {"message": "Hello World!"}

app/api/router.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fastapi import APIRouter
2+
from app.api import hello
3+
4+
api_router = APIRouter()
5+
# Hello World 라우터 포함
6+
api_router.include_router(hello.router)

app/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from fastapi import FastAPI
2+
from app.api.router import api_router
3+
4+
app = FastAPI(title="배포 연습용 API")
5+
6+
# API 라우터 등록
7+
app.include_router(api_router)

0 commit comments

Comments
 (0)