Deploying an application to the cloud of Heroku
Heroku is an application platform, specifically a cloud platform as a service . The advantage of using PaaS is that you can instantly deploy your applications coded in Python, Ruby, Facebook API, Scala, Java, Spring and other languages, regardless of the infrastructure. This will help enterprises to reduce costs and increase agility.
Saving costs, services on demand, scalability and load bursting .. are some of the advantages of using the cloud.
Speaking of infrastructure, Heroku is based on AWS (Amazon Web Services) and it is accessible with Git and Toolbelt.
As an example, as I recently prototyped a Flask based application that I named “Cine’hui” , I’ll be using a web application coded in Python and Debian system commands.
First install python, virtualenv, python-pip, git and gunicorn with apt-get or aptitude, then install heroku toolbelt:
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
You will need also a free account on heroku.
Once the package installed on it and the account is created :
Create the application folder:
mkdir myApp cd myApp
and create a virtual environment that we will call “venv”:
virtualenv venv --distribute
Activate it with:
source venv / bin / activate
Suppose that the file that will run your application (myFile.py) is in the ./myApp folder.
If the application is a web application (Django, Webpy, Flask ..etc) create the Procfile file and add this line to the top of the created file:
Web: gunicorn myApp / myFile: app
Now create your application on heroku with:
heroku create myApp
To ensure the proper functioning of Procfile, type:
The next step is important:
pip freeze> requirements.txt
This will tell pip to generate the list of dependencies (python modules) that you used in your virtual environment “venv”, which will then be used by Heroku.
Now we need to store the application on a Git repository, and for that start by creating “.gitignore” and add the lines:
venv * .pyc
Initialize the git:
Add all your files to the depot, and made a commit followed by a push:
git init git add. git commit -m "init" git push heroku master
To view your application on a browser:
Generally in development/deployment nothing works the first time 🙂
You’ll probably need this:
To open Python CLI, type:
heroku run python
And if you want to start a bash session (you’ll probably need it for debugging or any other purpose), type:
heroku run bash
Well, it was a basic method to deploy a web application coded in Python (Flask, Django or any other python based web development framework) on the Heroku cloud . The principle is almost the same for the other technologies.