Django Deployment

4,239 views
4,030 views

Published on

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

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,239
On SlideShare
0
From Embeds
0
Number of Embeds
557
Actions
Shares
0
Downloads
50
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Django Deployment

  1. 1. Deployment in the Cloud! Tareque Hossain
  2. 2. Pony in the Cloud
  3. 3. Deployment Strategy <ul><li>Cloud computing hosts (in our case Amazon EC2) supports dynamic instantiation of servers, which provides us the opportunity to maximize automation </li></ul><ul><li>To utilize the benefit, we automate our deployment 100% </li></ul><ul><li>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. </li></ul><ul><li>All project specific packages are retrieved and installed at the time of deployment </li></ul>
  4. 4. Deployment Strategy Continued <ul><li>Advantages of deployment time retrieval of project specific packages are: </li></ul><ul><ul><li>Ability to obtain most up to date package (with bug fixes) </li></ul></ul><ul><ul><li>Minimize machine image size </li></ul></ul><ul><ul><li>Use of public package distribution services (more clouds!) </li></ul></ul><ul><li>But there are disadvantages: </li></ul><ul><ul><li>Public package distros don’t have guaranteed uptime </li></ul></ul><ul><ul><li>Vulnerable to new bugs </li></ul></ul><ul><ul><li>Security issues </li></ul></ul>
  5. 5. Deployment Tools <ul><li>At PBS we use the following tools for deployment: </li></ul><ul><ul><li>fabric, a Python library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks </li></ul></ul><ul><ul><li>virtualenv, a tool to create isolated Python environments </li></ul></ul><ul><ul><li>pip, a tool to install Python packages, a replacement of easy_install </li></ul></ul><ul><ul><li>git, the version control system we primarily use </li></ul></ul><ul><li>Also involves writing some shell script </li></ul>
  6. 6. Deployment Procedure I <ul><li>Instantiate a new server on the cloud (no details) </li></ul><ul><li>Apache, MySQL, Python, setuptools & Git installed </li></ul><ul><li>Check out project from git, and switch to project directory </li></ul><ul><li>Execute a shell script bootstrap.sh , which we include in the dist folder of our projects, which does the following: </li></ul><ul><ul><li>Install virtualenv if not already present </li></ul></ul><ul><ul><li>Create a virtual environment for the deployment tools (since different projects might depend on different versions) </li></ul></ul><ul><ul><li>Install fabric </li></ul></ul>
  7. 7. 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 &quot;You must run this from your projects root directory.&quot; fi
  8. 8. Deployment Procedure II <ul><li>Fabric looks for fabfile.py in the project root folder </li></ul><ul><li>fabfile.py contains necessary server profiles & utility functions: </li></ul><ul><ul><li>bootstrap, a function that accepts a server profile as argument and sets up the projects virtual environment </li></ul></ul><ul><ul><li>deploy, checks for deployment revision, which in our case is git tag, accepts revision number as input & updates the project </li></ul></ul><ul><ul><li>bootstrap_on_demand, a function that performs bootstrap only if the project environment is out of date </li></ul></ul>
  9. 9. Fabric Code <ul><li>Let us look at the fabric code. </li></ul>
  10. 10. Questions? <ul><li>This presentation is available at: www.codexn.com </li></ul><ul><li>Sample bootstrap.sh & fabfile.py are available for download </li></ul>

×