[CI/CD] 모노레포에서 Firebase hosting - github action 연동하기

한음·2022년 9월 6일
1
post-thumbnail

github-action 이용해 firebase hosting 에 특정 폴더만 자동배포 하고싶어 난감할 때

해결법

1) .github/workflows 를 레포 루트경로에 위치시키고 workflow 파일을 작성 (yml)

firebase-hosting-pull-request.yml

name: DEPLOY
on:
  push:
    branches:
      - master
jobs:
  deploy:
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2

      - name: Install Dependencies
        run: npm ci
        working-directory: ${모노레포 경로}

      - name: Build
        run: npm run build
        working-directory: ${모노레포 경로}
        
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_VUE2_CC0A4 }}"
          projectId: vue2-cc0a4
          channelId: live

firebase-tools cli 를 이용해 호스팅 설정을 마쳤을 경우를 가정하고 진행
** workflows 폴더가 루트 경로에 있어야합니다.

핵심은 의존성 패키지 설치 (Install Dependencies) & 빌드 (Build) 에
working-directory: ./${모노레포명} 을 주어 해당 디렉토리내의 명령어를 실행하도록 하는 것

패키지 설치와 빌드를 마치면 firebase deploy 가 실행된다.

2) firebase.json 파일도 루트로 끄집어내주기

firebase.json

{
  "hosting": {
    "public": "${모노레포 경로}/${빌드파일 경로}",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

** 마찬가지로 중요한건 타겟을 기존 dist(혹은 빌드 파일 경로) 에 모노레포 경로를 붙여주는것


그리고 커밋을 날리면

어째저째 자동배포가 된다.


+) module not found 가 나온다면 firebase 가 전역으로 설치되어 있지 않은지 확인해본다.
기본경로 설정문제라 모듈 못가져오는 줄 알고 한참 삽질했다 ㄱ-

전역으로 설치되어있다면 package-lock 날리고 npm 캐시도 비우고 다시 설치한 뒤 배포 시도해보시길

profile
https://github.com/0hhanum

0개의 댓글