ํผํฌ ํ์ Scale-Up V2 (new) #7
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-Up V2 (new) | |
on: | |
workflow_dispatch: | |
env: | |
TF_CLOUD_ORGANIZATION: sckwon770 | |
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} | |
TF_WORKSPACE: jnu-parking | |
PEAK_CONFIG_DIRECTORY: "./jnu-parking-prod-was/peak/" | |
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-up-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-peak | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
directory: ${{ env.PEAK_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: ๋ ๋์ค ๋จ๋ scale-up Plan ์์ฑ | |
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.3.0 | |
id: redis-scale-up-plan | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
configuration_version: ${{ steps.set-peak.outputs.configuration_version_id }} | |
target: "aws_elasticache_replication_group.jnu-parking-redis-prod" | |
- name: ๋ ๋์ค ๋จ๋ scale-up Plan ์คํ | |
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.3.0 | |
if: fromJSON(steps.redis-scale-up-plan.outputs.payload).data.attributes.actions.IsConfirmable | |
id: redis-scale-up-apply | |
with: | |
run: ${{ steps.redis-scale-up-plan.outputs.run_id }} | |
comment: "๋ ๋์ค ๋จ๋ scale-up Plan ์คํ from GitHub Actions CI ${{ github.sha }}" | |
- name: ์ธํ๋ผ ์กฐ์ ์์ ์ฌ๋ ์๋ฆผ ๋ณด๋ด๊ธฐ | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: author, workflowRun, pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '#FCCF51', | |
title: '๐ค ์ฃผ์ฐจ๊ถ ์์คํ Scale-up ์์!', | |
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-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.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) scale-up Plan ์์ฑ | |
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.3.0 | |
id: infra-scale-up-plan | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
configuration_version: ${{ steps.set-peak.outputs.configuration_version_id }} | |
target: "aws_instance.jnu-parking-ec2-prod,aws_db_instance.jnu-parking-rds-prod" | |
- name: ์ธํ๋ผ ์ ์ฒด (EC2, RDS) scale-up Plan ์คํ | |
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.3.0 | |
if: fromJSON(steps.infra-scale-up-plan.outputs.payload).data.attributes.actions.IsConfirmable | |
id: infra-scale-up-apply | |
with: | |
run: ${{ steps.infra-scale-up-plan.outputs.run_id }} | |
comment: "์ธํ๋ผ ์ ์ฒด (EC2, RDS) scale-up Plan ์คํ from GitHub Actions CI ${{ github.sha }}" | |
- 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-peak.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: '#2E289E', | |
title: '๐ฅ ์ฃผ์ฐจ๊ถ ์์คํ Scale-up ์ฑ๊ณต!', | |
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-up-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.peak 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-up-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-peak | |
with: | |
workspace: ${{ env.TF_WORKSPACE }} | |
directory: ${{ env.PEAK_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-peak.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 }} |