问题描述
我正在尝试部署从 swaggerhub 生成的烧瓶 swagger 服务器,下面是我的文件夹结构和我使用的 procfile.有谁知道在heroku中部署这个flask swagger服务器的方法吗?
I am trying to deploy the flask swagger server generated from swaggerhub, below is my folder structure and procfile i use. Does any one knows the way to deploy this flask swagger server in heroku?
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 中的内容:
content in Procfile:
web: gunicorn app:swagger_server
runtime.txt 中的内容:
content in runtime.txt:
python-3.7.8
Requirements.txt 中的内容:
content in Requirments.txt:
connexion == 2.6.0
python_dateutil == 2.6.0
setuptools >= 21.0.0
gunicorn==20.0.0
main.py 文件中的内容:
content in main.py file:
#!/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 日志错误:
Error on the heroku log :
heroku 网络日志上的错误:
Error on the heroku web log:
推荐答案
我自己找到了解决方案,你也可以用它来部署在appengine中,将文件的主要内容更改如下:
I found the solution myself which you can use it to deploy in appengine too, change the main content of the file as below :
#!/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 中的内容:
content in the Procfile:
web: gunicorn swagger_server.__main__:app
requirements.txt 中的内容:
content in requirements.txt :
connexion == 2.6.0
python_dateutil == 2.6.0
setuptools >= 21.0.0
gunicorn
此解决方案适用于在 heroku 中部署,我删除了 main() 函数并编写了没有函数方法的内容.
this solution works for deploying in heroku, I removed the main() function and written contents without a function approach.
这篇关于如何将swaggerhub生成的flask swagger服务器部署到heroku?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!