Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js gcloud auth在dockerfile中不工作_Node.js_Google Cloud Platform_Google Cloud Functions_Dockerfile - Fatal编程技术网

Node.js gcloud auth在dockerfile中不工作

Node.js gcloud auth在dockerfile中不工作,node.js,google-cloud-platform,google-cloud-functions,dockerfile,Node.js,Google Cloud Platform,Google Cloud Functions,Dockerfile,我制作了一个多级dockerfile,安装我的npm包,然后尝试将它们部署到gcp 问题是,当我运行部署时,它告诉我它无法打开配置文件,并且我没有选择活动帐户 WARNING: Could not open the configuration file: [/root/.config/gcloud/configurations/config_default]. ERROR: (gcloud.functions.deploy) You do not currently have an active

我制作了一个多级dockerfile,安装我的npm包,然后尝试将它们部署到gcp

问题是,当我运行部署时,它告诉我它无法打开配置文件,并且我没有选择活动帐户

WARNING: Could not open the configuration file: [/root/.config/gcloud/configurations/config_default].
ERROR: (gcloud.functions.deploy) You do not currently have an active account selected.
Please run:

  $ gcloud auth login

to obtain new credentials, or if you have already logged in with a
different account:

  $ gcloud config set account ACCOUNT

to select an already authenticated account to use.
这是我的dockerfile:

FROM node:10.19.0-alpine3.9 AS build

ADD . /app
WORKDIR /app

RUN npm install

FROM google/cloud-sdk

WORKDIR /app
COPY --from=build /app /app

RUN gcloud auth activate-service-account --key-file /app/firebase-service-account.json
RUN gcloud config set project MY_PROJECT
RUN gcloud config set account service-account-email@service-account.iam.gserviceaccount.com
我还编写了一个bash脚本来构建和部署我的云功能

#! /bin/sh

docker build . -f deploy-functions.dockerfile -t cloud-functions-deploy

docker run cloud-functions-deploy gcloud functions deploy event-log-trigger \
--project ${GCP_PROJECT_ID} \
--entry-point eventLogBuilder \
--trigger-event providers/cloud.firestore/eventTypes/document.update \
--trigger-resource projects/${GCP_PROJECT_ID}/databases/\(default\)/documents/events/\{eventId\} \
--region=${GCP_REGION} --stage-bucket=${STAGE_BUCKET} --runtime nodejs10

在我的第一个bash脚本中,我没有
--project
标志,但需要添加它,因为它说命令没有项目。尽管我以root用户身份运行所有操作,但警告似乎是正确的,并且它无法打开
配置默认文件。

您可以通过创建
entrypoint.sh
文件来克服此问题

#entrypoint.sh
#设置环境变量GCP\U项目ID、阶段桶、GCP\U区域。。。
gcloud auth activate服务帐户--密钥文件/app/firebase-service-account.json
gcloud配置集项目$GCP\u项目\u ID
#您的部署命令
gcloud函数部署事件日志触发器\
--入口点eventLogBuilder\
--触发事件提供程序/cloud.firestore/eventTypes/document.update\
--触发器资源项目/${GCP\u PROJECT\u ID}/databases/\(默认值\)/documents/events/\{eventId\}\
--region=${GCP_region}--stage bucket=${stage_bucket}--runtime nodejs10
并在Dockerfile中设置此信息

# previous stage ... 
FROM google/cloud-sdk

WORKDIR /app
COPY --from=build /app /app

RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/bin/sh","/app/entrypoint.sh"]
在图像形成后,这些命令似乎不会持久存在

我通过运行命令检查了这一点

docker run cloud-functions-deploy gcloud config list

用于身份验证,而不是执行此操作

RUN gcloud auth activate-service-account --key-file /app/firebase-service-account.json
只需定义一个env变量

ENV GOOGLE_APPLICATION_CREDENTIALS=/app/firebase-service-account.json
对于项目和帐户,可以将其添加到gcloud调用的参数中(使用
--project
--account
标志)

ENV GOOGLE_APPLICATION_CREDENTIALS=/app/firebase-service-account.json