Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django Deployments Done Right

Django Deployments Done Right

Deployment is the process of getting code from your laptop to a production-level server. What makes a "good" deployment? This talk will give you a tooling-agnostic look at the steps that you should be taking during deployment and show you how to overcome some common pitfalls in the process.

Peter Baumgartner

September 08, 2015
Tweet

More Decks by Peter Baumgartner

Other Decks in Technology

Transcript

  1. What is a deployment? • Noun: The way your servers

    and software are setup • Verb: The techniques used to install and update your software on 
 the servers
  2. Good Deployments • Ship faster • new features • bug

    fixes • failure recovery • Happy Humans • more productive • less turnover
  3. Configuration Management • Use Salt or Ansible 
 (unless other

    in-house experience) • Fabric is not a configuration management tool • Use it for everything
 (setup, updates, deploys, etc.)
  4. Pin Dependencies • Install exact versions PyPI, e.g. Django==1.8.4 •

    Consider setup.py and install_requires over requirements.txt • Can’t use PyPI? • Setup your own (pip2pi + Nginx or S3) • Vendor • Use a repo that you own
  5. Reload, Don’t Restart • Don’t drop requests during a deploy

    • service {nginx,varnish} reload • Gracefully reload WSGI servers
 (gunicorn, uWSGI, etc.) • Works out-of-the-box with Upstart • systemd?
 ExecReload=/bin/kill -HUP $MAINPID
  6. Isolate Each Build • New build/release = New virtualenv •

    Broken builds don't take down the site • No cruft from previous builds • Fast painless rollbacks
  7. Isolate Each Build • Multiple servers?
 Build once, deploy everywhere

    1. Build wheels 2. Bundle 3. Ship • See platter.pocoo.org
  8. Database Migrations • Maintain backwards compatibility
 (for a few releases)

    • Big database and lots of traffic? • Avoid long table locks • See bit.ly/db-mg
  9. Track Releases • Store commit hash and timestamp • Invaluable

    for regression tracking • NewRelic, Opbeat, Slack, etc.
  10. Always Be Improving • Remember to think of the humans!

    • Can failures be avoided? • Can you make it faster? • Can you make it easier?