Merge pull request #315 from kmin-jeong/feat/answer #690
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
# 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 |