使用 --allow-unauthenticated 从 Cloud Build 部署 Cloud Functions
Deploying a Cloud Function from Cloud Build with --allow-unauthenticated
我的目标是使用 Cloud Build 部署 Cloud Function。我的 cloudbuild.yaml
看起来如下:
steps:
- name: gcr.io/cloud-builders/gcloud
args:
[
'functions', 'deploy', 'func3',
'--region=us-central1',
'--allow-unauthenticated',
'--entry-point=helloWorld',
'--runtime=nodejs8',
'--source=https://source.developers.google.com/projects/XXX/repos/myfunc',
'--trigger-http',
'--service-account=XXX@appspot.gserviceaccount.com'
]
当我提交构建时,会记录以下内容:
Created [https://cloudbuild.googleapis.com/v1/projects/XXX/builds/5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa].
Logs are available at [https://console.cloud.google.com/gcr/builds/5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa?project=YYY].
------------------------------------------------------------------------------------ REMOTE BUILD OUTPUT ------------------------------------------------------------------------------------
starting build "5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa"
FETCHSOURCE
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.functions.deploy) unrecognized arguments: --allow-unauthenticated
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: exit status 2
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ERROR: (gcloud.builds.submit) build 5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa completed with status "FAILURE"
如我们所见,我们失败了。如果我删除引用 --allow-unauthenticated
的行,所有操作都会正确进行。为了完整起见,这里是工作 cloudbuild.yaml
.
steps:
- name: gcr.io/cloud-builders/gcloud
args:
[
'functions', 'deploy', 'func3',
'--region=us-central1',
'--entry-point=helloWorld',
'--runtime=nodejs8',
'--source=https://source.developers.google.com/projects/XXX/repos/myfunc',
'--trigger-http',
'--service-account=XXX@appspot.gserviceaccount.com'
]
我已经检查了关于 gcloud functions deploy
的 gcloud 文档,发现 here 并且看不到任何拼写错误或其他微不足道的错误。我一直假设 运行ning gcloud
作为 Cloud Builder 步骤与手动 运行ning 相同。
如果我手动 运行 命令(包括 --allow-unauthenticated
)它可以正常工作。例如,如果我 运行:
#!/bin/bash
gcloud functions deploy func3 \
--region=us-central1 \
--allow-unauthenticated \
--entry-point=helloWorld \
--runtime=nodejs8 \
--source=https://source.developers.google.com/projects/XXX/repos/myfunc \
--trigger-http \
--service-account=XXX@appspot.gserviceaccount.com
...没有问题。
问题的核心是 Cloud Build 上下文中的 --allow-unauthenticated
选项可能有什么问题?
错误信息可能有点误导:
ERROR: (gcloud.functions.deploy) unrecognized arguments: --allow-unauthenticated
当 运行 gcloud help functions deploy
时它将 --allow-unauthenticated
列为有效标志:
--allow-unauthenticated
If set, makes this a public function. This will allow all callers,
without checking authentication.
正如 Travis 评论的那样...我认为这可能是错误的行为 "unlikely",因为在更新复杂的分布式系统时偶尔出现的故障并不特别。
这似乎是由错误的 gcloud
构建映像引起的暂时性问题。
暂时使用这个版本:
gcr.io/cloud-builders/gcloud@sha256:4ea77d19d7336d5a8dc4ae0e609d7f5b45fca067c34b70d7ed6740af229392c6
我的目标是使用 Cloud Build 部署 Cloud Function。我的 cloudbuild.yaml
看起来如下:
steps:
- name: gcr.io/cloud-builders/gcloud
args:
[
'functions', 'deploy', 'func3',
'--region=us-central1',
'--allow-unauthenticated',
'--entry-point=helloWorld',
'--runtime=nodejs8',
'--source=https://source.developers.google.com/projects/XXX/repos/myfunc',
'--trigger-http',
'--service-account=XXX@appspot.gserviceaccount.com'
]
当我提交构建时,会记录以下内容:
Created [https://cloudbuild.googleapis.com/v1/projects/XXX/builds/5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa].
Logs are available at [https://console.cloud.google.com/gcr/builds/5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa?project=YYY].
------------------------------------------------------------------------------------ REMOTE BUILD OUTPUT ------------------------------------------------------------------------------------
starting build "5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa"
FETCHSOURCE
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.functions.deploy) unrecognized arguments: --allow-unauthenticated
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: exit status 2
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ERROR: (gcloud.builds.submit) build 5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa completed with status "FAILURE"
如我们所见,我们失败了。如果我删除引用 --allow-unauthenticated
的行,所有操作都会正确进行。为了完整起见,这里是工作 cloudbuild.yaml
.
steps:
- name: gcr.io/cloud-builders/gcloud
args:
[
'functions', 'deploy', 'func3',
'--region=us-central1',
'--entry-point=helloWorld',
'--runtime=nodejs8',
'--source=https://source.developers.google.com/projects/XXX/repos/myfunc',
'--trigger-http',
'--service-account=XXX@appspot.gserviceaccount.com'
]
我已经检查了关于 gcloud functions deploy
的 gcloud 文档,发现 here 并且看不到任何拼写错误或其他微不足道的错误。我一直假设 运行ning gcloud
作为 Cloud Builder 步骤与手动 运行ning 相同。
如果我手动 运行 命令(包括 --allow-unauthenticated
)它可以正常工作。例如,如果我 运行:
#!/bin/bash
gcloud functions deploy func3 \
--region=us-central1 \
--allow-unauthenticated \
--entry-point=helloWorld \
--runtime=nodejs8 \
--source=https://source.developers.google.com/projects/XXX/repos/myfunc \
--trigger-http \
--service-account=XXX@appspot.gserviceaccount.com
...没有问题。
问题的核心是 Cloud Build 上下文中的 --allow-unauthenticated
选项可能有什么问题?
错误信息可能有点误导:
ERROR: (gcloud.functions.deploy) unrecognized arguments: --allow-unauthenticated
当 运行 gcloud help functions deploy
时它将 --allow-unauthenticated
列为有效标志:
--allow-unauthenticated
If set, makes this a public function. This will allow all callers,
without checking authentication.
正如 Travis 评论的那样...我认为这可能是错误的行为 "unlikely",因为在更新复杂的分布式系统时偶尔出现的故障并不特别。
这似乎是由错误的 gcloud
构建映像引起的暂时性问题。
暂时使用这个版本:
gcr.io/cloud-builders/gcloud@sha256:4ea77d19d7336d5a8dc4ae0e609d7f5b45fca067c34b70d7ed6740af229392c6