-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (75 loc) · 2.8 KB
/
Copy pathCD.yml
File metadata and controls
90 lines (75 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Deploy FastAPI to EC2
on:
push:
branches: [ main ]
paths:
- "main.py"
- "requirements.txt"
- ".github/workflows/CD.yml"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# =============================
# 1) EC2에 전체 FastAPI 프로젝트 업로드
# =============================
- name: Upload FastAPI to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
port: ${{ secrets.EC2_PORT }}
source: main.py,requirements.txt
target: "/home/ubuntu/Localy/fastapi"
overwrite: true
strip_components: 0
# =============================
# 2) FastAPI 재빌드 & 재시작
# =============================
- name: Build & Restart FastAPI Container
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
port: ${{ secrets.EC2_PORT }}
timeout: 600s # SSH connection idle timeout (중요!)
command_timeout: 20m # 실행 전체 timeout
script: |
set -euo pipefail
cd /home/ubuntu/Localy
echo "[1/4] docker compose 검사"
docker compose config >/dev/null
echo "[2/4] fastapi 빌드 & 교체"
docker compose up -d --build fastapi
echo "[3/4] nginx reload"
docker exec nginx-container nginx -t
docker exec nginx-container nginx -s reload
# echo "[4/4] FastAPI Health Check"
# # 내부(nginx → fastapi)
# if ! docker exec nginx-container curl -fsS http://fastapi:8000/textEmotion/health >/dev/null; then
# echo "::error::❌ 내부 헬스체크 실패 (nginx → fastapi)"
# docker logs fastapi-container --tail=100 || true
# docker logs nginx-container --tail=100 || true
# exit 1
# fi
# echo "✅ 내부 Health OK"
# # 외부(HTTPS)
# ok=0
# for i in $(seq 1 20); do
# if curl -fsS https://api.localy-maker.shop/health >/dev/null; then
# echo "✅ 외부 Health OK"
# ok=1
# break
# fi
# echo "외부 Health 대기중... ($i/20)"
# sleep 2
# done
# if [ "$ok" -eq 0 ]; then
# echo "::error::❌ 외부 헬스체크 실패"
# docker logs fastapi-container --tail=200 || true
# fi
echo "🚀 FastAPI Deploy Complete!"