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
51 changes: 49 additions & 2 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ jobs:
--auto-scaling-group-name "$ACTIVE_ASG" \
--min-size 0 --desired-capacity 0 --max-size 0

echo "💥 Forcing termination of existing instances in $ACTIVE_ASG"

INSTANCE_IDS=$(aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$ACTIVE_ASG" \
--query "AutoScalingGroups[0].Instances[*].InstanceId" \
--output text)

for INSTANCE_ID in $INSTANCE_IDS; do
echo "🔥 Terminating instance: $INSTANCE_ID"
aws autoscaling terminate-instance-in-auto-scaling-group \
--instance-id "$INSTANCE_ID" \
--should-decrement-desired-capacity
done

echo "⏳ Waiting for $ACTIVE_ASG to fully scale down..."
while true; do
INSTANCE_COUNT=$(aws autoscaling describe-auto-scaling-groups \
Expand All @@ -200,7 +214,8 @@ jobs:

echo "ACTIVE_ASG_COLOR=$ACTIVE_ASG_COLOR" >> $GITHUB_ENV
echo "DELETE_ASG_COLOR=$DELETE_ASG_COLOR" >> $GITHUB_ENV

echo "DELETE_ASG=$DELETE_ASG" >> $GITHUB_ENV

- name: Wait for ALB Health Check → Switch Listener → Shutdown old ASG
run: |
DEPLOY_TG_NAME="weplate-tg-${ACTIVE_ASG_COLOR}"
Expand Down Expand Up @@ -272,7 +287,39 @@ jobs:
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name "$DELETE_ASG" \
--min-size 0 --desired-capacity 0 --max-size 0
echo "✅ $DELETE_ASG is now disabled"

# Step 2: Terminate instances (if any)
INSTANCE_IDS=$(aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$DELETE_ASG" \
--query "AutoScalingGroups[0].Instances[*].InstanceId" \
--output text)

if [ -z "$INSTANCE_IDS" ]; then
echo "✅ $DELETE_ASG has no running instances."
else
for INSTANCE_ID in $INSTANCE_IDS; do
echo "🔥 Terminating instance in $DELETE_ASG: $INSTANCE_ID"
aws autoscaling terminate-instance-in-auto-scaling-group \
--instance-id "$INSTANCE_ID" \
--should-decrement-desired-capacity
done

echo "⏳ Waiting for $DELETE_ASG to fully scale down..."
while true; do
INSTANCE_COUNT=$(aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$DELETE_ASG" \
--query "AutoScalingGroups[0].Instances | length(@)" --output text)

echo "🔄 $DELETE_ASG instance count: $INSTANCE_COUNT"

if [ "$INSTANCE_COUNT" -eq 0 ]; then
echo "✅ All instances in $DELETE_ASG have been terminated."
break
fi

sleep 10
done
fi
else
echo "ℹ️ No previous ASG to shut down"
fi