Before deploying a Flask application, there are a number of things that you must prepare, namely:
To create an application using Flask, first create a folder to store all the python scripts.
mkdir my-flask-app cd my-flask-app
After that, create three files needed by the application, namely: app.py, requirements.txt and awan.yaml
touch app.py requirements.txt awan.yaml
Open the requirements.txt file to register the required packages.
Install the required package using pip:
pip install -r requirements.txt
Flask is a core package for running applications. We will use Gunicorn to run Flask in the production environment.
Next we edit the app.py file
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run(debug=True)
Run the following command to see the output of this application.
FLASK_APP=app.py flask run --port=5002
Please open th url http://localhost:5005 in your browser.
If the application is already running, now we will try to deploy it to Awan. For that we need to prepare information about this application and write it to the awan.yaml file
version: '1.0' web: type: python version: 3 run: gunicorn --log-level debug --access-logfile - -b 0.0.0.0:$PORT app:app
Do a git commit to save the file information that we have created.
git init git add -v . git commit -m "initial commit"
We need to add the Cloud remote repository to our project.
git remote add awan firstname.lastname@example.org:TEAM/APP_NAME.git
Then push this application to Awanio:
git push awan master
Wait a few moments until the deployment is complete, then open the application url in Awanio.