arrow_back Microsoft Azure Infrastructure Services foundation
Continuous deployment with Fabric
Submitted by Akshar Raaj (@akshar-raaj) on Saturday, 3 May 2014
People attending this talk will leave with an understanding of continous deployment and continous deployment tools in general and Fabric in particular.
They will appreciate the usefulness of a continous deployment tool like Fabric. Essentially they will realise the time they save by using a single step build process. By the time they leave, they would have learned how to write a Fabric script which can automate deployment.
Expectation from attendees
- Understands what it means to ssh to a production server.
- Must have deployed a web application to production.
- Basic understanding of Python.
Your time is precious and is best spent writing code. It should not be wasted on a production server doing the repetitive task again and again. And by repetitive task I mean fetching the code changes to server, installing the libraries, restarting the web server, restarting the proxy server and so on.
Code changes continously. And you need to deploy the code to production every day, possibly you want to deploy with every code push. And sshing to the server everytime you want to deploy, and doing the repetitive tasks is a waste of time and energy.
So, deployment of code should be automated. Joel's test has a requirement that build should be a one step process.
Fabric is a command-line tool for streamlining the use of SSH for application deployment (taken from docs).
We will write a basic web application using Python. This application will serve few urls, it will depend on certain third party libraries which are installble from PyPI. We will use gunicorn as the web server and nginx as the reverse proxy.
Everytime we want to deploy we need to do the following:
cdto required directory.
- Fetch the code from the repository and checkout to master. (We will use github)
- Activate the virtual environment.
- Install the requirements i.e the third party libraries on which the application depends.
- Kill existing gunicorn process.
- Start a new gunicorn process.
- Restart nginx.
We will ssh to a server and will deploy the code there. We will perform the steps mentioned above. You will notice the time it takes and pain involved in performing those steps manually. And then we will write a Fabric script which can automate these steps for us, which will be much faster than the previous approach where we manually had to do every step involved in build.
We need a web application for this workshop. We will use Python to write our web application. So, you must know the basics of Python.
Every person attending the workshop would not be aware about the same Python web framework, so we can't use a framework for the web application. Our web application will only use standard Python library. Our web application will be WSGI compliant, and we will use Gunicorn which is WSGI compliant too. Read this to get a basic idea of WSGI.
Gunicorn is a wsgi server. Read about gunicorn here.
You need a deployment server to gain a first hand experience of deployment. I have an ec2 server, and suggest you to have a server too.
Make sure you have port 8000 and 8001 open on your server.
- We will finally make port 8001 non-public. But in the initial stages it might help with debugging.
Have the following things installed on your development machine as well as on deployment server.
Make sure your server public key is added on github, so you would be able to pull from github.
I have created the web application which we will use throughout this workshop. Check it here.