【问题标题】:python flask-restful deployment in google cloud engine谷歌云引擎中的python flask-restful部署
【发布时间】:2018-10-29 20:32:07
【问题描述】:

我第一次将 Python 应用程序部署到 GAE 中,它使用 Flask-restful 作为 REST 服务器,我无法理解如何正确配置部署。

我正在尝试使用最小的 flask-restful 应用程序示例 minimal.py

from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

我已经通过以下方式配置了部署app.yaml 文件,其中网络部分试图授予对flask-restful 的默认5000 端口的访问权限:

runtime: python
env: flex
entrypoint: python minimal.py

runtime_config:
  python_version: 3

network:
  instance_tag: instance-1
  name: default
  forwarded_ports:
    - 5000

名称 default 是我的 VPC 中配置的唯一网络。

部署说明如下,为了去掉我之前做的试验:

gcloud app deploy --promote --stop-previous-version

所以,当我尝试使用 curl 发布时,我收到 502 错误,我也可以在我的服务器中看到。

我在某处遗漏了一步......可能在 VPC 网络或 app.yaml 配置中,但我现在迷路了......

任何帮助将不胜感激:)

【问题讨论】:

    标签: google-app-engine flask flask-restful


    【解决方案1】:

    尝试更新yaml 的配置。

    runtime: python
    env: flex
    entrypoint: gunicorn -b :$PORT minimal:app
    
    runtime_config:
      python_version: 3
    
    manual_scaling:
      instances: 1
    resources:
      cpu: 1
      memory_gb: 0.5
      disk_size_gb: 10
    

    参考:https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml

    【讨论】:

    • 谢谢,它成功了。虽然我必须弄清楚 gunicorn 必须每年添加到 requirements.txt 文件中才能使其工作。当然,普通的pip freeze > requirements.txt 是不够的。
    猜你喜欢
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 2021-07-30
    • 2018-12-19
    • 1970-01-01
    • 2018-06-20
    相关资源
    最近更新 更多