fix: port 변경 및 workflow 추가 #1
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 to AWS EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Copy files to EC2 | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: "." | |
| target: "/home/ubuntu/gitfit-ai" | |
| overwrite: true | |
| - name: Build and Deploy on EC2 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| cd /home/ubuntu/gitfit-ai | |
| # 기존 컨테이너 중지 및 삭제 | |
| docker stop gitfit-ai || true | |
| docker rm gitfit-ai || true | |
| # Docker 이미지 빌드 | |
| docker build -t gitfit-ai:latest . | |
| # 새 컨테이너 실행 | |
| docker run -d \ | |
| --name gitfit-ai \ | |
| --restart unless-stopped \ | |
| -p 8000:8000 \ | |
| --env-file /home/ubuntu/.env \ | |
| gitfit-ai:latest | |
| # 사용하지 않는 이미지 정리 | |
| docker image prune -f |