Merge pull request #13 from Myaongi/refactor/#11 #5
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 VM on GCP | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| workflow_dispatch: | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Free up disk space | |
| run: | | |
| echo "=== 디스크 정리 전 상태 ===" | |
| df -h | |
| # 불필요한 대용량 패키지 제거 (약 10GB 확보) | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /usr/local/lib/android | |
| sudo rm -rf /opt/ghc | |
| sudo rm -rf /opt/hostedtoolcache/CodeQL | |
| # Docker 캐시 정리 | |
| docker system prune -af | |
| # APT 캐시 정리 | |
| sudo apt-get clean | |
| echo "=== 디스크 정리 후 상태 ===" | |
| df -h | |
| - name: Get Git short SHA | |
| id: vars | |
| run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Create config.py | |
| run: | | |
| echo "${{ secrets.CONFIG_PY }}" > app/domain/config.py | |
| ls -la yolov8s.pt | |
| echo "config.py created from GitHub Secret" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest | |
| ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:${{ steps.vars.outputs.sha }} | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:buildcache | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:buildcache,mode=max | |
| build-args: | | |
| BUILDKIT_INLINE_CACHE=1 | |
| - name: Deploy to VM | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.VM_HOST }} | |
| username: ${{ secrets.VM_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # 디스크 공간 정리 (용량 최적화) | |
| docker system df | |
| # 사용하지 않는 이미지만 안전하게 정리 | |
| docker image prune -af | |
| docker container prune -f | |
| docker system df | |
| # 기존 컨테이너 중지 및 제거 (있을 경우) | |
| docker stop gangajikimi-api || true | |
| docker rm gangajikimi-api || true | |
| # 최신 이미지 pull | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest | |
| # 새 컨테이너 실행 | |
| docker run -d \ | |
| --name gangajikimi-api \ | |
| --restart unless-stopped \ | |
| -p 8000:8000 \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest | |
| echo "=== 배포 완료 ===" | |
| docker ps | grep gangajikimi-api |