Maciek Sawicki
Maciek Sawicki

Reputation: 6835

How to set runtime version in Google Cloud Buildpacks when using Functions Framework for Python?

I'm trying to use Functions Framework to build my function using 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

I get following error when I try to build the function:

$ 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 ([email protected]) ===
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

When I delete

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

from project.toml I get following error:

$ 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 ([email protected]) ===
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

Questions:

  1. What is the correct/easiest/recommended way for managing python runtime version in this scenario?
  2. What is the correct value for GOOGLE_RUNTIME_VERSION?
  3. Is there any place where I can find list of all runtime versions?

Upvotes: 3

Views: 1929

Answers (2)

Deniss T.
Deniss T.

Reputation: 2652

I was able to reproduce the errors you're experiencing and here's what I observed:


As advised by Dustin, in order to use Python 3.8.6, it should be enough to specify it in the .python-version file:

3.8.6

In project.toml, however, you can also specify it the following way:

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

Regarding the available versions, buildpacks support Python 3.7+ although 3.8.6 seems to be the highest supported version.

I've also tested it with versions 3.8.4, 3.8.0, 3.7.7, 3.7.2 and 3.7.0 to confirm that, and it's been successful for me, while 3.9.0 and versions lower than 3.7.0 were leading to the same error: "Runtime version does not exist".


The other error you were experiencing ("Sorry your project couldn't be built") when deleting GOOGLE_RUNTIME_VERSION in project.toml seems to be related to your GOOGLE_FUNCTION_SOURCE setting as you haven't specified the value for it:

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

The error was gone once I added the value. E.g.

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

Upvotes: 1

Dustin Ingram
Dustin Ingram

Reputation: 21580

The availability of a given runtime lags a bit behind the Python release it corresponds to. You should find that 3.8.6 is now available.

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

Setting .python-version to a value like 3.8.6 is the recommended way.

What is the correct value for GOOGLE_RUNTIME_VERSION?

This would be the same as what you'd put in .python-version, but would take precedence over it.

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

Unfortunately not at this time, but you can file an issue at https://github.com/GoogleCloudPlatform/buildpacks to request this.

Upvotes: 0

Related Questions