10
Deployment in the Cloud! Tareque Hossain

Django Deployment

Embed Size (px)

DESCRIPTION

A presentation on django project deployment & update strategies. Presented at django-NOVA meetup on April 2nd, 2010

Citation preview

Page 1: Django Deployment

Deployment in the Cloud!

Tareque Hossain

Page 2: Django Deployment

Pony in the Cloud

Page 3: Django Deployment

Deployment Strategy

Cloud computing hosts (in our case Amazon EC2) supports dynamic instantiation of servers, which provides us the opportunity to maximize automation

To utilize the benefit, we automate our deployment 100% Key software packages become part of Amazon Machine Image

(AMI) e.g. MySQL, Apache, mod_wsgi, global Python runtimes, setuptools, search engines, version control systems etc.

All project specific packages are retrieved and installed at the time of deployment

Page 4: Django Deployment

Deployment StrategyContinued

Advantages of deployment time retrieval of project specific packages are: Ability to obtain most up to date package (with bug fixes) Minimize machine image size Use of public package distribution services (more clouds!)

But there are disadvantages: Public package distros don’t have guaranteed uptime Vulnerable to new bugs Security issues

Page 5: Django Deployment

Deployment Tools

At PBS we use the following tools for deployment: fabric, a Python library and command-line tool for

streamlining the use of SSH for application deployment or systems administration tasks

virtualenv, a tool to create isolated Python environments pip, a tool to install Python packages, a replacement of

easy_install git, the version control system we primarily use

Also involves writing some shell script

Page 6: Django Deployment

Deployment Procedure I

Instantiate a new server on the cloud (no details) Apache, MySQL, Python, setuptools & Git installed Check out project from git, and switch to project directory Execute a shell script bootstrap.sh, which we include in the

dist folder of our projects, which does the following: Install virtualenv if not already present Create a virtual environment for the deployment tools (since

different projects might depend on different versions) Install fabric

Page 7: Django Deployment

Shell Bootstrap Code

if [ -e fabfile.py ]; then if ! command -v virtualenv &>/dev/null; then

sudo easy_install virtualenv fi rm -Rf .ve.boot~/ virtualenv .ve.boot~/ .ve.boot~/bin/easy_install -q http://git.fabfile.org/cgit.cgi/fabric/snapshot/fabric-0.9b1.tar.gz .ve.boot~/bin/fab local bootstrap rm -Rf .ve.boot~/else echo "You must run this from your projects root directory."fi

Page 8: Django Deployment

Deployment Procedure II

Fabric looks for fabfile.py in the project root folder fabfile.py contains necessary server profiles & utility functions:

bootstrap, a function that accepts a server profile as argument and sets up the projects virtual environment

deploy, checks for deployment revision, which in our case is git tag, accepts revision number as input & updates the project

bootstrap_on_demand, a function that performs bootstrap only if the project environment is out of date

Page 9: Django Deployment

Fabric Code

Let us look at the fabric code.

Page 10: Django Deployment

Questions?

This presentation is available at: www.codexn.com Sample bootstrap.sh & fabfile.py are available for download