【问题标题】:dlib library is not installing on gclouddlib 库未安装在 gcloud 上
【发布时间】:2023-03-08 19:35:01
【问题描述】:

我正在 google cloud run 上部署一个烧瓶应用程序,但我遇到了关于在 dlib 库上安装的问题。 dlib 开始安装,然后进入循环构建 dlib 轮,然后在一段时间后抛出错误。 CMake 库已经安装成功。

这里是 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

这是错误

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

【问题讨论】:

标签: python google-cloud-platform gcloud google-cloud-run dlib


【解决方案1】:

在将应用程序部署到 Cloud Run 时使用 gcloud 命令:gcloud run deploy 将允许您在 Cloud Build 中构建映像只需 10 分钟。镜像构建成功后,会自动部署到 Cloud Run,但是如果失败,则会收到超时错误或 Cloud Run 部署错误:

部署失败

错误:(gcloud.run.deploy) DEADLINE_EXCEEDED

根据这个linkdlib和必要的包会被安装5-10分钟导致你失败​​。

如何修复和部署?

您应该手动创建容器映像并将其部署到 Cloud Run。

  1. 在 Artifacts 注册表中创建 Docker 存储库:
gcloud artifacts repositories create AR-REPO-NAME --repository-format=docker \
--location=us-central1 --description="Docker repository"
  • AR-REPO-NAME 替换为您首选的 Docker 存储库名称。
  1. 构建带有--timeout标志的Docker镜像以延长镜像的总构建时间:
gcloud builds submit --tag us-central1-docker.pkg.dev/PROJECT-ID/AR-NAME/IMAGE-NAME \
/path/to/your/application --timeout=30m
  • PROJECT-ID 替换为您的 Cloud 项目 ID
  • IMAGE-NAME 替换为您喜欢的图片名称
  • /path/to/your/application替换为您的应用程序和Dockerfile目录
  1. 将容器映像部署到 Cloud Run:
gcloud run deploy SERVICE-NAME --image IMAGE_URL
  • SERVICE-NAME 替换为您首选的 Cloud Run 服务名称
  • IMAGE_URL 替换为您在 Artifacts Registry 中的容器映像 URL,例如:
gcloud run deploy SERVICE-NAME \
--image us-central1-docker.pkg.dev/PROJECT-ID/AR-REPO-NAME/IMAGE-NAME 

【讨论】:

  • @ZainFareed 如果您对我的回答有任何澄清或疑问,请告诉我。如果对您有帮助,您可以接受或投票赞成我的回答。
猜你喜欢
  • 2020-03-04
  • 2015-11-07
  • 2017-06-14
  • 2017-04-12
  • 2018-10-12
  • 2020-07-09
  • 2020-07-08
  • 2018-09-15
  • 2018-11-30
相关资源
最近更新 更多