簡體   English   中英

如何將從swaggerhub生成的flask swagger服務器部署到heroku?

[英]How to deploy flask swagger server generated from swaggerhub to heroku?

我正在嘗試部署從 swaggerhub 生成的 Flask 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

.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 網絡日志上的錯誤: 在此處輸入圖片說明

我自己找到了解決方案,將文件的主要內容更改如下:

#!/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() 函數並在沒有函數方法的情況下編寫了內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM