1

I have a Django app that uses Weasyprint to generate PDF outputs. This works fine on my local development machine.

I am able to successfully deploy to Azure Web Apps, but get the following error message:

2020-11-17T07:34:14.287002623Z OSError: no library called "cairo" was found
2020-11-17T07:34:14.287006223Z no library called "libcairo-2" was found
2020-11-17T07:34:14.287009823Z cannot load library 'libcairo.so.2': libcairo.so.2: cannot open shared 
object file: No such file or directory
2020-11-17T07:34:14.287016323Z cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open 
shared object file: No such file or directory
2020-11-17T07:34:14.287020123Z cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open 
shared object file: No such file or directory

Per Weasyprint's documentation (https://weasyprint.readthedocs.io/en/stable/install.html#debian-ubuntu), I have attempted to make the reccommended installations via a custom deployment script which looks like such:

jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ env.PYTHON_VERSION }}
  uses: actions/setup-python@v2
  with:
    python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
  run: |
    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
    python -m pip install --upgrade pip
    pip install -r requirements.txt

- name: Deploy Web App using GH Action azure/webapps-deploy
  uses: azure/webapps-deploy@v2
  with:
    app-name: ${{ env.AZURE_WEBAPP_NAME }}
    publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
    package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

However, my problem persists and I still receive the same message.

Does anybody have experience installing Weasyprint & Cairo on a Linux-based Web App?

I appreciate any help in advance.

UPDATE

Currently, I am able to deploy using the default deployment script created by Azure (shown below). I am then able to SSH into the deployment machine and manually activate the virtual environment & install the requisite packages. This process works and my application now works as expected.

I'd like to roll this command into the deployment process somehow (either as part of the default script or via a post deployment action).

GITHUB ACTIONS DEPLOYMENT SCRIPT

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master

- name: Set up Python version
  uses: actions/setup-python@v1
  with:
    python-version: '3.6'

- name: Build using AppService-Build
  uses: azure/appservice-build@v2
  with:
    platform: python
    platform-version: '3.6'

- name: 'Deploy to Azure Web App'
  uses: azure/webapps-deploy@v2
  with:
    app-name: {{appname}}
    slot-name: {{slotname}}
    publish-profile: {{profilename}}

MANUAL VIRTUAL ENV ACTIVATION & INSTALLS

source /home/site/wwwroot/pythonenv3.6/bin/activate
sudo apt-get install {{ additional packages }}
George Rodman
  • 289
  • 7
  • 19
  • Hard to say, I'll hazard the guess that your local machine has a GUI, and your server in azure most likely won't have one; therefore it will be missing `cairo` and possibly a few other libraries and their development counterparts ... which version of Linux are you running, both on your dev box and in your azure instance? – tink Nov 17 '20 at 20:18
  • So I actually just was able to resolve this manually by SSH into the deployment machine and manually activating the virtual environment and installing the reccommended packages from Weasyprint's documentation. However, I have to re-do this every time I deploy a new version. Is there a way to include the installation of these dependencies in the deployment script? – George Rodman Nov 17 '20 at 21:20
  • Can you share your demo code without any confidential information and business. So we can try to solve it and help you. – Jason Pan Nov 18 '20 at 01:19
  • Thanks Jason. I added the code that currently works and results in a working application. However, it's a 2 step process that I'd like to streamline. – George Rodman Nov 18 '20 at 03:04
  • I have replied to all three of your posts. I have tried every method that needs to be used for you. You can try to execute it yourself, it should be useful to you, if it does not work, raise a support ticket for official help. – Jason Pan Nov 20 '20 at 09:43

1 Answers1

0

The required dependencies and the things you want to install can be successfully added to the .yml file, but whether it takes effect for your webapp, you still need to test, and specific problems need to be analyzed in detail.

If that doesn't work, it is recommended to install ssh manually.

I add linux command in .yml file to apt-get install xxx.

enter image description here

For more details,

enter image description here

enter image description here

Below is my .yml file. It works fine.

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Python app to Azure Web App - pyodbcInstallENV

on:
  push:
    branches:
      - master

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master

    - name: Set up Python version
      uses: actions/setup-python@v1
      with:
        python-version: '3.8'
    - name: Install custom env
      run: |
        cd /home
        sudo apt-get update
        sudo apt-get install g++
        sudo apt-get install unixodbc-dev
        pip install pyodbc 
    - name: Build using AppService-Build
      uses: azure/appservice-build@v2
      with:
        platform: python
        platform-version: '3.8'

    - name: 'Deploy to Azure Web App'
      uses: azure/webapps-deploy@v2
      with:
        app-name: 'pyodbcInstallENV'
        slot-name: 'production'
        publish-profile: ${{ secrets.AzureAppService_PublishProfile_d712769***2017c9521 }}
Jason Pan
  • 15,263
  • 1
  • 14
  • 29