Merge pull request #138 from Team-Festimate/main #21
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 | |
| on: | |
| push: | |
| branches: | |
| - release/** | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Jdk 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Push yml file | |
| run: | | |
| echo "${{ secrets.YML }}" > ./src/main/resources/application-prod.yml | |
| - name: Build with Gradle | |
| run: ./gradlew -x test clean build | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: Build and Push Docker Image | |
| run: | | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/festimate:latest . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/festimate:latest | |
| - name: Deploy via SSH with Blue-Green Strategy | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.HOST }} | |
| username: ${{ secrets.USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: ${{ secrets.PORT }} | |
| script: | | |
| # 로그인 | |
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
| # 현재 컨테이너 상태 확인 | |
| if docker ps | grep festimate-container-blue; then | |
| CURRENT=blue | |
| NEXT=green | |
| NEXT_PORT=8082 | |
| else | |
| CURRENT=green | |
| NEXT=blue | |
| NEXT_PORT=8081 | |
| fi | |
| echo "현재 운영 중: $CURRENT → 새로 띄울 컨테이너: $NEXT (port $NEXT_PORT)" | |
| # 🧹 이전 컨테이너 중지 및 제거 | |
| docker stop festimate-container-$NEXT || true | |
| docker rm festimate-container-$NEXT || true | |
| # 최신 이미지 pull 및 새 컨테이너 실행 | |
| docker pull ${{ secrets.DOCKER_USERNAME }}/festimate:latest | |
| docker run -d --rm -p $NEXT_PORT:8080 --name festimate-container-$NEXT ${{ secrets.DOCKER_USERNAME }}/festimate:latest | |
| # 헬스 체크 | |
| for i in {1..10}; do | |
| if curl -s http://localhost:$NEXT_PORT/actuator/health | grep '"status":"UP"'; then | |
| echo "🟢 새 컨테이너 헬스 체크 통과" | |
| break | |
| fi | |
| echo "🔁 헬스 체크 중..." | |
| sleep 3 | |
| done | |
| # Nginx 설정 전환 | |
| echo "🌐 Nginx 전환: $NEXT" | |
| sudo cp /etc/nginx/conf.d/backup/api-$NEXT.conf /etc/nginx/conf.d/api.conf | |
| sudo systemctl reload nginx | |
| # 이전 컨테이너 종료 | |
| docker stop festimate-container-$CURRENT || true | |
| echo "배포 완료 at $(date '+%Y-%m-%d %H:%M:%S')" |