0

I'm deploying a flask application on google cloud run but I'm facing issue regarding installation on dlib library. dlib started to install then it goes to loop to build dlib wheel then after some time it throws an error. CMake libray is already installed successfully.

Here is the Dockerfile

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.8-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
#RUN apt-get update && apt-get install -y cmake
#RUN sudo apt-get update && sudo apt-get install build-essential
#RUN apt-get update && apt-get install build-essential cmake

RUN apt update && apt install -y gcc clang clang-tools cmake python3
RUN pip install dlib

RUN pip install --no-cache-dir -r requirements.txt
RUN pip install gunicorn

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

Here is the error

Building wheels for collected packages: dlib, face-recognition-models
  Building wheel for dlib (setup.py): started
  Building wheel for dlib (setup.py): still running...
  Building wheel for dlib (setup.py): still running...
  Building wheel for dlib (setup.py): still running...
  Building wheel for dlib (setup.py): still running...
  Building wheel for dlib (setup.py): still running...
  Building wheel for dlib (setup.py): still running...
  Building wheel for dlib (setup.py): still running...
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 2
JM Gelilio
  • 3,482
  • 1
  • 11
  • 23
  • Does this answer your question? [Installing dlib with python 3.8 windows 10 error](https://stackoverflow.com/questions/59350831/installing-dlib-with-python-3-8-windows-10-error) – kiner_shah Nov 08 '21 at 07:51

1 Answers1

0

Using gcloud command: gcloud run deploy when deploying your application to Cloud Run will allow you to build image in Cloud Build for only 10 minutes. When the image is successfully built, it will deploy to Cloud Run automatically, but if it is fails, you will receive timeout error or Cloud Run deployment error:

Deployment failed

ERROR: (gcloud.run.deploy) DEADLINE_EXCEEDED

According to this link, the dlib and necessary package will be installed for 5-10 minutes which lead you to fail.

HOW TO FIX AND DEPLOY?

You should manually create the container image and deploy it to Cloud Run.

  1. Create Docker Repository in Artifacts registry:
gcloud artifacts repositories create AR-REPO-NAME --repository-format=docker \
--location=us-central1 --description="Docker repository"
  • Replace the AR-REPO-NAME to your preferred Docker Repository name.
  1. Build a Docker image with --timeout flag to extend the total build time of the image:
gcloud builds submit --tag us-central1-docker.pkg.dev/PROJECT-ID/AR-NAME/IMAGE-NAME \
/path/to/your/application --timeout=30m
  • Replace the PROJECT-ID to your Cloud Project ID
  • Replace the IMAGE-NAME to your preferred image name
  • Replace the /path/to/your/application to your application and Dockerfile directory
  1. Deploy the container image to Cloud Run:
gcloud run deploy SERVICE-NAME --image IMAGE_URL
  • Replace the SERVICE-NAME to your preferred Cloud Run Service name
  • Replace the IMAGE_URL to your container image URL in your Artifacts Registry, for example:
gcloud run deploy SERVICE-NAME \
--image us-central1-docker.pkg.dev/PROJECT-ID/AR-REPO-NAME/IMAGE-NAME 
JM Gelilio
  • 3,482
  • 1
  • 11
  • 23