Python 3.9版Google Cloud Function突发构建失败求助
Google Cloud Functions Python 3.9构建失败:缺失gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder镜像
问题描述
我有一个基于Python 3.9的Google Cloud Function,此前运行完全正常,近期未对函数或依赖做任何修改,但手动测试时突然构建失败,报错找不到指定的builder镜像。
错误日志
[10:37:08 PM] - Preparing function sources ... [10:37:08 PM] - Building function sources ... [10:37:09 PM] - Error: Command failed: cd /gcf-working-dir/function-sources && pack build gcf-ui-function --builder gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder --pull-policy if-not-present --env GOOGLE_FUNCTION_TARGET=hello_http --env GOOGLE_FUNCTION_SIGNATURE_TYPE=cloudevent --env GOOGLE_DEVMODE=1 --env GOOGLE_RUNTIME_VERSION=3.9 ERROR: failed to build: failed to fetch builder image 'gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder:latest': image 'gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder:latest' does not exist on the daemon: not found > at checkExecSyncError (node:child_process:826:11) at execSync (node:child_process:900:15) at buildFunction (/app/app.runfiles/google3/cloud/console/web/functions/external/testing_server/workers/build_function_worker.js:17:38) at Object.<anonymous> (/app/app.runfiles/google3/cloud/console/web/functions/external/testing_server/workers/build_function_worker.js:35:131) at Module._compile (node:internal/modules/cjs/loader:1095:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:816:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) at MessagePort.<anonymous> (node:internal/main/worker_thread:183:24) ERROR: failed to build: failed to fetch builder image 'gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder:latest': image 'gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder:latest' does not exist on the daemon: not found [10:37:09 PM] - Error while building function sources. Please check logs.
已尝试的操作
- 反复确认Cloud Function的运行时设置为Python 3.9
- 验证
gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder:latest镜像的可用性 - 多次重新部署函数,问题依旧
额外信息
- 函数此前无任何运行问题
- 近期未修改函数代码或依赖项
- Google Cloud SDK已更新至最新版本
可能的解决方法
1. 强制拉取最新镜像,跳过本地缓存
部署时修改构建的拉取策略,强制从仓库拉取最新镜像,避免本地缓存的过期镜像导致问题。使用gcloud命令部署时可指定参数:
gcloud functions deploy YOUR_FUNCTION_NAME \ --runtime python39 \ --trigger-http \ --build-args="pull-policy=always"
2. 指定具体的镜像版本标签而非latest
latest标签可能被移除或更新,可通过GCR仓库页面查看该镜像的可用版本标签,替换命令中的latest为对应版本号,示例:
pack build gcf-ui-function \ --builder gcr.io/gae-runtimes/buildpacks/google-gae-18/python/builder:20240501 \ --pull-policy always \ --env GOOGLE_FUNCTION_TARGET=hello_http \ --env GOOGLE_FUNCTION_SIGNATURE_TYPE=cloudevent \ --env GOOGLE_DEVMODE=1 \ --env GOOGLE_RUNTIME_VERSION=3.9
3. 切换到GCP官方通用buildpack builder
如果特定的gae-18 builder已被废弃,尝试使用GCP通用的buildpack builder镜像:
pack build gcf-ui-function \ --builder gcr.io/buildpacks/builder:v1 \ --pull-policy always \ --env GOOGLE_FUNCTION_TARGET=hello_http \ --env GOOGLE_FUNCTION_SIGNATURE_TYPE=cloudevent \ --env GOOGLE_DEVMODE=1 \ --env GOOGLE_RUNTIME_VERSION=3.9
4. 清理构建缓存后重新部署
部署时添加--no-cache参数,强制跳过构建缓存,重新完成全量构建:
gcloud functions deploy YOUR_FUNCTION_NAME \ --runtime python39 \ --trigger-http \ --no-cache
5. 检查项目服务账号的镜像拉取权限
确认Cloud Functions默认使用的服务账号(PROJECT_ID@appspot.gserviceaccount.com)拥有storage.objectViewer权限,确保能正常访问GCR仓库中的镜像。可通过IAM页面为该账号添加对应权限。
内容的提问来源于stack exchange,提问作者Veeee
相关产品推荐
相关产品推荐

