如何在google云中的app.yaml中包含系统范围?

时间:2018-05-22 18:51:13

标签: python google-app-engine google-cloud-platform cloud

我正在部署使用cairosvg的flask app,用于将SVG转换为PDF。当我部署到GCP时,本地应用程序运行顺利,它没有部署并出现以下错误:

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.

在Google上搜索时,我找到dlopen() failed to load a library: cairo / cairo-2,但我不知道如何加入app.yml

我的app.yml文件:

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

1 个答案:

答案 0 :(得分:1)

如果缺少的依赖项可用作python包,您只需将它们添加到应用程序的requirements.txt文件中,请参阅Using Python Libraries

但是从帖子的答案你引用的那些可能不是python包。如果是这样,您仍然可以基于相应的谷歌提供的docker镜像创建自定义运行时,在该镜像中添加应用程序所需的其他非python依赖项。来自About Custom Runtimes

  

自定义运行时允许您定义新的运行时环境   可能包括其他组件,如语言解释器或   应用服务器。

另见Building Custom Runtimes