Skip to content

Commit

Permalink
[FEAT] 깃허브 액션 CI/CD추가, OpenAI 상태 확인 API
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeYuChul committed Sep 19, 2024
1 parent 6a31d65 commit 00ca2f0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy to EC2

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ec2-user/Starting_Block_PDFGPT
git pull origin main
sudo reboot
verify:
needs: deploy
runs-on: ubuntu-latest

steps:
- name: Wait for EC2 to reboot
run: sleep 90 # 90초(1분30초) 정도 기다렸다가 서버가 부팅 완료될 시간을 줌

- name: Check server status
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo systemctl status starting_block_pdfgpt.service
- name: Check API Documentation
run: |
curl -I https://pdfgpt.startingblock.co.kr/docs
23 changes: 23 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,29 @@ async def delete_thread(thread_id: str):
return {"id": thread_id, "object": "thread.deleted", "deleted": True}
except Exception as e:
raise HTTPException(status_code=500, detail="스레드를 삭제하는 동안 오류가 발생했습니다.")

# API 상태 확인
@app.get("/gpt/api_status", tags=["GPT"], summary='API 상태 확인')
async def api_status():
try:
# OpenAI 상태 API 호출
async with httpx.AsyncClient() as client:
response = await client.get('https://status.openai.com/api/v2/status.json')
if response.status_code == 200:
status_data = response.json()
indicator = status_data.get('status', {}).get('indicator', 'unknown')

# 상태에 따라 메시지 반환
if indicator in ['major', 'critical']:
return {"status": "caution", "message": "OpenAI API에 문제가 있습니다. 현재 사용을 주의하세요."}
elif indicator in ['minor', 'none']:
return {"status": "good", "message": "OpenAI API가 정상적으로 동작하고 있습니다."}
else:
return {"status": "unknown", "message": "상태를 확인할 수 없습니다."}
else:
raise HTTPException(status_code=500, detail="OpenAI 상태 API를 불러올 수 없습니다.")
except Exception as e:
raise HTTPException(status_code=500, detail="API 호출 중 오류가 발생했습니다.")

if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=5001, timeout_keep_alive=60)

0 comments on commit 00ca2f0

Please sign in to comment.