Search code examples
google-cloud-platformyamlghostscriptgoogle-cloud-build

Cloud build pytest Can not find Ghostscript library


I'm trying to create a trigger that test a function before deploying it in cloud function. So far I managed to install requirements.txt and execute pytest but I get the following error:

/usr/local/lib/python3.7/site-packages/ghostscript/__init__.py:35: in <module>
    from . import _gsprint as gs
/usr/local/lib/python3.7/site-packages/ghostscript/_gsprint.py:515: in <module>
    raise RuntimeError('Can not find Ghostscript library (libgs)')
E   RuntimeError: Can not find Ghostscript library (libgs)

I have ghostscript in my requirements.txt file :

[...]
ghostscript==0.6
[...]
pytest==6.0.1
pytest-mock==3.3.1

Here is my deploy.yaml

steps:
  - name: 'docker.io/library/python:3.7'
    id: Test
    entrypoint: /bin/sh
    dir: 'My_Project/'
    args:
    - -c
    - 'pip install -r requirements.txt && pytest pytest/test_mainpytest.py -v'

From the traceback, I understand that I don't have ghostscript installed on the cloud build, which is true.

Is there a way to install ghostscript on a step of my deploy.yaml?

Edit-1:

So I tried to install ghostscript using commands in a step, I tried apt-get gs, apt-get ghostscript but unfortunately it didn't work


Solution

  • The real problem is that you are missing a c-library, the package itself seems installed by pip. You should install that library with your package manager. This is an example for ubuntu-based containers:

      - name: 'gcr.io/cloud-builders/gcloud'
        entrypoint: 'bash'
        args:
          - '-c'
          - |
            apt update
            apt install ghostscript -y
            pip install -r requirements.txt
            pytest pytest/test_mainpytest.py -v