【问题标题】:How to set runtime version in Google Cloud Buildpacks when using Functions Framework for Python?使用 Functions Framework for Python 时如何在 Google Cloud Buildpacks 中设置运行时版本?
【发布时间】:2020-10-18 01:06:56
【问题描述】:

我正在尝试使用 Functions Framework 来使用 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. 有没有可以找到列表的地方 的所有运行时版本?

【问题讨论】:

    标签: python google-cloud-platform google-cloud-functions


    【解决方案1】:

    我能够重现您遇到的错误,这是我观察到的:


    按照 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 支持Python 3.7+。

    我还用3.8.4、3.8.0、3.7.7、3.7.2 和3.7.0 版本对其进行了测试,以确认这一点,这对我来说是成功的,而3.9.0 和低于@ 的版本987654333@ 导致同样的错误:“运行时版本不存在”。


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

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

    添加值后,错误就消失了。例如

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

    【讨论】:

      【解决方案2】:

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

      在这种情况下管理 python 运行时版本的正确/最简单/推荐的方法是什么?

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

      GOOGLE_RUNTIME_VERSION 的正确值是多少?

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

      有什么地方可以找到所有运行时版本的列表吗?

      很遗憾,目前没有,但您可以通过https://github.com/GoogleCloudPlatform/buildpacks 提出问题来提出请求。

      【讨论】:

        猜你喜欢
        • 2021-12-26
        • 2019-11-15
        • 2019-07-11
        • 1970-01-01
        • 2020-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多