如何在Circleci中构建Firebase项目,包括Firestore和存储规则

时间:2018-06-26 05:26:45

标签: firebase google-cloud-firestore firebase-storage circleci

我有一个在firebase中托管的react项目。我正在使用circleci进行构建。这一直很好。但是,我想在构建中包括Firebase Firestore规则以及索引配置和Firebase存储规则。

我将它们添加到我的firebase.json文件中,如下所示:

 "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "storage": {
    "rules": "storage.rules"
  }

如果我从命令行进行Firebase部署,则我配置的规则和索引可以正常工作。

当我尝试在circleci中进行构建时,我的问题就来了。我进入部署阶段,然后出现此错误:

i  deploying firestore, hosting

Error: Error reading rules file firestore.rules
Exited with code 1

这是config.yml的相关部分:

deploy_uat:
    docker:
      - image: google/cloud-sdk
    steps:
      - run: echo $(printenv)

      - type: shell
        name: "Provisioning infrastructure"
        command: |
          curl -sL https://deb.nodesource.com/setup_8.x | bash -
          apt-get -qq install -y build-essential nodejs
          echo "node version -> $(node --version)"
          echo "npm version -> $(npm --version)"

          # Firebase tools include native code and need npm 5.x to install into a special dir since it won't have permission to access '/usr/lib/node_modules/'
          mkdir ~/.npm-global
          npm config set prefix '~/.npm-global'
          export PATH=~/.npm-global/bin:$PATH

          npm install -g firebase-tools

      - type: shell
        name: "Downloading & configuring archive prior to deployment"
        command: |
          echo ${GCP_SERVICE_ACCOUNT_AMCE_API_ADMIN_CIRCLECI} | base64 --decode > key.json
          gcloud auth activate-service-account --key-file key.json
          gcloud config set compute/zone us-central1
          gcloud config set project AMCE-45

          mkdir tmp
          cd tmp
          gsutil cp gs://AMCE-45-AMCE-admin-archive-web/${CIRCLE_PROJECT_REPONAME}-${CIRCLE_SHA1}.tgz .
          tar xfz ${CIRCLE_PROJECT_REPONAME}-${CIRCLE_SHA1}.tgz
          ls -al

      - type: shell
        name: "Deploying"
        command: |
          export PATH=~/.npm-global/bin:$PATH

          ls -al build
          echo "Using env -> $(cat build/env.js)"

          firebase list --token "${FIREBASE_AUTH_TOKEN_AMCE_WEB_CUSTOMER_UAT}"
          firebase deploy -P uat --token "${FIREBASE_AUTH_TOKEN_AMCE_WEB_CUSTOMER_UAT}"

是否需要添加一些其他依赖项?我一直在尝试添加各种Firebase依赖项,但只会产生错误。

1 个答案:

答案 0 :(得分:0)

经过一夜的睡眠,解决方案很明显...

我没有在config.yml文件中添加firestore.rules,storage.rules和firestore.indexes.json。一旦添加它们,它就可以正常运行。

      ls -al
      tar -zcvf ${CIRCLE_PROJECT_REPONAME}-${CIRCLE_SHA1}.tgz .firebaserc firebase.json firestore.rules storage.rules firestore.indexes.json build