Skip to content

Commit

Permalink
refactor: CI turbo로 프론트, 백엔드 동시 수행
Browse files Browse the repository at this point in the history
  • Loading branch information
ezcolin2 committed Nov 16, 2024
1 parent 3196147 commit 815e2bd
Showing 1 changed file with 57 additions and 40 deletions.
97 changes: 57 additions & 40 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
# CI가 끝난 뒤 CD 실행
name: Create Directory on Remote Server

on:
workflow_run:
workflows:
- "OctoDocs CI Pipeline"
types:
- completed
on:
push:
branches:
- develop
- be-feature-#173

jobs:
frontend-CD:
runs-on: ubuntu-latest
# frontend-CD:
# runs-on: ubuntu-latest

steps:
# 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# steps:
# # 코드 체크아웃
# - name: Checkout code
# uses: actions/checkout@v3

# .env 파일 생성 후 붙여넣기
- name: Create .env file
run: |
echo "${{secrets.DEVELOPMENT_FE_ENV}}" > ./frontend/.env
# # .env 파일 생성 후 붙여넣기
# - name: Create .env file
# run: |
# echo "${{secrets.DEVELOPMENT_ENV}}" > ./apps/frontend/.env
# echo "${{secrets.DEVELOPMENT_ENV}}" > ./apps/backend/.env

# Node.js 설치
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "23"
# 패키지 설치 및 React 빌드
- name: Install dependencies and build
run: |
cd frontend
npm install
npm run build
# # Node.js 설치
# - name: Set up Node.js
# uses: actions/setup-node@v3
# with:
# node-version: "23"
# 패키지 설치 및 빌드
# - name: Install dependencies and build
# run: |
# yarn install
# yarn build

# aws cli를 통해 ncloud object storage 업로드
- name: Configure AWS credentials
env:
NCLOUD_ACCESS_KEY_ID: ${{ secrets.NCLOUD_ACCESS_KEY_ID }}
NCLOUD_SECRET_ACCESS_KEY: ${{ secrets.NCLOUD_SECRET_ACCESS_KEY }}
run: |
aws configure set aws_access_key_id $NCLOUD_ACCESS_KEY_ID
aws configure set aws_secret_access_key $NCLOUD_SECRET_ACCESS_KEY
aws configure set region ap-northeast-2
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp ./frontend/dist s3://octodocs/ --recursive --debug
# - name: Configure AWS credentials
# env:
# NCLOUD_ACCESS_KEY_ID: ${{ secrets.NCLOUD_ACCESS_KEY_ID }}
# NCLOUD_SECRET_ACCESS_KEY: ${{ secrets.NCLOUD_SECRET_ACCESS_KEY }}
# run: |
# aws configure set aws_access_key_id $NCLOUD_ACCESS_KEY_ID
# aws configure set aws_secret_access_key $NCLOUD_SECRET_ACCESS_KEY
# aws configure set region ap-northeast-2
# aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp ./frontend/dist s3://octodocs/ --recursive --debug
backend-CD:
runs-on: ubuntu-latest

steps:
# 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# - name: Checkout code
# uses: actions/checkout@v3

# .env 파일 생성 후 붙여넣기
- name: Create .env file
run: |
echo "${{secrets.DEVELOPMENT_ENV}}" > ./.env
# # .env 파일 생성 후 붙여넣기
# - name: Create .env file
# run: |
# echo "${{secrets.DEVELOPMENT_ENV}}" > ./.env
# sh 실행
- name: Connect to Remote Server and Run Commands
env:
Expand Down Expand Up @@ -85,6 +91,9 @@ jobs:
yarn -v
yarn install
# build
yarn build
# Check and kill existing process
EXISTING_PID=$(lsof -ti :3000)
Expand All @@ -104,15 +113,23 @@ jobs:
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
source: ./.env
target: /home/root/app/octodocs
target: /home/root/app/octodocs/apps/backend
- name: Copy .env to remote server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_DEV_IP }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_PRIVATE_KEY }}
source: ./.env
target: /home/root/app/octodocs/apps/frontend
# yarn start
- name: yarn start
env:
REMOTE_HOST: ${{ secrets.REMOTE_DEV_IP }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
run: |
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST "cd /home/root/app/octodocs; nohup yarn start > nohup.out 2> nohup.err < /dev/null &"
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST "nohup node /home/root/app/octodocs/apps/backend/dist/main.js > nohup.out 2> nohup.err < /dev/null &"
# # 배포용 쉘 스크립트 파일 전송
# - name: Copy deploy.sh to remote server
Expand Down

0 comments on commit 815e2bd

Please sign in to comment.