Skip to content

Merge pull request #272 from JayJayleee/bugfix/#271-realtime-alert-reโ€ฆ #601

Merge pull request #272 from JayJayleee/bugfix/#271-realtime-alert-reโ€ฆ

Merge pull request #272 from JayJayleee/bugfix/#271-realtime-alert-reโ€ฆ #601

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: React CI/CD with Docker
# event trigger
on:
# ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ push ๋  ๋•Œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
push:
branches:
- main
- develop
# ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ PR ๋  ๋•Œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
pull_request:
branches:
permissions:
contents: read
jobs:
build:
if: github.repository == 'COFLLL/CoverFlow-FE'
runs-on: ubuntu-latest
steps:
## Repo checkout
- name: Checkout source code.
uses: actions/checkout@v3
## Node version ํ™•์ธ
- name: Check Node v
run: node -v
## ์˜์กด ํŒŒ์ผ ์„ค์น˜
- name: Install dependencies
run: yarn
## React Build
- name: Generate build
run: CI='false' yarn build
######### CD(Continuous Delivery) ##########
## docker hub์— ๋กœ๊ทธ์ธํ•˜๊ณ  cofl-front-dev ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œ & push ํ•ฉ๋‹ˆ๋‹ค.
- name: Docker build & push to dev repo
if: contains(github.ref, 'develop')
run: |
docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" -p "${{ secrets.DOCKER_PASSWORD_DEV }}"
docker build -f Dockerfile-front-dev -t "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev .
docker push "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev
## docker hub์— ๋กœ๊ทธ์ธํ•˜๊ณ  cofl-front-prod์— ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œ & push ํ•ฉ๋‹ˆ๋‹ค.
- name: Docker build & push to prod repo
if: contains(github.ref, 'main')
run: |
docker login -u "${{ secrets.DOCKER_USERNAME_PROD }}" -p "${{ secrets.DOCKER_PASSWORD_PROD }}"
docker build -f Dockerfile-front-prod -t "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod .
docker push "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod
## AWS EC2์— ์ ‘์†ํ•˜๊ณ  develop์„ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.
- name: Deploy to Dev
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.HOST_DEV }} # EC2 ์ธ์Šคํ„ด์Šค ํผ๋ธ”๋ฆญ DNS
username: ${{ secrets.USERNAME }} # ์ธ์Šคํ„ด์Šค๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” AMI์— ์ •์˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
key: ${{ secrets.PRIVATE_KEY }} # ํ‚ค ํŽ˜์–ด์˜ pem ํ‚ค
# sudo docker-compose up -d
script: |
sudo docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" -p "${{ secrets.DOCKER_PASSWORD_DEV }}"
sudo docker stop cofl_react_dev
sudo docker rm -f $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker pull "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev
sudo docker run --name cofl_react_dev -d --log-driver=syslog -p 3001:3001 "${{ secrets.DOCKER_USERNAME_DEV }}"/cofl-front-dev
sudo docker image prune -a -f
## AWS EC2์— ์ ‘์†ํ•˜๊ณ  production์„ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.
- name: Deploy to Prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST_PROD }} # EC2 ์ธ์Šคํ„ด์Šค ํผ๋ธ”๋ฆญ DNS
username: ${{ secrets.USERNAME }} # ์ธ์Šคํ„ด์Šค๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” AMI์— ์ •์˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
key: ${{ secrets.PRIVATE_KEY }} # ํ‚ค ํŽ˜์–ด์˜ pem ํ‚ค
# sudo docker-compose up -d
script: |
sudo docker login -u "${{ secrets.DOCKER_USERNAME_PROD }}" -p "${{ secrets.DOCKER_PASSWORD_PROD }}"
sudo docker stop cofl_react_prod
sudo docker rm -f $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker pull "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod
sudo docker run --name cofl_react_prod -d --log-driver=syslog -p 3001:3001 "${{ secrets.DOCKER_USERNAME_PROD }}"/cofl-front-prod
sudo docker image prune -a -f