Google Cloud Functions(GCF)-使用apt-get安装软件包

时间:2018-08-24 22:27:50

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

我需要2个软件包,我的 Google云功能(GCF)功能才能正常工作。我通常会在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代码中下载软件包?还有其他(更轻松/更轻松)的方法来实现我想要的工作吗?

谢谢!

4 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:2)

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

答案 2 :(得分:0)

答案 3 :(得分:0)

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

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