Skip to content
Merged
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
75 changes: 27 additions & 48 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down