Deployment of Python Applications

Before deploying a python application, there are several things that you must prepare, namely:

  • Awanio account
  • ssh public key that has been registered on the Awanio dashboard page
  • git url endpoint to be used for push code. The format is git@awan.io:TEAM/APP_NAME.git
  • awan.yaml file that is placed in the top application folder

After all this is fulfilled, then you can start making applications based on a starter kit that can be cloned from https://github.com/awanio/python-starter-kit

An example awan.yaml file to use is:

version: '1.0'
web:
  type: python
  version: 3
  run: gunicorn --log-level debug --access-logfile - -b :$PORT --workers=2 my_web:app

In this configuration, the python web application will use gunicorn as a runtime. For that you have to declare gunicorn in the file requirements.txt like the following example:

gunicorn
whitenoise

The whitenoise package is needed together with the gunicorn as middleware to serve static content.

Examples of application files can be seen in my_web.py

As another example, you can also use Twisted as web runtime. An example of the awan.yaml file for this configuration is:

version: '1.0'
web:
  type: python
  version: 3
  run: python3 my_twisted.py

In this case, you must declare twisted in the requirements.txt file

Twisted>=17.9.0rc1

Sometimes our application requires a process worker that runs before or concurrently with a web application, for example in a Django application that requires migration and process_tasks. So the example awan.yaml file is:

version: '1.0'
web:
  type: python
  version: 3
  run: python src/manage.py migrate & python src/manage.py process_tasks & gunicorn --log-level debug --access-logfile - -b 0.0.0.0:$PORT --workers=2

After the application is ready, add git remote Awanio to the project:

git remote add awan git@awan.io:TEAM/APP_NAME.git

After the application is ready, then please commit and push to the Awanio git server

git push awan master