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
Moby (used by Docker) actually has an "unknown" error code:
It usually indicates that your container environment (Docker) is a bit sickly and should be restarted.
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.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.
Hopefully the additional information from the detailed output channel will give you what you need to debug and fix your build.