我想使用CloudBuild部署firebase函数。
但是,发生以下错误,无法部署。
.
.
.
Step #2: [2019-11-28T05:30:33.984Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Thu, 28 Nov 2019 05:30:33 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, accept-ranges=none, transfer-encoding=chunked
Step #2: [2019-11-28T05:30:35.986Z] >>> HTTP REQUEST GET https://cloudfunctions.googleapis.com/v1/operations/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Step #2:
Step #2: [2019-11-28T05:30:36.433Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Thu, 28 Nov 2019 05:30:36 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, accept-ranges=none, transfer-encoding=chunked
Step #2: [2019-11-28T05:30:38.436Z] >>> HTTP REQUEST GET https://cloudfunctions.googleapis.com/v1/operations/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Step #2:
Step #2: ⚠ functions[func-example(asia-northeast1)]: Deployment error.
Step #2: Error setting up the execution environment for your function. Please try deploying again after a few minutes.
Step #2:
Step #2:
Step #2: Functions deploy had errors with the following functions:
Step #2: func-example
Step #2:
Step #2:
Step #2: To try redeploying those functions, run:
Step #2: firebase deploy --only functions:func-example
Step #2:
Step #2:
Step #2: To continue deploying other features (such as database), run:
Step #2: firebase deploy --except functions
Step #2: [2019-11-28T05:30:38.912Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Thu, 28 Nov 2019 05:30:38 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, accept-ranges=none, transfer-encoding=chunked
Step #2:
Step #2: Error: Functions did not deploy properly.
Finished Step #2
ERROR
ERROR: build step 2 "gcr.io/project-id-xxxxxxxxxxxxxxx/firebase" failed: exit status 1
如何解决此错误? 我尝试每隔几个小时部署2天,但没有成功。
情况如下。
steps:
# because node10 is used
- name: 'node:10.16.3'
entrypoint: 'yarn'
dir: 'functions'
args: ['install']
# because a grpc error occurs
- name: 'gcr.io/${_FIREBASE_PROJECT_ID}/firebase'
entrypoint: 'npm'
dir: 'functions'
args: ['rebuild']
# container already created
- name: 'gcr.io/${_FIREBASE_PROJECT_ID}/firebase'
args:
['deploy', '--only', 'functions:trigger', '--debug', '--project', '${_FIREBASE_PROJECT_ID}']
env:
- 'FIREBASE_PROJECT_ID=${_FIREBASE_PROJECT_ID}'
{
"name": "functions",
"engines": {
"node": "10"
},
"scripts": {
"build": "tsc",
"deploy": "firebase use xxx && firebase deploy --only functions",
"deploy:func-example": "firebase use xxx && firebase deploy --only functions:func-example"
},
"main": "lib/index.js",
"dependencies": {
.
.
.
},
"private": true,
"version": "0.0.0"
}
手动部署成功。
$ yarn deploy
yarn run v1.15.2
$ firebase use xxx && firebase deploy --only functions
Now using alias xxx (xxxxxxxxxxxxxxxx)
=== Deploying to 'xxxxxxxxxxxxxxxx'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build
npm WARN lifecycle The node binary used for scripts is /var/folders/7l/wbcfr4yn5wq8zyntjxg1_hc0ygjdjv/T/yarn--1574914184465-0.44163642642000567/node but npm is using /Users/sekiguchi_t/.anyenv/envs/nodenv/versions/10.16.3/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> functions@0.0.0 build /xxxxxxxxxxxxxxxxxxxxx
> tsc
✔ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (226.54 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 10 (Beta) function func-example(asia-northeast1)...
✔ scheduler: all necessary APIs are enabled
✔ functions[func-example(asia-northeast1)]: Successful update operation.
✔ Deploy complete!
答案 0 :(得分:1)
可能有两个原因,其中之一是您需要将包含服务帐户变量的.env
文件与之一起发送,因为Firebase在部署过程中会上传整个功能文件夹并执行某种操作结束时的执行测试。
一种实现方法是将.env
文件转换为base64字符串
cat .env | base64
并将其保存到云中作为环境变量,例如。 SERVICE_ACCOUNT。
在部署命令之前,将base64字符串转换回功能文件夹中的.env
文件。
echo $SERVICE_ACCOUNT | base64 -d > .env