【问题标题】:How to deploy flask swagger server generated from swaggerhub to heroku?如何将swaggerhub生成的flask swagger服务器部署到heroku?
【发布时间】:2021-07-18 12:01:34
【问题描述】:

我正在尝试部署从 swaggerhub 生成的烧瓶 swagger 服务器,下面是我的文件夹结构和我使用的 procfile。有谁知道在heroku中部署这个flask swagger服务器的方法吗?

project
│   swagger-codegen    
│
└───swagger_server
│      │___controllers
|      |___models
│      │___swagger
|      |___test
│       __init__.py
|       __main__.py 
│       encoder.py
|       util.py
|  
│   
|_   .dockerignore
|_    .gitignore
|_    dockerfile
|_    gitpush.sh
|_    Procfile
|_    requirements.txt
|_    runtime.txt
|_    setup.py


Procfile 中的内容:

web: gunicorn app:swagger_server

runtime.txt 中的内容:

python-3.7.8

Requirements.txt 中的内容:

connexion == 2.6.0
python_dateutil == 2.6.0
setuptools >= 21.0.0
gunicorn==20.0.0

ma​​in.py 文件中的内容:

#!/usr/bin/env python3

import connexion
import os

from swagger_server import encoder


def main():
    app = connexion.App(__name__, specification_dir='./swagger/')
    app.app.json_encoder = encoder.JSONEncoder
    app.add_api('swagger.yaml', arguments={'title': 'end point'}, pythonic_params=True)
    port = int(os.environ.get("PORT", 5000))
    app.run(host = '0.0.0.0', port=port )


if __name__ == '__main__':
    main()

heroku 日志错误:

heroku 网络日志上的错误:

【问题讨论】:

  • 不确定这是否是问题所在,但您在端点后的参数字典中的主函数中有一个不匹配的 ':arguments={'title': end point'}
  • @YoavBenHaim 抱歉,输入问题时打错字
  • 我认为应该是Procfile中的main:swagger_server
  • @charchit 试过了,又报错
  • 你看过任何教程吗,这里有一篇同样的文章medium.com/@kar9475/…

标签: python flask heroku swagger swagger-codegen


【解决方案1】:

我自己找到了解决方案,你也可以用它来部署在 appengine 中,将文件的主要内容更改如下:

#!/usr/bin/env python3
import connexion
from swagger_server import encoder

app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'Docuware end point'}, pythonic_params=True)

if __name__ == '__main__':
    app.run()

Procfile 中的内容:

web: gunicorn swagger_server.__main__:app

requirements.txt 中的内容:

connexion == 2.6.0
python_dateutil == 2.6.0
setuptools >= 21.0.0
gunicorn

此解决方案适用于在 heroku 中部署,我删除了 main() 函数并编写了没有函数方法的内容。

【讨论】:

  • 这帮助我将其部署到应用引擎。谢谢!
  • @intotecho 感谢分享这个有用的信息,我将添加一些标签来指定它也适用于应用引擎:)
猜你喜欢
  • 2021-08-24
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多