Skip to content

Feat: Chat-23-chatting (#6) #9

Feat: Chat-23-chatting (#6)

Feat: Chat-23-chatting (#6) #9

Workflow file for this run

name: Front Deployment
# trigger๊ฐ€ ๋˜๊ธธ ๋ฐ”๋ผ๋Š” action์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. push / pull_request๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
# ์ €๋Š” develop ๋ธŒ๋žœ์น˜์— push๊ฐ€ ๋˜๋ฉด actions์„ ์‹คํ–‰ํ•˜๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
on:
push:
branches:
- develop
# ์œ„์˜ ์ด๋ฒคํŠธ๊ฐ€ ํŠธ๋ฆฌ๊ฑฐ๋˜๋ฉด ์‹คํ–‰ํ•  ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
jobs:
build:
name: react build & deploy
# runner๊ฐ€ ์‹คํ–‰๋  ํ™˜๊ฒฝ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
runs-on: ubuntu-latest
# name์€ ๋‹จ๊ณ„๋ณ„๋กœ ์‹คํ–‰๋˜๋Š” ์•ก์…˜๋“ค์˜ ์„ค๋ช…์„ ๋‹ด์€ ๊ฒƒ์œผ๋กœ, ๋‚˜์ค‘์— github action์—์„œ workflow์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
# uses ํ‚ค์›Œ๋“œ๋กœ Action์„ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
steps:
# ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ ‘๊ทผํ•˜์—ฌ CI์„œ๋ฒ„๋กœ ์ฝ”๋“œ๋ฅผ ๋‚ด๋ ค๋ฐ›๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค.
- name: checkout Github Action
uses: actions/checkout@v3
# workflow๊ฐ€ ์‹คํ–‰๋  ๋•Œ ํ•„์š”ํ•œ ํŒŒ์ผ ์ค‘์—์„œ ๊ฑฐ์˜ ๋ฐ”๋€Œ์ง€ ์•Š๋Š” ํŒŒ์ผ๋“ค์„ GitHub์˜ ์บ์‹œ์— ์˜ฌ๋ ค๋†“๊ณ  CI ์„œ๋ฒ„๋กœ ๋‚ด๋ ค๋ฐ›์Šต๋‹ˆ๋‹ค.
# ํ”„๋กœ์ ํŠธ์—์„œ ์ž์ฃผ ๋ฐ”๋€Œ์ง€ ์•Š๋Š” ์ˆ˜๋งŽ์€ ํŒจํ‚ค์ง€๋ฅผ ๋งค๋ฒˆ ๋‹ค์šด๋ฐ›์•„ ์˜ฌ๋ฆฌ๋ฉด ์‹œ๊ฐ„๋„ ์˜ค๋ž˜๊ฑธ๋ฆฌ๊ณ  ๋„คํŠธ์›Œํฌ ๋Œ€์—ญํญ์„ ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค.
- name: Get npm cache directory
id: npm-cache-dir
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: install npm dependencies
run: npm install
- name: react build
run: npm run build
# aws์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•œ ๊ถŒํ•œ์„ ๋ฐ›์•„์˜ต๋‹ˆ๋‹ค.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY_ID }}
aws-region: ap-northeast-2
# S3์— build ํŒŒ์ผ์„ ์˜ฌ๋ฆฝ๋‹ˆ๋‹ค.
- name: Upload to S3
env:
BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
run: |
aws s3 sync \
./build s3://$BUCKET_NAME
# cloudfront๋กœ ๋ฐฐํฌ๋˜๋Š” ํŒŒ์ผ์€ ๊ธฐ๋ณธ์„ค์ • ์ƒ 24์‹œ๊ฐ„๋™์•ˆ ์บ์‹œ๊ฐ€ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.
# ๋ฐฐํฌ ํ›„ S3์—๋Š” ์ตœ์‹  ์ •์ ๋ฆฌ์†Œ์Šค๊ฐ€ ์˜ฌ๋ผ๊ฐ€์žˆ์ง€๋งŒ ์—ฃ์ง€๋กœ์ผ€์ด์…˜์—” ์ด์ „ ํŒŒ์ผ์ด ์˜ฌ๋ผ๊ฐ€์žˆ๋Š” ์ƒํƒœ๋ผ๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.
# ๋ฐ”๋กœ ๋ณ€ํ™”๊ฐ€ ๋ฐ˜์˜๋˜๊ธธ ๋ฐ”๋ž€๋‹ค๋ฉด invalidation์„ ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
# ํ•ด๋‹น ๋ถ€๋ถ„์€ ๊ณผ๊ธˆ๋  ์ˆ˜ ์žˆ์œผ๋‹ˆ ํ™•์ธ ํ›„ ์‚ฌ์šฉํ•˜์„ธ์š”
- name: CloudFront Invalidation
env:
CLOUD_FRONT_ID: ${{ secrets.AWS_CLOUDFRONT_ID }}
run: aws cloudfront create-invalidation --distribution-id $CLOUD_FRONT_ID --paths "/*"