2

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.

Nick Nelson
  • 1,131
  • 2
  • 18
  • 36
  • Remove the package `ptvsd` and try again. You cannot remotely debug Cloud run applications with Visual Studio. – John Hanley Oct 02 '22 at 22:12
  • This did not fix the issue. To be clear, I am able to "Run on Cloud Run Emulator" using the Flask sample app without changing anything. Once I add "pandas==1.5.0" to the requirements.txt file, the build fails with the error above. – Nick Nelson Oct 03 '22 at 13:55

2 Answers2

3

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.

  • Awesome tip, I didn't know about that! Thanks! This gave me some better information to google and found that starting with a different base Python version did the trick. Was able to compile an app with python:3.10 instead of python:3.10-alpine and pip installed pandas just fine. – Nick Nelson Oct 04 '22 at 00:12
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.

Brian de Alwis
  • 2,814
  • 2
  • 18
  • 32
  • Is this relevant even if I am using the "Cloud Shell Editor" in GCP to develop the app from one of their working samples? Literally, the only thing I added to the working example was the pandas==1.5.0 in the requirements.txt file and it breaks. – Nick Nelson Oct 03 '22 at 13:56
  • I don’t know the internal details of Moby/Docker. Maybe you’re running out of memory or disk space? – Brian de Alwis Oct 05 '22 at 00:23