From 92ac8de1330e54b880121729c734067ad1038fe3 Mon Sep 17 00:00:00 2001 From: Namsoo315 Date: Wed, 5 Nov 2025 16:54:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20CD=20yml=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..fac33552 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,87 @@ +name: 🚀 Deploy to AWS ECS (Monew) + +on: + push: + branches: + - main + +permissions: + contents: read + id-token: write + +env: + AWS_REGION: ap-northeast-2 + ECR_REPOSITORY: monew-repo + ECS_CLUSTER: monew-cluster + ECS_SERVICE: monew-service + ECS_TASK_DEFINITION: monew-task + CONTAINER_NAME: monew-app + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: 📦 Checkout repository + uses: actions/checkout@v4 + + - name: 🔑 Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: ${{ env.AWS_REGION }} + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + role-session-name: github-actions + + - name: 🔐 Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: 🛠️ Build and push Docker image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: | + echo "🔨 Building Docker image..." + docker build -t $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:latest . + docker push $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:latest + + - name: 📄 Download current ECS Task Definition + run: | + aws ecs describe-task-definition \ + --task-definition $ECS_TASK_DEFINITION \ + --query taskDefinition \ + --output json > task-definition.json + + - name: 🧩 Update Task Definition with new image + run: | + NEW_IMAGE="${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest" + echo "✅ Updating container image to $NEW_IMAGE" + jq --arg IMAGE "$NEW_IMAGE" \ + '.containerDefinitions[0].image = $IMAGE' \ + task-definition.json > new-task-definition.json + + - name: 📝 Register new ECS Task Definition + id: register-task + run: | + NEW_TASK_DEF_ARN=$(aws ecs register-task-definition \ + --cli-input-json file://new-task-definition.json \ + --query "taskDefinition.taskDefinitionArn" \ + --output text) + echo "✅ New Task Definition ARN: $NEW_TASK_DEF_ARN" + echo "NEW_TASK_DEF_ARN=$NEW_TASK_DEF_ARN" >> $GITHUB_ENV + + - name: 🚀 Deploy new Task Definition to ECS Service + run: | + echo "Deploying new Task Definition to ECS..." + aws ecs update-service \ + --cluster $ECS_CLUSTER \ + --service $ECS_SERVICE \ + --task-definition $NEW_TASK_DEF_ARN + echo "✅ ECS Service update triggered successfully!" + + - name: ✅ Confirm Deployment + run: | + echo "Checking ECS deployment status..." + aws ecs describe-services \ + --cluster $ECS_CLUSTER \ + --services $ECS_SERVICE \ + --query "services[0].deployments" From 11b6668a39ca8f1addfc26fb521d895c1ac2ce4d Mon Sep 17 00:00:00 2001 From: Namsoo315 Date: Wed, 5 Nov 2025 16:54:53 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20docker=20yml=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SPRING_PROFILES_ACTIVE 변경 --- monew/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monew/Dockerfile b/monew/Dockerfile index db11ac17..89288a25 100644 --- a/monew/Dockerfile +++ b/monew/Dockerfile @@ -22,7 +22,7 @@ WORKDIR /app RUN yum update -y && yum install -y curl && yum clean all ENV SERVER_PORT=8080 \ - SPRING_PROFILES_ACTIVE=docker \ + SPRING_PROFILES_ACTIVE=local \ PROJECT_NAME=sb05-monew-team7 \ PROJECT_VERSION=1.0.0 From af94f8d907d7a07546fb316882dd5a45089f1ce2 Mon Sep 17 00:00:00 2001 From: Namsoo315 Date: Wed, 5 Nov 2025 16:55:06 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20application.yml=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Batch 작동되게 변경 --- monew/src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monew/src/main/resources/application.yml b/monew/src/main/resources/application.yml index 1ad9af97..d8c7052b 100644 --- a/monew/src/main/resources/application.yml +++ b/monew/src/main/resources/application.yml @@ -33,6 +33,7 @@ spring: redis: host: ${SPRING_DATA_REDIS_HOST:localhost} port: ${SPRING_DATA_REDIS_PORT:6379} + password: ${SPRING_DATA_REDIS_PASSWORD batch: job: @@ -40,7 +41,7 @@ spring: trigger: enabled: true jdbc: - initialize-schema: never + initialize-schema: always servlet: multipart: From 575923e7b606bb30055d31eda5628e3983618998 Mon Sep 17 00:00:00 2001 From: Namsoo315 Date: Tue, 11 Nov 2025 19:24:45 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=EB=B0=B0=ED=8F=AC=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 36 +++++++++++++++---- monew/docker-compose.yml | 5 +++ .../impl/InterestRepositoryCustomImpl.java | 2 +- monew/src/main/resources/application.yml | 4 +-- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fac33552..fe63c434 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,7 +47,7 @@ jobs: - name: 📄 Download current ECS Task Definition run: | aws ecs describe-task-definition \ - --task-definition $ECS_TASK_DEFINITION \ + --task-definition "$ECS_TASK_DEFINITION" \ --query taskDefinition \ --output json > task-definition.json @@ -76,12 +76,36 @@ jobs: --cluster $ECS_CLUSTER \ --service $ECS_SERVICE \ --task-definition $NEW_TASK_DEF_ARN + aws ecs wait services-stable \ + --cluster $ECS_CLUSTER \ + --services $ECS_SERVICE echo "✅ ECS Service update triggered successfully!" - - name: ✅ Confirm Deployment + - name: ✅ Confirm Deployment (with validation) run: | - echo "Checking ECS deployment status..." - aws ecs describe-services \ + echo "🔍 Checking ECS deployment status..." + + STATUS_JSON=$(aws ecs describe-services \ --cluster $ECS_CLUSTER \ - --services $ECS_SERVICE \ - --query "services[0].deployments" + --services $ECS_SERVICE) + + PRIMARY_DEPLOYMENT=$(echo "$STATUS_JSON" | jq -r '.services[0].deployments[] | select(.status=="PRIMARY")') + + DESIRED_COUNT=$(echo "$PRIMARY_DEPLOYMENT" | jq -r '.desiredCount') + RUNNING_COUNT=$(echo "$PRIMARY_DEPLOYMENT" | jq -r '.runningCount') + FAILED_COUNT=$(echo "$PRIMARY_DEPLOYMENT" | jq -r '.failedTasks') + + echo "Desired: $DESIRED_COUNT, Running: $RUNNING_COUNT, Failed: $FAILED_COUNT" + + if [ "$RUNNING_COUNT" -lt "$DESIRED_COUNT" ]; then + echo "❌ Deployment not yet stable — runningCount < desiredCount" + exit 1 + fi + + if [ "$FAILED_COUNT" != "0" ]; then + echo "🚨 Deployment has failed tasks!" + exit 1 + fi + + echo "✅ Deployment verified successfully!" + diff --git a/monew/docker-compose.yml b/monew/docker-compose.yml index 8e57ca98..e0683450 100644 --- a/monew/docker-compose.yml +++ b/monew/docker-compose.yml @@ -82,6 +82,11 @@ services: test: ["CMD-SHELL", "curl -f http://localhost:8080/actuator/health || exit 1"] interval: 10s retries: 5 + deploy: + resources: + limits: + cpus: "2.0" + memory: 4g ports: - "8080:8080" - "1327:1327" diff --git a/monew/src/main/java/com/spring/monew/interest/repository/impl/InterestRepositoryCustomImpl.java b/monew/src/main/java/com/spring/monew/interest/repository/impl/InterestRepositoryCustomImpl.java index 64f4e0ce..13aa7bd1 100644 --- a/monew/src/main/java/com/spring/monew/interest/repository/impl/InterestRepositoryCustomImpl.java +++ b/monew/src/main/java/com/spring/monew/interest/repository/impl/InterestRepositoryCustomImpl.java @@ -169,7 +169,7 @@ public List findSimilarNames(String name, double threshold) { private OrderSpecifier getOrderSpecifier(String orderBy, String direction) { Order order = "DESC".equalsIgnoreCase(direction) ? Order.DESC : Order.ASC; if ("subscriberCount".equals(orderBy)) { - new OrderSpecifier<>(order, InterestRepositoryCustomImpl.interest.subscriptionsCount); + return new OrderSpecifier<>(order, InterestRepositoryCustomImpl.interest.subscriptionsCount); } return new OrderSpecifier<>(order, InterestRepositoryCustomImpl.interest.name); } diff --git a/monew/src/main/resources/application.yml b/monew/src/main/resources/application.yml index d8c7052b..576034c9 100644 --- a/monew/src/main/resources/application.yml +++ b/monew/src/main/resources/application.yml @@ -33,7 +33,7 @@ spring: redis: host: ${SPRING_DATA_REDIS_HOST:localhost} port: ${SPRING_DATA_REDIS_PORT:6379} - password: ${SPRING_DATA_REDIS_PASSWORD + password: ${SPRING_DATA_REDIS_PASSWORD} batch: job: @@ -41,7 +41,7 @@ spring: trigger: enabled: true jdbc: - initialize-schema: always + initialize-schema: never servlet: multipart: