Skip to content

Commit

Permalink
refactor: 다운타임 줄이기 위해 트래픽을 점진적으로 전환
Browse files Browse the repository at this point in the history
  • Loading branch information
kanguk01 committed Nov 2, 2024
1 parent 515c0a4 commit 8f722b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
60 changes: 55 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public OpenAPI openAPI() {
private Info apiInfo() {
return new Info()
.title("Splanet")
.description("Splanet의 API 문서 (Version : Green)")
.description("Splanet의 API 문서")
.version("1.0.0");
}
}

0 comments on commit 8f722b3

Please sign in to comment.