How do I add WeasyPrint dependencies to Azure App Service app?

614 Views Asked by At

With WeasyPrint, I need to do the following in order to get the required libraries:

sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info

I have added this to my GitHub triggers as it builds:

    - name: Install WeasyPrint dependencies
  run: |
    cd /home
    sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info

And when I view the build logs, it shows that it is successful; however, the Python app will still not start, saying it could not find the required libraries:

OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': libcairo.so.2: cannot open shared 
No such file or directory
cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open 
No such file or directory
cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open 
No such file or directory

I tried to do what another user did (successfully, it seems) and just log in via SSH to install it directly, but when I try to do this, apt-get throws 404 errors, for example:

(antenv) root@13f25a3adfa1:/tmp/8d947bb726491c3# apt-get install libcairo2
Reading package lists... Done
Building dependency tree
[. . .]
Fetched 4156 kB in 0s (4207 kB/s)
E: Failed to fetch http://security.debian.org/debian-security/pool/updates/main/libx/libx11/libx11-data_1.6.4-3+deb9u3_all.deb  404  Not Found
E: Failed to fetch http://security.debian.org/debian-security/pool/updates/main/libx/libx11/libx11-6_1.6.4-3+deb9u3_amd64.deb  404  Not Found
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Does Azure App Service not allow you to do this anymore? I'm at a loss as to what to try next.

EDIT: So I was able to get all of the dependencies to add by SSHing into the machine and running apt-get update first. However, I still run into the issue of my Python app still not being able to run. I see the following errors, even though the libraries installed:

2021-07-19T14:43:06.741297128Z OSError: no library called "cairo" was found
    2021-07-19T14:43:06.741300828Z no library called "libcairo-2" was found
    2021-07-19T14:43:06.741304429Z cannot load library 'libcairo.so.2': libcairo.so.2: cannot open shared object file: No such file or directory
    2021-07-19T14:43:06.741308229Z cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open shared object file: No such file or directory
    2021-07-19T14:43:06.741311929Z cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open shared object file: No such file or directory
2

There are 2 best solutions below

0
LarryX On

https://learn.microsoft.com/en-us/azure/app-service/configure-language-python

App Service's build system, called Oryx, performs the following steps when you deploy your app if the app setting SCM_DO_BUILD_DURING_DEPLOYMENT is set to 1: ....

I believe it can be put in requirements.txt, or PRE_BUILD_COMMAND setting

0
Zack Rothstein On

This was quite a journey to figure out. Here are some references to my Flask app and most importantly, the startup.sh file:

Environment variables

APPSETTING_ScmType = BitbucketGit
FRAMEWORK = PYTHON
FRAMEWORK_VERSION = 3.10
LINUX_OS_VERSION = debian|bullseye

startup.sh file

#!/bin/bash
apt-get install -y libpango-1.0-0 libpangoft2-1.0-0
gunicorn --preload --bind=0.0.0.0 --workers=4 startup:app