针对 Firebase 多站点托管中的特定站点进行 React js 并使用 github 操作?

发布于 2025-01-10 07:39:07 字数 1591 浏览 0 评论 0原文

所以我有一个 React js,我使用 firebase 来托管该网站。我创建了一个名为“parentproject”的项目,其中包含多个站点“site1”“site2”。 我正在使用 GitHub actions 来检测我的两个分支“prod 和 dev”中的一个的推送。因此,当我推送到 prod 分支时,我想部署在“site1”上,当我推送到 dev 分支时,我想部署在“site2”上。 我也在使用 github 工作流程。我的 firebase 配置是:

.firebaserc

{
  "projects": {
    "default": "site1"
  },
  "targets": {
    "parentProject": {
      "hosting": {
        "prod": ["site1"],
        "dev": ["site2"],
      }
    }
  }
}

firebase.json

{
  "hosting": {
    "target": "prod",
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我的推送分支的 yml 文件如下所示:

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - prod
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '14'
      - run: npm ci
      - run: CI=false npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SECRETKEY }}'
          channelId: live
          projectId: parentProject
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels

每次我推送到 prod 时,我的网站都会部署在默认的 firebase 托管页面上,而不是“site1”。任何建议都有帮助。

So I have a react js and I am using firebase to host the site. And I have created a project named "parentproject" having multiple sites "site1" "site2".
And I am using GitHub actions to detect push on either of my 2 branches "prod and dev". So, when I push into prod branch I want to deploy on "site1" and when I push to dev branch I want to deply on "site2".
I am also using github workflow. My firebase configs are :

.firebaserc

{
  "projects": {
    "default": "site1"
  },
  "targets": {
    "parentProject": {
      "hosting": {
        "prod": ["site1"],
        "dev": ["site2"],
      }
    }
  }
}

firebase.json

{
  "hosting": {
    "target": "prod",
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

My yml file for push branch looks like:

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - prod
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '14'
      - run: npm ci
      - run: CI=false npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SECRETKEY }}'
          channelId: live
          projectId: parentProject
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels

Every time I push to prod, my site gets deployed on default firebase hosting page, not "site1". Any suggestion are helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的味道 2025-01-17 07:39:07

有一个名为“target”的字段,您可以在其中设置要部署的特定站点,有关详细信息,请参阅 firebase github 操作的文档:https://github.com/FirebaseExtended/action-hosting-deploy#target-string

(...)
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SECRETKEY }}'
          channelId: live
          projectId: parentProject
==>       target: "<site id here>"
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels

您还必须在 firebase.json 上添加字段“site” , 喜欢:

{
  "hosting": {
    "target": "prod",
==> "site": "<id of the site in the firebase projet>",
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

There is a field called "target" where you can setup the specific site to deploy, more about it on the documentation of the firebase github action: https://github.com/FirebaseExtended/action-hosting-deploy#target-string

(...)
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SECRETKEY }}'
          channelId: live
          projectId: parentProject
==>       target: "<site id here>"
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels

You have to add also the field "site" on the firebase.json, like:

{
  "hosting": {
    "target": "prod",
==> "site": "<id of the site in the firebase projet>",
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文