Skip to content

Commit bcf10a3

Browse files
authored
[FEAT] 무중단 배포 GitAction 스크립트 업데이트 (#830)
1 parent 6adb2a6 commit bcf10a3

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

.github/workflows/main-deploy.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,27 @@ jobs:
5656
docker tag ${{ env.IMAGE_NAME }}:${{ env.VERSION_TAG }} ${{ env.IMAGE_NAME }}:latest
5757
docker push ${{ env.IMAGE_NAME }}:latest
5858
59-
- name: Get Github Actions IP
60-
id: ip
61-
uses: haythem/[email protected]
59+
- name: Create the configuration file
60+
run: |
61+
cat << EOF > config.json
62+
{
63+
"AutoScalingGroupName": "gg-main",
64+
"DesiredConfiguration": {
65+
"LaunchTemplate": {
66+
"LaunchTemplateId": "${{ secrets.LAUNCH_TEMPLATE_ID }}",
67+
"Version": "\$Latest"
68+
}
69+
},
70+
"Preferences": {
71+
"MinHealthyPercentage": 100,
72+
"MaxHealthyPercentage": 110,
73+
"InstanceWarmup": 300,
74+
"ScaleInProtectedInstances": "Ignore",
75+
"StandbyInstances": "Ignore"
76+
}
77+
}
78+
EOF
79+
cat config.json
6280
6381
- name: AWS Credentials
6482
uses: aws-actions/configure-aws-credentials@v2
@@ -67,23 +85,6 @@ jobs:
6785
aws-secret-access-key: ${{ secrets.AWS_SECURITY_SECRET_KEY }}
6886
aws-region: ap-northeast-2
6987

70-
- name: Add Github Actions IP to Security group
71-
run: |
72-
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_MAIN_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
73-
74-
- name: executing docker-compose up on main server
75-
uses: appleboy/ssh-action@master
76-
with:
77-
host: ${{ secrets.MAIN_SERVER_HOST }}
78-
username: ${{ secrets.MAIN_SERVER_USERNAME }}
79-
key: ${{ secrets.MAIN_SERVER_PEM }}
80-
script: |
81-
cd ./docker
82-
docker-compose down tomcat
83-
docker rmi ${{ env.IMAGE_NAME }}:latest
84-
docker-compose up tomcat -d
85-
docker-compose up prometheus -d
86-
87-
- name: Remove Github Actions IP From Security Group
88+
- name: Trigger Instance Refresh
8889
run: |
89-
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_MAIN_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
90+
aws autoscaling start-instance-refresh --cli-input-json file://config.json

.github/workflows/test-deploy.yml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,35 @@ jobs:
5858
docker build -t ${{ env.IMAGE_NAME }}:latest .
5959
docker push ${{ env.IMAGE_NAME }}:latest
6060
61-
- name: Get Github Actions IP
62-
id: ip
63-
uses: haythem/[email protected]
64-
65-
- name: AWS Credentials
61+
- name: Create the configuration file
62+
run: |
63+
cat << EOF > config.json
64+
{
65+
"AutoScalingGroupName": "gg-dev",
66+
"DesiredConfiguration": {
67+
"LaunchTemplate": {
68+
"LaunchTemplateId": "${{ secrets.DEV_LAUNCH_TEMPLATE_ID }}",
69+
"Version": "\$Latest"
70+
}
71+
},
72+
"Preferences": {
73+
"MinHealthyPercentage": 100,
74+
"MaxHealthyPercentage": 110,
75+
"InstanceWarmup": 300,
76+
"ScaleInProtectedInstances": "Ignore",
77+
"StandbyInstances": "Ignore"
78+
}
79+
}
80+
EOF
81+
cat config.json
82+
83+
- name: Configure AWS CLI
6684
uses: aws-actions/configure-aws-credentials@v2
6785
with:
6886
aws-access-key-id: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_ACCESS_KEY_ID }}
6987
aws-secret-access-key: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_SECRET_KEY }}
7088
aws-region: ap-northeast-2
7189

72-
- name: Add Github Actions IP to Security group
73-
run: |
74-
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
75-
76-
- name: executing docker-compose up on test server
77-
uses: appleboy/ssh-action@master
78-
with:
79-
host: ${{ secrets.TEST_MIGRATE_SERVER_HOST }}
80-
username: ${{ secrets.TEST_MIGRATE_SERVER_USERNAME }}
81-
key: ${{ secrets.TEST_MIGRATE_SERVER_PEM }}
82-
script: |
83-
cd /home/ec2-user/docker
84-
docker-compose down tomcat
85-
docker rmi ${{ env.IMAGE_NAME }}:latest
86-
docker-compose up tomcat -d
87-
docker-compose up prometheus -d
88-
89-
- name: Remove Github Actions IP From Security Group
90+
- name: Trigger Instance Refresh
9091
run: |
91-
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
92+
aws autoscaling start-instance-refresh --cli-input-json file://config.json

0 commit comments

Comments
 (0)