Skip to content

ํ”ผํฌ ํƒ€์ž„ Scale-Up V2 (new) #7

ํ”ผํฌ ํƒ€์ž„ Scale-Up V2 (new)

ํ”ผํฌ ํƒ€์ž„ Scale-Up V2 (new) #7

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 }}