From 5161246b9348540346b8e881928a773789d88c1b Mon Sep 17 00:00:00 2001 From: sonwonjae Date: Mon, 21 Apr 2025 00:58:43 +0900 Subject: [PATCH] fix: edit color execute logic --- .github/workflows/Release.yml | 75 +++++++++++++---------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 5f2667e..b25b5d5 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -118,75 +118,54 @@ jobs: - name: Determine ASG and Apply Desired Scaling run: | + BLUE_NAME="blue" + GREEN_NAME="green" + BLUE_ASG="weplate-$BLUE_NAME-asg" + GREEN_ASG="weplate-$GREEN_NAME-asg" + BLUE_COUNT=$(aws autoscaling describe-auto-scaling-groups \ - --auto-scaling-group-names weplate-blue-asg \ + --auto-scaling-group-names "$BLUE_ASG" \ --query "AutoScalingGroups[0].Instances | length(@)" --output text) GREEN_COUNT=$(aws autoscaling describe-auto-scaling-groups \ - --auto-scaling-group-names weplate-green-asg \ + --auto-scaling-group-names "$GREEN_ASG" \ --query "AutoScalingGroups[0].Instances | length(@)" --output text) echo "Blue count: $BLUE_COUNT" echo "Green count: $GREEN_COUNT" if [ "$BLUE_COUNT" -eq 0 ] && [ "$GREEN_COUNT" -eq 0 ]; then - echo "🟦 No ASG running. Blue will be launched." - TARGET_ASG="weplate-blue-asg" - DELETE_ASG="" - - aws autoscaling update-auto-scaling-group \ - --auto-scaling-group-name "$TARGET_ASG" \ - --min-size 1 --max-size 1 --desired-capacity 1 - aws autoscaling start-instance-refresh \ - --auto-scaling-group-name "$TARGET_ASG" \ - --strategy Rolling - + ASG_COLOR="$BLUE_NAME" elif [ "$BLUE_COUNT" -gt 0 ] && [ "$GREEN_COUNT" -eq 0 ]; then - echo "🟩 Blue is running. Deploying to Green." - TARGET_ASG="weplate-green-asg" - DELETE_ASG="weplate-blue-asg" - - aws autoscaling update-auto-scaling-group \ - --auto-scaling-group-name "$TARGET_ASG" \ - --min-size 1 --max-size 1 --desired-capacity 1 - aws autoscaling start-instance-refresh \ - --auto-scaling-group-name "$TARGET_ASG" \ - --strategy Rolling - + ASG_COLOR="$GREEN_NAME" elif [ "$GREEN_COUNT" -gt 0 ] && [ "$BLUE_COUNT" -eq 0 ]; then - echo "🟦 Green is running. Deploying to Blue." - TARGET_ASG="weplate-blue-asg" - DELETE_ASG="weplate-green-asg" - - aws autoscaling update-auto-scaling-group \ - --auto-scaling-group-name "$TARGET_ASG" \ - --min-size 1 --max-size 1 --desired-capacity 1 - aws autoscaling start-instance-refresh \ - --auto-scaling-group-name "$TARGET_ASG" \ - --strategy Rolling - + ASG_COLOR="$BLUE_NAME" else - echo "⚠️ Blue and Green are both alive. Forcing deploy to Blue & shutting down Green." - TARGET_ASG="weplate-blue-asg" - DELETE_ASG="weplate-green-asg" + ASG_COLOR="$BLUE_NAME" + DELETE_COLOR="$GREEN_NAME" + fi - aws autoscaling update-auto-scaling-group \ - --auto-scaling-group-name "$TARGET_ASG" \ - --min-size 1 --max-size 1 --desired-capacity 1 - aws autoscaling start-instance-refresh \ - --auto-scaling-group-name "$TARGET_ASG" \ - --strategy Rolling + TARGET_ASG="weplate-$ASG_COLOR-asg" + DELETE_ASG="${DELETE_COLOR:+weplate-$DELETE_COLOR-asg}" + # Apply scaling + aws autoscaling update-auto-scaling-group \ + --auto-scaling-group-name "$TARGET_ASG" \ + --min-size 1 --max-size 1 --desired-capacity 1 + aws autoscaling start-instance-refresh \ + --auto-scaling-group-name "$TARGET_ASG" \ + --strategy Rolling + + # If both alive, shutdown DELETE + if [ "$DELETE_ASG" != "" ]; then aws autoscaling update-auto-scaling-group \ --auto-scaling-group-name "$DELETE_ASG" \ --min-size 0 --max-size 0 --desired-capacity 0 fi - echo "TARGET_ASG=$TARGET_ASG" >> $GITHUB_ENV - echo "DELETE_ASG=$DELETE_ASG" >> $GITHUB_ENV - + echo "ASG_COLOR=$ASG_COLOR" >> $GITHUB_ENV + - name: Wait for ALB Health Check → Switch Listener → Shutdown old ASG run: | - ASG_COLOR="${TARGET_ASG##*-}" TG_NAME="weplate-tg-${ASG_COLOR}" echo "✅ [$ASG_COLOR] start" TG_ARN=$(aws elbv2 describe-target-groups \