diff --git a/.github/workflows/icurri_deploy.yml b/.github/workflows/icurri_deploy.yml index f35d1e5..ffffbd2 100644 --- a/.github/workflows/icurri_deploy.yml +++ b/.github/workflows/icurri_deploy.yml @@ -1,8 +1,8 @@ -name: DOTFLOW_SERVER_DEPLOY +name: ICURRI_DEPLOY on: push: - branches: [ "release" ] + branches: [ "release" ] jobs: ci: @@ -81,22 +81,12 @@ jobs: needs: ci name: CD runs-on: ubuntu-latest - permissions: - id-token: write - contents: read env: - AWS_REGION: ap-northeast-2 + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} steps: - # AWS 자격 증명 설정 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v3 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} - - # SSH로 EC2에 배포 + # Deploy to EC2 (Release Branch) - name: Deploy to EC2 (Release Branch) if: github.ref == 'refs/heads/release' uses: appleboy/ssh-action@master @@ -105,26 +95,15 @@ jobs: username: ubuntu key: ${{ secrets.RELEASE_SSH_KEY }} script: | - # 컨테이너 중지 및 제거 - sudo docker ps -q | xargs -r sudo docker stop || true - sudo docker ps -aq | xargs -r sudo docker rm || true - - # 사용하지 않는 이미지 및 시스템 정리 - sudo docker images -q | xargs -r sudo docker rmi || true - sudo docker system prune -af || true - - # ECR 로그인 - aws ecr get-login-password --region ${{ env.AWS_REGION }} | sudo docker login --username AWS --password-stdin ${{ secrets.ECR_URI }} - - # Docker 이미지 풀 + # Stop and remove all containers except MongoDB + sudo docker ps -a -q --filter "name!=mongoDB" | xargs -r sudo docker stop || true + sudo docker ps -a -q --filter "name!=mongoDB" | xargs -r sudo docker rm || true + sudo docker images -q | xargs -r docker rmi || true + sudo docker system prune -af + + # Docker login and pull new image from ECR + aws ecr get-login-password --region ap-northeast-2 | sudo docker login --username AWS --password-stdin ${{ secrets.ECR_URI }} sudo docker pull ${{ secrets.ECR_URI }}:${{ github.sha }} - - # 새 컨테이너 실행 - sudo docker run --name dotflow-dev-repo -d \ - -e SPRING_PROFILE=dev \ - -e TZ=Asia/Seoul \ - -e SERVER=true \ - -p 8080:8080 \ - ${{ secrets.ECR_URI }}:${{ github.sha }} - - + + # Run the new container + sudo docker run --name dotflow-dev-repo -d -e SPRING_PROFILE=dev -e TZ=Asia/Seoul -e SERVER=true -p 8080:8080 ${{ secrets.ECR_URI }}:${{ github.sha }}