Deploy fastAPI app to docker hub by BHyeonKim #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy fastAPI app | |
| run-name: Deploy fastAPI app to docker hub by ${{github.actor}} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Remove old files | |
| uses: appleboy/ssh-action@v1.2.2 | |
| with: | |
| host: ${{ secrets.AI_SERVER_HOST }} | |
| username: ${{ secrets.AI_SERVER_USERNAME }} | |
| key: ${{ secrets.AI_SERVER_KEY }} | |
| port: ${{ secrets.AI_SERVER_PORT }} | |
| script: | | |
| rm -rf ~/chatbot || true | |
| mkdir ~/chatbot | |
| - name: Copy files via SSH | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.AI_SERVER_HOST }} | |
| username: ${{ secrets.AI_SERVER_USERNAME }} | |
| key: ${{ secrets.AI_SERVER_KEY }} | |
| port: ${{ secrets.AI_SERVER_PORT }} | |
| source: "." | |
| target: "~/chatbot" | |
| - name: Start chatbot service | |
| uses: appleboy/ssh-action@v1.2.2 | |
| with: | |
| host: ${{ secrets.AI_SERVER_HOST }} | |
| username: ${{ secrets.AI_SERVER_USERNAME }} | |
| key: ${{ secrets.AI_SERVER_KEY }} | |
| port: ${{ secrets.AI_SERVER_PORT }} | |
| script: | | |
| cd ~/chatbot | |
| python3 -m venv venv | |
| source venv/bin/activate | |
| pip install -r requirements.txt | |
| echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" > .env | |
| echo "TAVILY_API_KEY=${{ secrets.TAVILY_API_KEY }}" >> .env | |
| sudo chmod +x ./dependency.sh | |
| ./dependency.sh | |
| - name: Verify server status | |
| uses: appleboy/ssh-action@v1.2.2 | |
| with: | |
| host: ${{ secrets.AI_SERVER_HOST }} | |
| username: ${{ secrets.AI_SERVER_USERNAME }} | |
| key: ${{ secrets.AI_SERVER_KEY }} | |
| port: ${{ secrets.AI_SERVER_PORT }} | |
| script: | | |
| # 15초 대기 후 서버 상태 확인 | |
| sleep 15 | |
| echo "===== 서버 프로세스 확인 =====" | |
| ps aux | grep uvicorn | |
| ps aux | grep mlflow | |
| echo "===== 포트 사용 현황 =====" | |
| netstat -tulpn | grep 8000 || echo "8000번 포트가 사용되고 있지 않습니다." | |
| echo "===== 서버 응답 테스트 =====" | |
| curl -I http://localhost:8000 || echo "FastAPI 서버가 응답하지 않습니다." | |
| # uses: actions/checkout@v4 | |
| # - name: Create env file | |
| # run: | | |
| # echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" > .env | |
| # echo "TAVILY_KEY=${{ secrets.TAVILY_KEY }}" >> .env | |
| # - name: Build image | |
| # run: | | |
| # docker build -t ${{secrets.DOCKER_USERNAME}}/if-ai:latest . | |
| # - name: Login to Docker Hub | |
| # uses: docker/login-action@v3.4.0 | |
| # with: | |
| # username: ${{secrets.DOCKER_USERNAME}} | |
| # password: ${{secrets.DOCKER_TOKEN}} | |
| # - name: Push image to Docker hub | |
| # run: | | |
| # docker push ${{secrets.DOCKER_USERNAME}}/if-ai:latest |