在使用Python框架函数时,如何在Google Cloud BuildPack中设置运行时版本?

2024-04-24 21:59:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用函数框架来使用pack构建我的函数

$ls -lah .
total 40
drwxr-xr-x  9 viroos  staff   288B Oct 18 02:54 .
drwxr-xr-x  9 viroos  staff   288B Oct 11 03:20 ..
-rw-r--r--  1 viroos  staff    44B Oct 17 19:37 .gitignore
-rw-r--r--  1 viroos  staff     6B Oct 18 02:24 .python-version
drwxr-xr-x  3 viroos  staff    96B Oct 17 22:44 __pycache__
-rw-r--r--  1 viroos  staff    32B Oct 18 02:54 main.py
-rw-r--r--  1 viroos  staff   259B Oct 18 02:54 project.toml
-rw-r--r--  1 viroos  staff    75B Oct 18 02:20 requirements.txt
drwxr-xr-x  6 viroos  staff   192B Oct 17 19:35 venv
$ cat project.toml 
[[build.env]]
name =  "GOOGLE_RUNTIME_VERSION"
value = "python38"
[[build.env]]
name = "GOOGLE_FUNCTION_TARGET"
value = "foo"
[[build.env]]
name = "GOOGLE_FUNCTION_SIGNATURE_TYPE"
value = "event"
[[build.env]]
name = "GOOGLE_FUNCTION_SOURCE"
$ cat .python-version 
3.8.6

当我尝试构建函数时,出现以下错误:

$ pack build foo --builder gcr.io/buildpacks/builder:v1v1: Pulling from buildpacks/builder
Digest: sha256:75f77739e5f8b6e06ff24ca56382de6ef44fce4d5def89dbde04fff5f8c95567
Status: Image is up to date for gcr.io/buildpacks/builder:v1
v1: Pulling from buildpacks/gcp/run
Digest: sha256:5c9214c1500035542b066d9fe8e4b5643c9b52388f52f543e91f55b8ebb27bc9
Status: Image is up to date for gcr.io/buildpacks/gcp/run:v1
===> DETECTING
4 of 5 buildpacks participating
google.python.runtime             0.9.1
google.python.functions-framework 0.9.1
google.python.pip                 0.9.1
google.utils.label                0.0.1
===> ANALYZING
Previous image with name "foo" not found
===> RESTORING
===> BUILDING
=== Python - Runtime (google.python.runtime@0.9.1) ===
Using runtime version from GOOGLE_RUNTIME_VERSION: python38
Failure: (ID: d1f5dcf5) Runtime version python38 does not exist at https://storage.googleapis.com/gcp-buildpacks/python/python-python38.tar.gz (status 403). You can specify the version with GOOGLE_RUNTIME_VERSION.
--------------------------------------------------------------------------------
Sorry your project couldn't be built.
Our documentation explains ways to configure Buildpacks to better recognise your project:
 -> https://github.com/GoogleCloudPlatform/buildpacks/blob/main/README.md
If you think you've found an issue, please report it:
 -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
--------------------------------------------------------------------------------
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 145

当我删除

[[build.env]]
name =  "GOOGLE_RUNTIME_VERSION"
value = "python38"

project.toml我得到以下错误:

$ pack build foo --builder gcr.io/buildpacks/builder:v1
v1: Pulling from buildpacks/builder
Digest: sha256:75f77739e5f8b6e06ff24ca56382de6ef44fce4d5def89dbde04fff5f8c95567
Status: Image is up to date for gcr.io/buildpacks/builder:v1
v1: Pulling from buildpacks/gcp/run
Digest: sha256:5c9214c1500035542b066d9fe8e4b5643c9b52388f52f543e91f55b8ebb27bc9
Status: Image is up to date for gcr.io/buildpacks/gcp/run:v1
===> DETECTING
4 of 5 buildpacks participating
google.python.runtime             0.9.1
google.python.functions-framework 0.9.1
google.python.pip                 0.9.1
google.utils.label                0.0.1
===> ANALYZING
Previous image with name "foo" not found
===> RESTORING
===> BUILDING
=== Python - Runtime (google.python.runtime@0.9.1) ===
Using runtime version from .python-version: 3.8.6
Failure: (ID: 8d3064d0) Runtime version 3.8.6 does not exist at https://storage.googleapis.com/gcp-buildpacks/python/python-3.8.6.tar.gz (status 403). You can specify the version with GOOGLE_RUNTIME_VERSION.
--------------------------------------------------------------------------------
Sorry your project couldn't be built.
Our documentation explains ways to configure Buildpacks to better recognise your project:
 -> https://github.com/GoogleCloudPlatform/buildpacks/blob/main/README.md
If you think you've found an issue, please report it:
 -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
--------------------------------------------------------------------------------
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 145

问题:

  1. 管理python的正确/最简单/推荐的方法是什么 此场景中的运行时版本
  2. 正确的值是多少 GOOGLE_RUNTIME_VERSION
  3. 有什么地方可以找到我的名单吗 在所有运行时版本中

Tags: tonamebuildprojectversiongooglebuilderoct
2条回答

我能够重现您所经历的错误,以下是我观察到的:


正如Dustin所建议的,为了使用Python 3.8.6,在.python-version文件中指定它就足够了:

3.8.6

但是,在project.toml中,也可以通过以下方式指定它:

[[build.env]]
name =  "GOOGLE_RUNTIME_VERSION"
value = "3.8.6"

关于available versions,尽管3.8.6似乎是受支持的最高版本,但buildpacks支持python3.7+

我还用版本3.8.43.8.03.7.73.7.23.7.0对它进行了测试,以确认这一点,并且对我来说是成功的,而3.9.0和低于3.7.0的版本导致了相同的错误:“运行时版本不存在”


删除project.toml中的GOOGLE_RUNTIME_VERSION时遇到的另一个错误(“很抱歉无法生成项目”),似乎与GOOGLE_FUNCTION_SOURCE设置有关,因为您没有为它指定值:

[[build.env]]
name = "GOOGLE_FUNCTION_SOURCE"

一旦我添加了值,错误就消失了。例如

[[build.env]]
name = "GOOGLE_FUNCTION_SOURCE"
value = "main.py"

给定运行时的可用性稍微落后于它对应的Python版本。您应该会发现3.8.6现在可用

What is the correct/easiest/recommended way for managing python runtime version in this scenario?

建议将.python-version设置为类似3.8.6的值

What is the correct value for GOOGLE_RUNTIME_VERSION?

这与您在.python-version中输入的内容相同,但优先于它

Is there any place where I can find list of all runtime versions?

不幸的是,目前还没有,但是您可以在https://github.com/GoogleCloudPlatform/buildpacks提交一个问题以请求此操作

相关问题 更多 >