skip to Main Content

I am using VS Code with the Cloud Code extension to try to deploy a Python script to GCP Cloud Run. I am able to run the "hello, world" python flask app locally with the Cloud Run emulator and am also able to move it to deploy it to Cloud Run successfully, but the minute that I try to add any external libraries via the requirements.txt file and import in the app.py file, I get the following build failure error message:

Update failed with error code BUILD_DOCKER_UNKNOWN

app.py file:

"""
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')

requirements.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"]

Is that not how I’m supposed to add library dependencies? Please let me know what else I can provide to help troubleshoot this.

2

Answers


  1. Moby (used by Docker) actually has an "unknown" error code:

    // ErrUnknown signals that the kind of error that occurred is not known.
    type ErrUnknown interface {
        Unknown()
    }
    

    It usually indicates that your container environment (Docker) is a bit sickly and should be restarted.

    Login or Signup to reply.
  2. A tip for debugging Cloud Run: in the Output panel, there is a separate channel called Cloud Run: Run/Debug Locally - Detailed. This includes much more verbose logging from associated Skaffold and Docker subprocesses. Screenshot showing location of detailed channel

    When I attempted to repro the steps you followed (install the Python Flask Hello World sample, add a dependency on pandas 1.5.0) I was able to see some dependency compile issues for transitive dependencies of the added package, perhaps you ran into something similar.

    #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 
    

    Hopefully the additional information from the detailed output channel will give you what you need to debug and fix your build.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search