Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Functions (GCF) - installing packages With apt-get

I need 2 packages for my Google Cloud Functions (GCF) functions to work properly. I'd typically install them with the following command on Ubuntu:

apt-get -y install firefox xvfb

However, I don't know anyway to package my functions which would direct GCF to download these packages before running my code.

I tried installing them from within my Python function, using subprocess.call().

Here is some code:

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)

Unfortunately, this does not work. I get the following errors:

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)

How can I fix this error to download the packages from within my python code? Is there any other (easier/cleaner) way to achieve what I'm trying to do?

Thanks!

like image 560
Astar Avatar asked Mar 06 '23 13:03

Astar


2 Answers

You can't arrange for packages to be installed on Cloud Functions instances. This is because your code doesn't run with root privileges. If you need binaries to be available to your code deployed to Cloud Functions, you will have to build it yourself for Debian, and include the binaries in your functions directory so it gets deployed along with the rest of your code.

Even if you're able to do that, there's no guarantee it will work, because the Cloud Fucntions images may not include all the shared libraries required for the executables to work.

like image 125
Doug Stevenson Avatar answered Mar 12 '23 20:03

Doug Stevenson


You can request that new packages be added to the runtime using the public issue tracker. Note that the issue tracker says "App Engine" but just mention that this is for Cloud Functions.

like image 26
stewblr Avatar answered Mar 12 '23 21:03

stewblr