gcloud 崩溃(OSError):[Errno 2] 没有这样的文件或目录:'/workspace/env/bin/python3.7'

gcloud crashed (OSError): [Errno 2] No such file or directory: '/workspace/env/bin/python3.7'

尝试部署我的 fastapi python 服务(在 App Engine 上)时,我 运行 在部署步骤中遇到以下错误:ERROR: gcloud crashed (OSError): [Errno 2] No such file or directory: '/workspace/env/bin/python3.7'

我正在使用以下命令从我的本地计算机启动 deploy/build:gcloud builds submit --config config/cloudbuild/deploy.yaml --project $_PROJECT

是我做错了什么,还是gcloud builder出了问题?我已经尝试使用 google cloud sdk 版本 274.0.1 和 300.0.0.

deploy.yaml:

steps:

  # Install gcc
  - name: 'python:3.7'
    id: 'install-dependencies'
    entrypoint: sh
    args:
      - -c
      - apt update && apt-get -y install gcc && python -m pip install -r requirements.txt -t lib

  # Run tests
  - name: 'python:3.7'
    id: 'test'
    env:
      - PYTHONPATH=lib
    entrypoint: python3
    args: ['-m', 'pytest']

  # Deploy
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', '--project', '$PROJECT_ID']

timeout: '1200s'

app.yaml:

runtime: python37
service: my-service
instance_class: F2

entrypoint: gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
handlers:
  - url: /.*
    script: auto
    secure: always

inbound_services:
- warmup

automatic_scaling:
  min_instances: 1
  min_idle_instances: 1
  max_instances: 2
  max_idle_instances: 1

构建输出:

...
Finished Step #1 - "test"
Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #2:
Step #2:                    ***** NOTICE *****
Step #2:
Step #2: Official `cloud-sdk` images, including multiple tagged versions across multiple
Step #2: platforms, can be found at
Step #2: https://github.com/GoogleCloudPlatform/cloud-sdk-docker.
Step #2:
Step #2: Suggested alternative images include:
Step #2:
Step #2:     gcr.io/google.com/cloudsdktool/cloud-sdk
Step #2:     gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
Step #2:     gcr.io/google.com/cloudsdktool/cloud-sdk:debian_component_based
Step #2:     gcr.io/google.com/cloudsdktool/cloud-sdk:slim
Step #2:
Step #2: Please note that the `gcloud` entrypoint must be specified when using these
Step #2: images.
Step #2:
Step #2:                 ***** END OF NOTICE *****
Step #2:
Step #2: Services to deploy:
Step #2:
Step #2: descriptor:      [/workspace/app.yaml]
Step #2: source:          [/workspace]
Step #2: target project:  [my-project]
Step #2: target service:  [my-service]
Step #2: target version:  [20200710t134102]
Step #2: target url:      [https://my-service.uc.r.appspot.com]
Step #2:
Step #2:
Step #2: Do you want to continue (Y/n)?
Step #2: Beginning deployment of service [my-service]...
Step #2: Created .gcloudignore file. See `gcloud topic gcloudignore` for details.
Step #2: ERROR: gcloud crashed (OSError): [Errno 2] No such file or directory: '/workspace/env/bin/python3.7'
Step #2:
Step #2: If you would like to report this issue, please run the following command:
Step #2:   gcloud feedback
Step #2:
Step #2: To check gcloud for common problems, please run the following command:
Step #2:   gcloud info --run-diagnostics
Finished Step #2
ERROR
ERROR: build step 2 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1

Cloud Build 本质上是一个应用于共享文件系统 (/workspace) 的容器管道。

您唯一可用的状态是通过 /workspace

每一步都隐式挂载 /workspace

您的第 0 步大部分是多余的。它将 apt 应用于步骤 #0 中创建的容器映像(并且可能作为副作用)也会更新已安装的 /workspace 但这些更新将被丢弃(除了 /workspace 的突变该步骤完成。您不应尝试使用例如您打算在后续步骤中使用的 Python 模块安装来更新 /workspace

我怀疑您正在安装 pytest 和步骤 #0 中的 requirements.txt 但这并不正确地适用于步骤 #1 对 pytest 的使用。您应该做的是创建一个包含 pytest 的容器,以便您可以 运行 pytest 在此步骤中。

如果您放弃除第 2 步以外的所有内容,它应该会起作用(对我来说是这样)。

如果您希望 运行 pytest,您将需要一个包含它的容器映像,以便您可以 运行 在部署之前执行此独立步骤。