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 Instance | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install dependencies | |
| run: | | |
| npm ci --include=optional --legacy-peer-deps || (rm -rf node_modules && npm install --legacy-peer-deps) | |
| - name: Run linter | |
| run: npm run lint | |
| - name: Build project | |
| run: npm run build | |
| deploy: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ secrets.DOCKER_USERNAME }}/final-fe:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Deploy to GCP VM | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.GCP_VM_HOST }} | |
| username: ${{ secrets.GCP_VM_USERNAME }} | |
| key: ${{ secrets.GCP_VM_SSH_KEY }} | |
| script: | | |
| # HTTPS 설정 파일 찾기 | |
| HTTPS_DIR="" | |
| for dir in ~ /home/zkzkasd /home/ubuntu /root; do | |
| if [ -f "$dir/docker-compose.https.yml" ]; then | |
| HTTPS_DIR="$dir" | |
| echo "✅ HTTPS 설정을 찾았습니다: $HTTPS_DIR" | |
| break | |
| fi | |
| done | |
| # HTTPS Docker Compose 파일이 있는지 확인 | |
| if [ -z "$HTTPS_DIR" ]; then | |
| echo "❌ HTTPS 설정이 되어있지 않습니다!" | |
| echo "먼저 서버에서 add-https-to-existing.sh 스크립트를 실행해주세요." | |
| echo "확인된 디렉토리들:" | |
| ls -la ~/docker-compose* 2>/dev/null || echo " ~/docker-compose* 없음" | |
| ls -la /home/zkzkasd/docker-compose* 2>/dev/null || echo " /home/zkzkasd/docker-compose* 없음" | |
| ls -la /home/ubuntu/docker-compose* 2>/dev/null || echo " /home/ubuntu/docker-compose* 없음" | |
| exit 1 | |
| fi | |
| # 올바른 디렉토리로 이동 | |
| cd "$HTTPS_DIR" | |
| # 환경 변수 파일 생성/업데이트 | |
| echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" > .env | |
| # 기존 컨테이너 중지 및 제거 | |
| docker-compose -f docker-compose.https.yml down || true | |
| # 오래된 이미지 제거 | |
| docker rmi ${{ secrets.DOCKER_USERNAME }}/final-fe:latest || true | |
| # 최신 이미지 풀 및 실행 | |
| docker-compose -f docker-compose.https.yml pull | |
| docker-compose -f docker-compose.https.yml up -d | |
| # 사용하지 않는 이미지 정리 | |
| docker image prune -f | |
| # 배포 상태 확인 | |
| sleep 10 | |
| docker-compose -f docker-compose.https.yml ps | |
| echo "✅ GCP VM HTTPS 배포 완료: https://serverway.shop" |