我正在通过 this GitHub Action 部署 Firebase 云功能.当我使用服务帐户从我自己的机器部署时,它工作正常。使用相同的服务帐户运行操作时,我遇到了以下错误。
最终错误:
ERROR: error fetching storage source: generic::unknown: retry budget exhausted (3 attempts): fetching gcs source: unpacking source from gcs: source fetch container exited with non-zero status: 9
之前的日志:
End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of /tmp/source-archive.zip or /tmp/source-archive.zip.zip, and cannot find /tmp/source-archive.zip.ZIP, period.
这是我的操作 yml:
name: Deploy
on:
pull_request:
branches:
- master
jobs:
integration-test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: checkout repo and set up Node.js v12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies
run: cd ./functions/ && npm install
- id: deploy
name: Deploy my_function to Cloud Functions
uses: google-github-actions/deploy-cloud-functions@v0.1.2
with:
name: my_function
runtime: nodejs12
credentials: ${{ secrets.GCP_ACCOUNT_JSON }}
source_dir: ./functions/
- id: echo_url
name: Echo deployed Cloud Function URL
run: echo ${{ steps.deploy.outputs.url }}
该函数本身不需要 GCS 访问权限,但服务帐户是一个编辑器,因此无论如何它都有。我想这个问题更多地与将 GitHub 源代码上传到 GCS 然后从那里获取以进行部署的方式有关?任何提示?
最佳答案
如果有人使用 Cloud Build 进行部署并遇到此问题,这里有一个潜在的原因和解决方案。
原因
我正在按照 official Cloud Build documentation for Firebase 中的步骤操作但一直收到这个错误。对于说使用 Node 12 的类似问题,有多个答案,但这实际上并没有帮助,因为我使用的是提供的图像。
我终于想到它实际上是构建步骤图像 由 Google 提供的 Node 版本不兼容。我查看了用于构建镜像的 Docker 文件,它没有指定 Node.js 的哪个版本。当我在 Cloud Build 上检查图像中使用的 Node 版本时,它是 Node 15。我怀疑这就是导致问题的原因。
解决方案
为了创建一个可以在 Cloud Build 上使用 Node 12 部署 Firebase 函数的镜像,我按照 documentation 中的步骤克隆了社区构建器镜像。 :
git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git
cd cloud-builders-community/firebase
但是在我将构建提交到我的项目之前,我在 Dockerfile
中进行了更改。专门使用 Node 12 的 repo:FROM node:12
按照其余步骤提交图像。一旦我这样做了,我就能够在 Cloud Build 上部署 Firebase 函数!作为引用,这是我的
cloudbuild.yaml
看起来像:timeout: 1600s
steps:
# I am using Typescript, so I had to install dependencies
# and build my function source before I deployed
- name: gcr.io/$PROJECT_ID/firebase
entrypoint: yarn
args: ["install-functions"]
- name: gcr.io/$PROJECT_ID/firebase
entrypoint: yarn
args: ["build:functions"]
# Deploy using the build image's default entry point
- name: gcr.io/$PROJECT_ID/firebase
args: ["deploy", "--project=$PROJECT_ID", "--only=functions"]
关于firebase - 错误:获取存储源时出错:generic::unknown... 当通过 GitHub Actions 部署 GCP Cloud Function 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65009405/