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

Ast*_*tar 5 firefox python-3.x xvfb google-cloud-platform google-cloud-functions

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

apt-get -y install firefox xvfb
Run Code Online (Sandbox Code Playgroud)

但是,我不知道如何打包我的函数,这会指示 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)
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用。我收到以下错误:

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)
Run Code Online (Sandbox Code Playgroud)

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

谢谢!

Dou*_*son 7

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

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