【问题标题】:gcloud crashed (OSError): [Errno 2] No such file or directory: '/workspace/env/bin/python3.7'gcloud 崩溃(OSError):[Errno 2] 没有这样的文件或目录:'/workspace/env/bin/python3.7'
【发布时间】:2020-10-31 06:56:56
【问题描述】:

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

我正在使用以下命令从本地计算机开始部署/构建: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

【问题讨论】:

    标签: python deployment build python-3.7 gcloud


    【解决方案1】:

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

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

    每一步都隐式挂载/workspace

    您的第 0 步基本上是多余的。它将apt 应用于在步骤#0 中创建的容器映像(并且可能作为副作用)更新已安装的/workspace,但这些更新被丢弃(除了当该步骤完成时对/workspace 的突变。你应该'不要尝试使用您打算在后续步骤中使用的 Python 模块安装来更新 /workspace

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

    如果您放弃除第 2 步之外的所有内容,它应该可以工作(对我有用)。

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

    【讨论】:

    • 谢谢,运行gcloud app deploy 直接有效。通过从中删除.gcloudignore 并添加虚拟环境目录,我让它也能正常工作。到.gcloudignore。不知道为什么/怎么可能是问题,但是..
    • 嘿@5ton3 如果它解决了你的问题,请将其标记为正确
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2017-06-13
    • 2012-07-18
    • 1970-01-01
    • 2015-11-17
    相关资源
    最近更新 更多