WAS 인프라 - 대기 타임 Scale-Down #16
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: WAS 인프라 - 대기 타임 Scale-Down | |
on: | |
workflow_dispatch: | |
env: | |
TF_CLOUD_ORGANIZATION: sckwon770 | |
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} | |
TF_WORKSPACE: jnu-parking | |
CONFIG_DIRECTORY: "./jnu-parking-prod-was/idle/" | |
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 | |
modify-infra-with-terraform: | |
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: Upload Configuration | |
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.0.0 | |
id: apply-upload | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
directory: ${{ env.CONFIG_DIRECTORY }} | |
- name: Create Plan Run | |
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.0.0 | |
id: apply-run | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }} | |
- name: Apply | |
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.0.0 | |
if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.IsConfirmable | |
id: apply | |
with: | |
run: ${{ steps.apply-run.outputs.run_id }} | |
comment: "Apply Run 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: '🧊 인프라 조정 알림', | |
text: `주차권 시스템 Scale-down 성공! (EC2, RDS, ElastiCache)`, | |
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, modify-infra-with-terraform ] | |
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: '✅ Spring boot 기동 알림', | |
text: '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 }} |