Vaibhav Singh
Vaibhav Singh

Reputation: 1574

How to include system wide in app.yaml in google cloud?

I am deploying flask app which uses cairosvg which is used to convert SVG to PDF. Locally app is running smoothly when I am deploying to GCP, it's not deploying and getting following error:

Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2018-05-22 18:09:41 +0000] [1] [INFO] Starting gunicorn 19.8.1
[2018-05-22 18:09:41 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-05-22 18:09:41 +0000] [1] [INFO] Using worker: sync
[2018-05-22 18:09:41 +0000] [7] [INFO] Booting worker with pid: 7
[2018-05-22 18:09:42 +0000] [7] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/env/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/env/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/home/vmagent/app/run.py", line 4, in <module>
    from api.controllers import (
  File "/home/vmagent/app/api/controllers/generateBadges.py", line 7, in <module>
    from api.utils.merge_badges import MergeBadges
  File "/home/vmagent/app/api/utils/merge_badges.py", line 4, in <module>
    from cairosvg import svg2pdf
  File "/env/lib/python3.6/site-packages/cairosvg/__init__.py", line 29, in <module>
    from . import surface
  File "/env/lib/python3.6/site-packages/cairosvg/surface.py", line 24, in <module>
    import cairocffi as cairo
  File "/env/lib/python3.6/site-packages/cairocffi/__init__.py", line 41, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "/env/lib/python3.6/site-packages/cairocffi/__init__.py", line 38, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2
[2018-05-22 18:09:42 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-05-22 18:09:42 +0000] [1] [INFO] Shutting down: Master
[2018-05-22 18:09:42 +0000] [1] [INFO] Reason: Worker failed to boot.

On searching on google, i found dlopen() failed to load a library: cairo / cairo-2 but I don't know how to include in app.yml.

my app.yml file:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  python_version: 3

env_variables:
    SQLALCHEMY_DATABASE_URI: >-
      postgresql+psycopg2://USER:PASSWORD@/DATABASE?host=/cloudsql/INSTANCE_CONNECTION_NAME

beta_settings:
    cloud_sql_instances: INSTANCE_CONNECTION_NAME

Upvotes: 0

Views: 164

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39834

If the missing dependencies are available as python packages you just need to add those to your app's requirements.txt file, see Using Python Libraries.

But from the answer to the post you referenced those might not be python packages. If so you can still create a custom runtime based on the corresponding google-supplied docker image in which you add the additional non-python dependencies your app require. From About Custom Runtimes:

Custom runtimes allow you to define new runtime environments, which might include additional components like language interpreters or application servers.

See also Building Custom Runtimes.

Upvotes: 1

Related Questions