Reputation: 475
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
content in Procfile:
web: gunicorn app:swagger_server
content in runtime.txt:
python-3.7.8
content in Requirments.txt:
connexion == 2.6.0
python_dateutil == 2.6.0
setuptools >= 21.0.0
gunicorn==20.0.0
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()
Upvotes: 2
Views: 774
Reputation: 475
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()
content in the Procfile:
web: gunicorn swagger_server.__main__:app
content in requirements.txt :
connexion == 2.6.0
python_dateutil == 2.6.0
setuptools >= 21.0.0
gunicorn
this solution works for deploying in heroku, I removed the main() function and written contents without a function approach.
Upvotes: 3