Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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
aws ecs wait services-stable \
--cluster $ECS_CLUSTER \
--services $ECS_SERVICE
echo "✅ ECS Service update triggered successfully!"

- name: ✅ Confirm Deployment (with validation)
run: |
echo "🔍 Checking ECS deployment status..."

STATUS_JSON=$(aws ecs describe-services \
--cluster $ECS_CLUSTER \
--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!"

2 changes: 1 addition & 1 deletion monew/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions monew/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public List<String> 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);
}
Expand Down
1 change: 1 addition & 0 deletions monew/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down