python - 更新失败,错误代码为 BUILD_DOCKER_UNKNOWN

标签 python visual-studio-code google-cloud-platform google-cloud-code

我正在使用 VS Code 和 Cloud Code 扩展来尝试将 Python 脚本部署到 GCP Cloud Run。我可以使用 Cloud Run 模拟器在本地运行“hello, world”python Flask 应用程序,也可以将其移动以成功部署到 Cloud Run,但当我尝试通过要求添加任何外部库时。 txt 文件并导入到 app.py 文件中,我收到以下构建失败错误消息:

Update failed with error code BUILD_DOCKER_UNKNOWN

app.py 文件:

"""
A sample Hello World server.
"""
import os

from flask import Flask, render_template
import pandas as pd

# pylint: disable=C0103
app = Flask(__name__)


@app.route('/')
def hello():
    """Return a friendly HTTP greeting."""
    message = "It's running!"

    """Get Cloud Run environment variables."""
    service = os.environ.get('K_SERVICE', 'Unknown service')
    revision = os.environ.get('K_REVISION', 'Unknown revision')

    return render_template('index.html',
        message=message,
        Service=service,
        Revision=revision)

if __name__ == '__main__':
    server_port = os.environ.get('PORT', '8080')
    app.run(debug=False, port=server_port, host='0.0.0.0')

需求.txt

Flask==2.2.2
requests==2.28.1
ptvsd==4.3.2 # Required for debugging.
pandas==1.5.0

Dockerfile:

# Python image to use.
FROM python:3.10-alpine

# Set the working directory to /app
WORKDIR /app

# copy the requirements file used for dependencies
COPY requirements.txt .

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Copy the rest of the working directory contents into the container at /app
COPY . .

# Run app.py when the container launches
ENTRYPOINT ["python", "app.py"]

这不是我应该添加库依赖项的方式吗?请让我知道我还能提供什么来帮助解决此问题。

最佳答案

调试 Cloud Run 的提示:在“输出”面板中,有一个名为 Cloud Run:本地运行/调试 - 详细 的单独 channel 。这包括来自关联 Skaffold 和 Docker 子进程的更详细的日志记录。 Screenshot showing location of detailed channel

当我尝试重现您遵循的步骤(安装 Python Flask Hello World 示例,添加对 pandas 1.5.0 的依赖项)时,我能够看到所添加包的传递依赖项的一些依赖项编译问题,也许您运行了进入类似的东西。

#8 4.842 Collecting pandas==1.5.0
#8 4.912   Downloading pandas-1.5.0.tar.gz (5.2 MB)
#8 5.055      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.2/5.2 MB 37.2 MB/s eta 0:00:00
#8 6.508   Installing build dependencies: started
#8 28.55   Installing build dependencies: finished with status 'error'
#8 28.58   error: subprocess-exited-with-error
#8 28.58   
#8 28.58   × pip subprocess to install build dependencies did not run successfully.
#8 28.58   │ exit code: 1
#8 28.58   ╰─> [281 lines of output]
#8 28.58       Collecting setuptools>=51.0.0
#8 28.58         Downloading setuptools-65.4.1-py3-none-any.whl (1.2 MB)
#8 28.58            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 18.0 MB/s eta 0:00:00
#8 28.58       Collecting wheel
#8 28.58         Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
#8 28.58       Collecting Cython<3,>=0.29.32
#8 28.58         Downloading Cython-0.29.32-cp310-cp310-musllinux_1_1_x86_64.whl (2.0 MB)
#8 28.58            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 30.0 MB/s eta 0:00:00
#8 28.58       Collecting oldest-supported-numpy>=0.10
#8 28.58         Downloading oldest_supported_numpy-2022.8.16-py3-none-any.whl (3.9 kB)
#8 28.58       Collecting numpy==1.21.6
#8 28.58         Downloading numpy-1.21.6.zip (10.3 MB)
#8 28.58            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.3/10.3 MB 37.4 MB/s eta 0:00:00
#8 28.58         Installing build dependencies: started
#8 28.58         Installing build dependencies: finished with status 'done'
#8 28.58         Getting requirements to build wheel: started
#8 28.58         Getting requirements to build wheel: finished with status 'done'
#8 28.58         Preparing metadata (pyproject.toml): started
#8 28.58         Preparing metadata (pyproject.toml): finished with status 'done'
#8 28.58       Building wheels for collected packages: numpy
#8 28.58         Building wheel for numpy (pyproject.toml): started
#8 28.58         Building wheel for numpy (pyproject.toml): finished with status 'error'
#8 28.58         error: subprocess-exited-with-error
#8 28.58       
#8 28.58         × Building wheel for numpy (pyproject.toml) did not run successfully.

...
...
...

#8 28.58                 raise RuntimeError("Broken toolchain: cannot link a simple C program")
#8 28.58             RuntimeError: Broken toolchain: cannot link a simple C program
#8 28.58             [end of output]
#8 28.58       
#8 28.58         note: This error originates from a subprocess, and is likely not a problem with pip.
#8 28.58         ERROR: Failed building wheel for numpy
#8 28.58       Failed to build numpy
#8 28.58       ERROR: Could not build wheels for numpy, which is required to install pyproject.toml-based projects
#8 28.58       [end of output]
#8 28.58   
#8 28.58   note: This error originates from a subprocess, and is likely not a problem with pip.
#8 28.58 error: subprocess-exited-with-error
#8 28.58 

希望详细输出 channel 中的附加信息能为您提供调试和修复构建所需的信息。

关于python - 更新失败,错误代码为 BUILD_DOCKER_UNKNOWN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73929040/

相关文章:

python - 奥杜 11 : How to get current record in javascript

python - 更改 tkinter 菜单栏的颜色

python - Django-如何确定 ModelForm init 中的字段类型?

node.js - @types/node 和 VS 代码 : IntelliSense not working because of comment formatting

python - Google Cloud Functions (Python) 中的随机连接错误

python - scipy.integrate.ode.integrate() 可选的 `step` 和 `relax` 参数有什么作用?

visual-studio-code - 如何让 Pytest 调用 VSCode 断点 View 而不是 PDB

visual-studio-code - 更改 VSCode 回溯中的突出显示颜色/文本颜色

google-cloud-platform - 您如何通过 Google Cloud Composer 安排 GCP AI Platform 笔记本?

docker - 谷歌云容器注册表错误: “Failed to trigger build: Request contains an invalid argument.”