Skip to content

Commit

Permalink
[FEAT] 무중단 배포 GitAction 스크립트 업데이트 (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
wken5577 authored Apr 22, 2024
1 parent 6adb2a6 commit bcf10a3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 46 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/main-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,27 @@ jobs:
docker tag ${{ env.IMAGE_NAME }}:${{ env.VERSION_TAG }} ${{ env.IMAGE_NAME }}:latest
docker push ${{ env.IMAGE_NAME }}:latest
- name: Get Github Actions IP
id: ip
uses: haythem/[email protected]
- name: Create the configuration file
run: |
cat << EOF > config.json
{
"AutoScalingGroupName": "gg-main",
"DesiredConfiguration": {
"LaunchTemplate": {
"LaunchTemplateId": "${{ secrets.LAUNCH_TEMPLATE_ID }}",
"Version": "\$Latest"
}
},
"Preferences": {
"MinHealthyPercentage": 100,
"MaxHealthyPercentage": 110,
"InstanceWarmup": 300,
"ScaleInProtectedInstances": "Ignore",
"StandbyInstances": "Ignore"
}
}
EOF
cat config.json
- name: AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand All @@ -67,23 +85,6 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECURITY_SECRET_KEY }}
aws-region: ap-northeast-2

- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_MAIN_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: executing docker-compose up on main server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.MAIN_SERVER_HOST }}
username: ${{ secrets.MAIN_SERVER_USERNAME }}
key: ${{ secrets.MAIN_SERVER_PEM }}
script: |
cd ./docker
docker-compose down tomcat
docker rmi ${{ env.IMAGE_NAME }}:latest
docker-compose up tomcat -d
docker-compose up prometheus -d
- name: Remove Github Actions IP From Security Group
- name: Trigger Instance Refresh
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_MAIN_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
aws autoscaling start-instance-refresh --cli-input-json file://config.json
49 changes: 25 additions & 24 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,35 @@ jobs:
docker build -t ${{ env.IMAGE_NAME }}:latest .
docker push ${{ env.IMAGE_NAME }}:latest
- name: Get Github Actions IP
id: ip
uses: haythem/[email protected]

- name: AWS Credentials
- name: Create the configuration file
run: |
cat << EOF > config.json
{
"AutoScalingGroupName": "gg-dev",
"DesiredConfiguration": {
"LaunchTemplate": {
"LaunchTemplateId": "${{ secrets.DEV_LAUNCH_TEMPLATE_ID }}",
"Version": "\$Latest"
}
},
"Preferences": {
"MinHealthyPercentage": 100,
"MaxHealthyPercentage": 110,
"InstanceWarmup": 300,
"ScaleInProtectedInstances": "Ignore",
"StandbyInstances": "Ignore"
}
}
EOF
cat config.json
- name: Configure AWS CLI
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_SECRET_KEY }}
aws-region: ap-northeast-2

- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: executing docker-compose up on test server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_MIGRATE_SERVER_HOST }}
username: ${{ secrets.TEST_MIGRATE_SERVER_USERNAME }}
key: ${{ secrets.TEST_MIGRATE_SERVER_PEM }}
script: |
cd /home/ec2-user/docker
docker-compose down tomcat
docker rmi ${{ env.IMAGE_NAME }}:latest
docker-compose up tomcat -d
docker-compose up prometheus -d
- name: Remove Github Actions IP From Security Group
- name: Trigger Instance Refresh
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
aws autoscaling start-instance-refresh --cli-input-json file://config.json

0 comments on commit bcf10a3

Please sign in to comment.