dlib 库未安装在 gcloud 上
Posted
技术标签:
【中文标题】dlib 库未安装在 gcloud 上【英文标题】:dlib library is not installing on gcloud 【发布时间】:2021-12-21 02:14:22 【问题描述】:我正在 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
【问题讨论】:
这能回答你的问题吗? Installing dlib with python 3.8 windows 10 error 【参考方案1】:在将应用程序部署到 Cloud Run 时使用 gcloud
命令:gcloud run deploy
将允许您在 Cloud Build 中构建映像只需 10 分钟。镜像构建成功后,会自动部署到 Cloud Run,但是如果失败,则会收到超时错误或 Cloud Run 部署错误:
部署失败
错误:(gcloud.run.deploy) DEADLINE_EXCEEDED
根据这个link,dlib
和必要的包会被安装5-10分钟导致你失败。
如何修复和部署?
您应该手动创建容器映像并将其部署到 Cloud Run。
-
在 Artifacts 注册表中创建 Docker 存储库:
gcloud artifacts repositories create AR-REPO-NAME --repository-format=docker \
--location=us-central1 --description="Docker repository"
将 AR-REPO-NAME
替换为您首选的 Docker 存储库名称。
-
构建带有
--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
目录
-
将容器映像部署到 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 如果您对我的回答有任何澄清或疑问,请告诉我。如果对您有帮助,您可以接受或投票赞成我的回答。以上是关于dlib 库未安装在 gcloud 上的主要内容,如果未能解决你的问题,请参考以下文章