Skip to content

Commit 4553063

Browse files
committed
GithubActions + Docker 배포 테스트
1 parent a9f7543 commit 4553063

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__/
2+
*.pyc
3+
*.pyo
4+
uploads/

.github/workflows/deploy.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Deploy FastAPI Backend to EC2
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
15+
- name: Copy to EC2 (carrot.db 제외)
16+
uses: appleboy/scp-action@master
17+
with:
18+
host: ${{ secrets.EC2_HOST }}
19+
username: ${{ secrets.EC2_USER }}
20+
key: ${{ secrets.EC2_KEY }}
21+
source: "."
22+
target: "~/backend-app"
23+
exclude: "carrot.db"
24+
25+
- name: SSH - Deploy Backend
26+
uses: appleboy/ssh-action@master
27+
with:
28+
host: ${{ secrets.EC2_HOST }}
29+
username: ${{ secrets.EC2_USER }}
30+
key: ${{ secrets.EC2_KEY }}
31+
script: |
32+
cd ~/backend-app
33+
docker-compose down
34+
docker-compose up -d --build

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY . .
9+
10+
# 업로드 디렉토리 보장
11+
RUN mkdir -p /app/uploads
12+
13+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.8'
2+
3+
services:
4+
backend:
5+
build: .
6+
container_name: fastapi-backend
7+
ports:
8+
- "8000:8000"
9+
volumes:
10+
- ./uploads:/app/uploads
11+
- ./carrot.db:/app/carrot.db
12+
restart: always

0 commit comments

Comments
 (0)