-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,15 +160,65 @@ jobs: | |
username: ubuntu | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
CURRENT_VERSION=${{ env.CURRENT_VERSION }} | ||
CURRENT_VERSION=${CURRENT_VERSION} | ||
if [ "$CURRENT_VERSION" == "blue" ]; then | ||
TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet-8081/${{ secrets.ARN_ID_8081 }}" | ||
OLD_TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet-blue/${{ secrets.ARN_ID_BLUE }}" | ||
NEW_TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet-green/${{ secrets.ARN_ID_GREEN }}" | ||
else | ||
TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet/${{ secrets.ARN_ID_8080 }}" | ||
OLD_TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet-green/${{ secrets.ARN_ID_GREEN }}" | ||
NEW_TARGET_GROUP_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:targetgroup/splanet-blue/${{ secrets.ARN_ID_BLUE }}" | ||
fi | ||
aws elbv2 modify-listener --listener-arn arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:listener/app/splanet/${{ secrets.ARN_ID_443 }} \ | ||
--default-actions Type=forward,TargetGroupArn=$TARGET_GROUP_ARN | ||
LISTENER_ARN="arn:aws:elasticloadbalancing:ap-northeast-2:${{ secrets.AWS_ACCOUNT_ID }}:listener/app/splanet/${{ secrets.ARN_ID_443 }}" | ||
# Step 1: Add new target group with weight 0 | ||
aws elbv2 modify-listener --listener-arn $LISTENER_ARN \ | ||
--default-actions Type=forward,ForwardConfig='{ | ||
"TargetGroups": [ | ||
{ | ||
"TargetGroupArn": "'"$OLD_TARGET_GROUP_ARN"'", | ||
"Weight": 100 | ||
}, | ||
{ | ||
"TargetGroupArn": "'"$NEW_TARGET_GROUP_ARN"'", | ||
"Weight": 0 | ||
} | ||
] | ||
}' | ||
echo "Added new target group with weight 0" | ||
# Step 2: Gradually shift traffic | ||
for weight in {10..100..10}; do | ||
aws elbv2 modify-listener --listener-arn $LISTENER_ARN \ | ||
--default-actions Type=forward,ForwardConfig='{ | ||
"TargetGroups": [ | ||
{ | ||
"TargetGroupArn": "'"$OLD_TARGET_GROUP_ARN"'", | ||
"Weight": '"$((100 - weight))"' | ||
}, | ||
{ | ||
"TargetGroupArn": "'"$NEW_TARGET_GROUP_ARN"'", | ||
"Weight": '"$weight"' | ||
} | ||
] | ||
}' | ||
echo "Shifted traffic to new target group with weight $weight%" | ||
sleep 10 | ||
done | ||
# Step 3: Remove old target group by setting its weight to 0 | ||
aws elbv2 modify-listener --listener-arn $LISTENER_ARN \ | ||
--default-actions Type=forward,ForwardConfig='{ | ||
"TargetGroups": [ | ||
{ | ||
"TargetGroupArn": "'"$NEW_TARGET_GROUP_ARN"'", | ||
"Weight": 100 | ||
} | ||
] | ||
}' | ||
echo "Switched all traffic to the new target group" | ||
|
||
- name: Remove Old Version | ||
uses: appleboy/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters