대기 타임 Scale-Down V2 (new) #5
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
name: 대기 타임 Scale-Down V2 (new) | |
on: | |
workflow_dispatch: | |
env: | |
TF_CLOUD_ORGANIZATION: sckwon770 | |
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} | |
TF_WORKSPACE: jnu-parking | |
IDLE_CONFIG_DIRECTORY: "./jnu-parking-prod-was/idle/" | |
MAINTENANCE_CONFIG_DIRECTORY: "./jnu-parking-prod-was/maintenance/" | |
IMAGE_NAME: jnuparking/jnu-parking-prod | |
jobs: | |
prepare-variables: | |
name: 워크플로우 변수 준비하기 | |
runs-on: ubuntu-latest | |
outputs: | |
image-name: ${{ steps.setup-env.outputs.image-name }} | |
steps: | |
- name: Github에서 레포 받아오기 | |
uses: actions/checkout@v3 | |
- name: 변수 출력하기 | |
id: setup-env | |
run: | | |
echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT | |
scale-down-infra: | |
needs: [ prepare-variables ] | |
name: 인프라 스케일 다운 | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: 아이들 모드 설정 | |
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.3.0 | |
id: set-idle | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
directory: ${{ env.IDLE_CONFIG_DIRECTORY }} | |
- name: 메인터넌스 모드 설정 | |
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.3.0 | |
id: set-maintenance | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
directory: ${{ env.MAINTENANCE_CONFIG_DIRECTORY }} | |
- name: 인프라 조정 시작 슬랙 알림 보내기 | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: author, workflowRun, pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '#FCCF51', | |
title: '🤖 주차권 시스템 Scale-down 시작!', | |
fields: [ | |
{ | |
title: '배포자', | |
value: `${process.env.AS_AUTHOR}`, | |
short: true, | |
}, | |
{ | |
title: '워크플로 링크', | |
value: `${process.env.AS_WORKFLOW_RUN}`, | |
short: true, | |
}, | |
] | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
- name: 공지 페이지 라우팅 변경 Plan 생성 | |
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.3.0 | |
id: maintenance-routing-plan | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
configuration_version: ${{ steps.set-maintenance.outputs.configuration_version_id }} | |
target: "aws_cloudfront_distribution.jnu-parking-manager-distribution,aws_cloudfront_distribution.jnu-parking-apply-distribution" | |
- name: 공지 페이지 라우팅 변경 Plan 실행 | |
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.3.0 | |
if: fromJSON(steps.maintenance-routing-plan.outputs.payload).data.attributes.actions.IsConfirmable | |
id: maintenance-routing-apply | |
with: | |
run: ${{ steps.maintenance-routing-plan.outputs.run_id }} | |
comment: "공지 페이지 라우팅 변경 Plan 실행 from GitHub Actions CI ${{ github.sha }}" | |
- name: 인프라 전체 (EC2, RDS, Elasticache) scale-down Plan 생성 | |
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.3.0 | |
id: infra-scale-down-plan | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
configuration_version: ${{ steps.set-idle.outputs.configuration_version_id }} | |
target: "aws_instance.jnu-parking-ec2-prod,aws_db_instance.jnu-parking-rds-prod,aws_elasticache_replication_group.jnu-parking-redis-prod" | |
- name: 인프라 전체 (EC2, RDS) scale-down Plan 실행 | |
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.3.0 | |
if: fromJSON(steps.infra-scale-down-plan.outputs.payload).data.attributes.actions.IsConfirmable | |
id: infra-scale-down-apply | |
with: | |
run: ${{ steps.infra-scale-down-plan.outputs.run_id }} | |
comment: "인프라 전체 (EC2, RDS) scale-down Plan 실행 from GitHub Actions CI ${{ github.sha }}" | |
- name: 스케일 다운 슬랙 알림 보내기 | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: author, workflowRun, pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '#2E289E', | |
title: '🧊 주차권 시스템 Scale-down 성공!', | |
fields: [ | |
{ | |
title: '배포자', | |
value: `${process.env.AS_AUTHOR}`, | |
short: true, | |
}, | |
{ | |
title: '워크플로 링크', | |
value: `${process.env.AS_WORKFLOW_RUN}`, | |
short: true, | |
}, | |
] | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
run-spring-boot: | |
needs: [ prepare-variables, scale-down-infra ] | |
runs-on: [ ubuntu-latest ] | |
name: 스프링 부트 기동 | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: GitHub 에서 레포 받아오기 | |
uses: actions/checkout@v3 | |
- name: 배포 스크립트 실행 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PROD_SSH_HOST }} | |
username: ${{ secrets.PROD_SSH_USERNAME }} | |
key: ${{ secrets.PROD_SSH_KEY }} | |
port: ${{ secrets.PROD_SSH_PORT }} | |
script: | | |
sudo docker rm -f $(sudo docker ps -qa) | |
sudo docker pull ${{ needs.prepare-variables.outputs.image-name }}:latest | |
sudo docker compose --env-file .env.idle up -d | |
sudo docker image prune -f | |
- name: 배포 완료 슬랙 알림 보내기 | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: author, workflowRun, pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '#24C183', | |
title: '(1/2) ✅ Spring boot 기동 성공!', | |
fields: [ | |
{ | |
title: '배포자', | |
value: `${process.env.AS_AUTHOR}`, | |
short: true, | |
}, | |
{ | |
title: '워크플로 링크', | |
value: `${process.env.AS_WORKFLOW_RUN}`, | |
short: true, | |
}, | |
] | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
start-service: | |
needs: [ prepare-variables, scale-down-infra, run-spring-boot ] | |
name: 라우팅 재개를 통한 서비스 재게 | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: 아이들 모드 설정 | |
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.3.0 | |
id: set-idle | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
directory: ${{ env.IDLE_CONFIG_DIRECTORY }} | |
- name: 공지 페이지 라우팅 원상복귀 Plan 생성 | |
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.3.0 | |
id: origin-routing-plan | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
configuration_version: ${{ steps.set-idle.outputs.configuration_version_id }} | |
target: "aws_cloudfront_distribution.jnu-parking-apply-distribution,aws_cloudfront_distribution.jnu-parking-manager-distribution" | |
- name: 공지 페이지 라우팅 원상복귀 Plan 실행 | |
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.3.0 | |
if: fromJSON(steps.origin-routing-plan.outputs.payload).data.attributes.actions.IsConfirmable | |
id: origin-routing-apply | |
with: | |
run: ${{ steps.origin-routing-plan.outputs.run_id }} | |
comment: "공지 페이지 라우팅 원상복귀 Plan 실행 from GitHub Actions CI ${{ github.sha }}" | |
- name: 서비스 재게 슬랙 알림 보내기 | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: author, workflowRun, pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '#24C183', | |
title: '(2/2) ✅ 서비스 재게 성공!', | |
fields: [ | |
{ | |
title: '배포자', | |
value: `${process.env.AS_AUTHOR}`, | |
short: true, | |
}, | |
{ | |
title: '워크플로 링크', | |
value: `${process.env.AS_WORKFLOW_RUN}`, | |
short: true, | |
}, | |
] | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |