【问题标题】:Google Cloud Functions (GCF) - installing packages With apt-getGoogle Cloud Functions (GCF) - 使用 apt-get 安装包
【发布时间】:2019-01-31 09:43:36
【问题描述】:

我的 Google Cloud Functions (GCF) 功能需要 2 个软件包才能正常工作。我通常会在 Ubuntu 上使用以下命令安装它们:

apt-get -y install firefox xvfb

但是,无论如何,我不知道要打包我的函数,这将指导 GCF 在运行我的代码之前下载这些包。

我尝试使用 subprocess.call() 从我的 Python 函数中安装它们。

这里有一些代码:

try:
    print(subprocess.check_output("apt-get -y install firefox", shell=True, stderr=subprocess.STDOUT))
except subprocess.CalledProcessError as e:
    print("Ping stdout output:\n", e.output)

try:
    print(subprocess.check_output("apt-get -y install xvfb", shell=True, stderr=subprocess.STDOUT))
except subprocess.CalledProcessError as e:
    print("Ping stdout output:\n", e.output)

很遗憾,这不起作用。我收到以下错误:

Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
 libcanberra0 libdbusmenu-gtk3-4 libstartup-notification0 libtdb1
 libxcb-util1 sound-theme-freedesktop xul-ext-ubufox
Suggested packages:\n fonts-lyx libcanberra-gtk0 libcanberra-pulse
The following NEW packages will be installed: firefox
 libcanberra0 libdbusmenu-gtk3-4 libstartup-notification0 libtdb1
 libxcb-util1 sound-theme-freedesktop xul-ext-ubufox
0 upgraded, 8 newly installed, 0 to remove and 5 not upgraded.
Need to get 44.5 MB of archives.
After this operation, 170 MB of additional disk space will be used.
W: Not using locking for read only lock file /var/lib/dpkg/lock
W: chown to _apt:root of directory /var/cache/apt/archives/partial failed - SetupAPTPartialDirectory (30: Read-only file system)
W: chmod 0700 of directory /var/cache/apt/archives/partial failed - SetupAPTPartialDirectory (1: Operation not permitted)
W: chown to _apt:root of directory /var/lib/apt/lists/auxfiles failed - SetupAPTPartialDirectory (30: Read-only file system)
W: chmod 0700 of directory /var/lib/apt/lists/auxfiles failed - SetupAPTPartialDirectory (1: Operation not permitted)
W: Not using locking for read only lock file /var/cache/apt/archives/lock
E: Couldn't determine free space in /var/cache/apt/archives/ - statvfs (38: Function not implemented)

如何解决此错误以从我的 python 代码中下载包?有没有其他(更简单/更清洁)的方法来实现我想要做的事情?

谢谢!

【问题讨论】:

    标签: python-3.x firefox google-cloud-platform google-cloud-functions xvfb


    【解决方案1】:

    您可以使用public issue tracker 请求将新包添加到运行时。请注意,问题跟踪器显示“App Engine”,但只是提到这是针对 Cloud Functions 的。

    【讨论】:

      【解决方案2】:

      不是您问题的直接答案,但您似乎正在尝试在 GCF 中使用无头浏览器。值得一提的是,Cloud Functions 现在支持无头 Chrome,如果您能够从 Firefox 过渡到 Chrome,它可能会更容易使用:

      https://cloud.google.com/blog/products/gcp/introducing-headless-chrome-support-in-cloud-functions-and-app-engine

      【讨论】:

        【解决方案3】:

        【讨论】:

          【解决方案4】:

          您无法安排在 Cloud Functions 实例上安装软件包。这是因为您的代码没有以 root 权限运行。如果您需要二进制文件可用于部署到 Cloud Functions 的代码,您必须自己为 Debian 构建它,并将二进制文件包含在您的函数目录中,以便它与您的其余代码一起部署。

          即使您能够做到这一点,也不能保证它会起作用,因为 Cloud Fucntions 映像可能不包含可执行文件工作所需的所有共享库。

          【讨论】:

          • 是否有任何文档详细说明 GCF 使用哪些操作系统,以及它们是否会发生变化?在另一个 SO 问题中,我询问了有关预先构建一些 Python 库的问题,并且我知道我可以为 Debian 构建它们(“Linux-4.4.0-x86_64-with-debian-buster-sid”是我运行的最后一个函数) - 但我不知道我下面的平台是否会发生变化
          猜你喜欢
          • 2020-08-21
          • 2017-06-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-03
          • 2015-03-21
          相关资源
          最近更新 更多