From 318fbe6fa980a396da2c83e20e92448311aa3194 Mon Sep 17 00:00:00 2001 From: ez <105545215+ezcolin2@users.noreply.github.com> Date: Sat, 16 Nov 2024 19:42:25 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20CI=20turbo=EB=A1=9C=20=ED=94=84?= =?UTF-8?q?=EB=A1=A0=ED=8A=B8,=20=EB=B0=B1=EC=97=94=EB=93=9C=20=EB=8F=99?= =?UTF-8?q?=EC=8B=9C=20=EC=88=98=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-pipeline.yml | 242 +++++++++++++++--------------- .github/workflows/main.yml | 79 +++++----- package.json | 3 +- turbo.json | 4 +- 4 files changed, 168 insertions(+), 160 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index d6b4a64f..feaa8226 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -9,7 +9,7 @@ on: - develop jobs: - setup-backend: + setup: runs-on: ubuntu-latest outputs: cache-key: ${{ steps.cache-backend-deps.outputs.cache-hit }} @@ -22,50 +22,49 @@ jobs: with: node-version: "23" - # 백엔드 의존성 캐시 설정 + # turbo 의존성 캐시 설정 - name: Cache Yarn dependencies for backend - id: cache-backend-deps + id: cache-deps uses: actions/cache@v3 with: - path: apps/backend/node_modules - key: ${{ runner.os }}-backend-yarn-${{ hashFiles('apps/backend/yarn.lock') }} + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} - # 백엔드 의존성 설치 + # turbo 의존성 설치 - name: Install backend dependencies - if: steps.cache-backend-deps.outputs.cache-hit != 'true' - working-directory: ./apps/backend - run: yarn install - - setup-frontend: - runs-on: ubuntu-latest - outputs: - cache-key: ${{ steps.cache-frontend-deps.outputs.cache-hit }} - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "23" - - # 프론트엔드 의존성 캐시 설정 - - name: Cache Yarn dependencies for frontend - id: cache-frontend-deps - uses: actions/cache@v3 - with: - path: apps/frontend/node_modules - key: ${{ runner.os }}-frontend-yarn-${{ hashFiles('apps/frontend/yarn.lock') }} - - # 프론트엔드 의존성 설치 - - name: Install frontend dependencies - if: steps.cache-frontend-deps.outputs.cache-hit != 'true' - working-directory: ./apps/frontend + if: steps.cache-deps.outputs.cache-hit != 'true' run: yarn install - backend-lint: + # setup: + # runs-on: ubuntu-latest + # outputs: + # cache-key: ${{ steps.cache-deps.outputs.cache-hit }} + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 + + # - name: Set up Node.js + # uses: actions/setup-node@v3 + # with: + # node-version: "23" + + # # 프론트엔드 의존성 캐시 설정 + # - name: Cache Yarn dependencies for frontend + # id: cache-deps + # uses: actions/cache@v3 + # with: + # path: node_modules + # key: ${{ runner.os }}-frontend-yarn-${{ hashFiles('yarn.lock') }} + + # # 프론트엔드 의존성 설치 + # - name: Install frontend dependencies + # if: steps.cache-frontend-deps.outputs.cache-hit != 'true' + # working-directory: ./apps/frontend + # run: yarn install + + lint: runs-on: ubuntu-latest - needs: setup-backend + needs: setup steps: - name: Checkout repository uses: actions/checkout@v3 @@ -75,57 +74,56 @@ jobs: with: node-version: "23" - # 백엔드 의존성 캐시 복원 + # 의존성 캐시 복원 - name: Restore Yarn dependencies for backend uses: actions/cache@v3 with: - path: apps/backend/node_modules - key: ${{ runner.os }}-backend-yarn-${{ hashFiles('apps/backend/yarn.lock') }} + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} # 백엔드 린트 실행 - - name: Run backend lint - working-directory: ./apps/backend + - name: Run lint run: yarn lint continue-on-error: true # 백엔드 린트 경고 포스트 - name: Post backend lint warning if any if: failure() - run: echo "⚠️ 백엔드 lint 실행 도중 경고가 발생했습니다. 확인해주세요." - - frontend-lint: + run: echo "⚠️ lint 실행 도중 경고가 발생했습니다. 확인해주세요." + + # frontend-lint: + # runs-on: ubuntu-latest + # needs: setup-frontend + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 + + # - name: Set up Node.js + # uses: actions/setup-node@v3 + # with: + # node-version: "23" + + # # 프론트엔드 의존성 캐시 복원 + # - name: Restore Yarn dependencies for frontend + # uses: actions/cache@v3 + # with: + # path: apps/frontend/node_modules + # key: ${{ runner.os }}-frontend-yarn-${{ hashFiles('apps/frontend/yarn.lock') }} + + # # 프론트엔드 린트 실행 + # - name: Run frontend lint + # working-directory: ./apps/frontend + # run: yarn lint + # continue-on-error: true + + # # 프론트엔드 린트 경고 포스트 + # - name: Post frontend lint warning if any + # if: failure() + # run: echo "⚠️ 프론트엔드 lint 실행 도중 경고가 발생했습니다. 확인해주세요." + + build: runs-on: ubuntu-latest - needs: setup-frontend - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "23" - - # 프론트엔드 의존성 캐시 복원 - - name: Restore Yarn dependencies for frontend - uses: actions/cache@v3 - with: - path: apps/frontend/node_modules - key: ${{ runner.os }}-frontend-yarn-${{ hashFiles('apps/frontend/yarn.lock') }} - - # 프론트엔드 린트 실행 - - name: Run frontend lint - working-directory: ./apps/frontend - run: yarn lint - continue-on-error: true - - # 프론트엔드 린트 경고 포스트 - - name: Post frontend lint warning if any - if: failure() - run: echo "⚠️ 프론트엔드 lint 실행 도중 경고가 발생했습니다. 확인해주세요." - - backend-build: - runs-on: ubuntu-latest - needs: setup-backend + needs: setup steps: - name: Checkout repository uses: actions/checkout@v3 @@ -136,56 +134,55 @@ jobs: node-version: "23" # 루트 의존성 캐시 설정 - name: Cache Yarn dependencies for root - id: cache-root-deps + id: cache-deps uses: actions/cache@v3 with: path: node_modules - key: ${{ runner.os }}-root-yarn-${{ hashFiles('yarn.lock') }} + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} # 루트 의존성 설치 - - name: Install root dependencies - if: steps.cache-root-deps.outputs.cache-hit != 'true' - run: yarn install - - # 백엔드 의존성 캐시 복원 - - name: Restore Yarn dependencies for backend - uses: actions/cache@v3 - with: - path: apps/backend/node_modules - key: ${{ runner.os }}-backend-yarn-${{ hashFiles('apps/backend/yarn.lock') }} + # - name: Install root dependencies + # if: steps.cache-root-deps.outputs.cache-hit != 'true' + # run: yarn install - # 백엔드 빌드 실행 - - name: Run backend build - working-directory: ./apps/backend - run: yarn build + # # 백엔드 의존성 캐시 복원 + # - name: Restore Yarn dependencies for backend + # uses: actions/cache@v3 + # with: + # path: apps/backend/node_modules + # key: ${{ runner.os }}-backend-yarn-${{ hashFiles('apps/backend/yarn.lock') }} - frontend-build: - runs-on: ubuntu-latest - needs: setup-frontend - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "23" - - # 프론트엔드 의존성 캐시 복원 - - name: Restore Yarn dependencies for frontend - uses: actions/cache@v3 - with: - path: apps/frontend/node_modules - key: ${{ runner.os }}-frontend-yarn-${{ hashFiles('apps/frontend/yarn.lock') }} - - # 프론트엔드 빌드 실행 - - name: Run frontend build - working-directory: ./apps/frontend + # 백엔드 빌드 실행 + - name: Run build run: yarn build - backend-test: + # frontend-build: + # runs-on: ubuntu-latest + # needs: setup-frontend + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 + + # - name: Set up Node.js + # uses: actions/setup-node@v3 + # with: + # node-version: "23" + + # # 프론트엔드 의존성 캐시 복원 + # - name: Restore Yarn dependencies for frontend + # uses: actions/cache@v3 + # with: + # path: apps/frontend/node_modules + # key: ${{ runner.os }}-frontend-yarn-${{ hashFiles('apps/frontend/yarn.lock') }} + + # # 프론트엔드 빌드 실행 + # - name: Run frontend build + # working-directory: ./apps/frontend + # run: yarn build + + test: runs-on: ubuntu-latest - needs: [setup-backend, backend-build] + needs: [setup, build] steps: - name: Checkout repository uses: actions/checkout@v3 @@ -195,14 +192,13 @@ jobs: with: node-version: "23" - # 백엔드 의존성 캐시 복원 - - name: Restore Yarn dependencies for backend + # 의존성 캐시 복원 + - name: Restore Yarn dependencies uses: actions/cache@v3 with: - path: apps/backend/node_modules - key: ${{ runner.os }}-backend-yarn-${{ hashFiles('apps/backend/yarn.lock') }} + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} - # 백엔드 테스트 실행 - - name: Run backend tests - working-directory: ./apps/backend + # 테스트 실행 + - name: Run tests run: yarn test diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 80c8fa1c..0830bd95 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,12 +1,11 @@ name: Create Directory on Remote Server - on: push: branches: - - develop + - be-feature-#173 jobs: - frontend-CD: + env: runs-on: ubuntu-latest steps: @@ -17,42 +16,41 @@ jobs: # .env 파일 생성 후 붙여넣기 - name: Create .env file run: | - echo "${{secrets.DEVELOPMENT_FE_ENV}}" > ./frontend/.env + echo "${{secrets.DEVELOPMENT_ENV}}" > ./.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 - backend-CD: - runs-on: ubuntu-latest + # - 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 + # CD: + # runs-on: ubuntu-latest - steps: + # 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: @@ -85,6 +83,9 @@ jobs: yarn -v yarn install + # build + yarn build + # Check and kill existing process EXISTING_PID=$(lsof -ti :3000) @@ -104,7 +105,15 @@ 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: @@ -112,7 +121,7 @@ jobs: 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 diff --git a/package.json b/package.json index ea359726..de35c216 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dev": "turbo run dev", "build": "turbo run build", "start": "node apps/backend/dist/main.js", - "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix" + "lint": "turbo run lint", + "test": "turbo run test" }, "dependencies": { "turbo": "^2.3.0" diff --git a/turbo.json b/turbo.json index db08335c..95f5dde5 100644 --- a/turbo.json +++ b/turbo.json @@ -11,6 +11,8 @@ "outputs": [ "dist/**" ] - } + }, + "lint": {}, + "test": {} } } \ No newline at end of file