在Google Cloud构建中部署功能时,可以找到依赖关系

发布于 2025-02-09 20:00:51 字数 1532 浏览 2 评论 0原文

因此,IM试图创建一个Google Cloud功能,该功能导入一个称为PDFTOTEXT的Python软件包。现在,为了pip安装pdftotext,您必须安装一些系统依赖项。 IE:

sudo apt install build-essential libpoppler-cpp-dev pkg-config python3-dev

现在,我的解决方案是创建我上传到Google源存储库的CloudBuild.yml文件,然后使用cloud build trigger,然后在将某些东西推到某些内容时部署该函数,然后将其部署仓库。

我的CloudBuild.yml文件看起来像这样:

 steps:
  # Install OS Dependencies
  - name: "docker.io/library/python:3.9"
    id: "OS Dependencies"
    entrypoint: bash
    args:
      - '-c'
      - | 
        apt-get update
        apt-get install -y build-essential libpoppler-cpp-dev pkg-config python3-dev
        apt-get install -y pip
        pip3 install -t /workspace/lib -r requirements.txt
  # Deploy Function      
  - name: "gcr.io/cloud-builders/gcloud"
    id: "Deploy Function"
    args:
      [ 
        "functions",
        "deploy",
        "pdf_handler",
        "--entry-point",
        "main",
        "--source",
        ".",
        "--runtime",
        "python39",
        "--memory",
        "256MB",
        "--service-account",
        "my_service_account",
        "--trigger-http",
        "--timeout",
        "540",
        "--region",
        "europe-west1",
      ]
options:
  logging: CLOUD_LOGGING_ONLY

触发器试图部署该函数,但是即使我安装了OS依赖项,我仍然会遇到此错误

"Deploy Function": pdftotext.cpp:3:10: fatal error: poppler/cpp/poppler-document.h: No such file or directory

,似乎该功能部署似乎无法找到依赖关系安装的位置。

我尝试在同一步骤中安装和部署,但仍然会遇到相同的错误。

任何建议将不胜感激。

提前致谢!

So im trying to create a google cloud function that imports a python package called pdftotext. Now in order to pip install pdftotext you have to install some system dependencies. i.e:

sudo apt install build-essential libpoppler-cpp-dev pkg-config python3-dev

Now my solution to doing that is to create a requirements.txt and a cloudbuild.yml file that I upload to google source repositories and then use a cloud build trigger that listens to the repo, and deploys the function when something is pushed to the repo.

my cloudbuild.yml file looks like this:

 steps:
  # Install OS Dependencies
  - name: "docker.io/library/python:3.9"
    id: "OS Dependencies"
    entrypoint: bash
    args:
      - '-c'
      - | 
        apt-get update
        apt-get install -y build-essential libpoppler-cpp-dev pkg-config python3-dev
        apt-get install -y pip
        pip3 install -t /workspace/lib -r requirements.txt
  # Deploy Function      
  - name: "gcr.io/cloud-builders/gcloud"
    id: "Deploy Function"
    args:
      [ 
        "functions",
        "deploy",
        "pdf_handler",
        "--entry-point",
        "main",
        "--source",
        ".",
        "--runtime",
        "python39",
        "--memory",
        "256MB",
        "--service-account",
        "my_service_account",
        "--trigger-http",
        "--timeout",
        "540",
        "--region",
        "europe-west1",
      ]
options:
  logging: CLOUD_LOGGING_ONLY

The trigger tries to deploy the function but i keep getting this error even though i installed the OS dependencies

"Deploy Function": pdftotext.cpp:3:10: fatal error: poppler/cpp/poppler-document.h: No such file or directory

It seems like the function deployment can't find the location where the dependencies are installed.

I've tried installing and deploying in the same step but still get the same error.

Any advice is appreciated.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2025-02-16 20:00:52

当您使用云功能部署时,仅通过服务将代码(在容器中)包装。

在包装期间,调用另一个云构建来构建该容器(使用buildpacks.io),然后将其部署。部署并不关心您在环境中安装一些APT软件包。但是您的 /lib目录已上传到该新的云构建,

您应该更新您部署的云功能代码的support.txt < /code>,以指向 /lib目录,以防止PIP寻找外部包(和汇编要求)

When you deploy with Cloud Functions, ONLY your code is taken and packaged (in a container) by the service.

During the packaging, another Cloud Build is called to build that container (with Buildpacks.io) and then to deploy it. That deployment doesn't care that you install some APT packages in your environment. But your /lib directory is uploaded to that new Cloud Build

You should update your requirements.txt of the Cloud Functions code that you deploy to point to the /lib directory to prevent PIP looking for external package (and compilation requirement)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文