SlideShare a Scribd company logo
1 of 13
Django Deployment
  {   Tips, Tricks and Best Practices
   You mission, should you choose to accept it:
           Make your application run with 1 click,
            everywhere it counts, every time.
           Make your application run exactly the same way,
            everywhere it counts, every time.
           Prove that the above are true.




Reproducibility
   Reproducible Infrastructure
       Reproducible Systems
       Reproducible [Django] Applications
           Dependencies
           Configuration
           Data
           Deployment




Steps to Reproducibility
   Systems: Virtual or Physical
            Power Management
            Console
            Backup / Restore
        Network Layer
            Load Balancing
            Security
            Performance




Infrastructure
   A Stable Foundation
           Stable Operating System
           Reproducible Installation
                Kickstart Install
                Base Image
       Configuration Management
           Puppet, Chef
       Packaging




Systems
   What Python?
           How will you install packages?
           How will you make it reproducible?
       Database?
           Backup / Restore
           Failover
           Performance
       Caching?
           HTTP
           Objects
       Queuing?
       SSL?




Application Environment
   It’s just code, right?
            Probably Not




Application
   Just use pip!          lib/pypi-cache:
                           Django-1.4.3.tar.gz
   Not so fast.
       Lots of external   requirements.txt:
        dependencies       Django==1.4.3
       Eliminate them
        with a local       Type this:
                           pip install --no-index --find-links
        cache
                           file://$(PWD)/lib/pypi-cache -r
   Don’t’ forget          requirements.txt
    virtualenv!




     Dependencies
   settings.py              settings.py:
        No logic allowed!   from urlparse import urljoin
        ‚unknown‛           from os import environ
         import times        import dj_database_url #courtesy of Heroku
        Critical
   Local_settings.py        DATABASES =
        More of the same    dj_database.config(default=‚xxx‛)
                             BASE_URL = environ*‘DJANGO_BASE_URL’+
   Consider pushing         STATIC_URL = urljoin(BASE_URL, ‘static’)
    configuration in         MEDIA_URL = urljoin(BASE_URL, ‘media’)
    externally via
    environ,                 Run this:
    configparser, etc        DJANGO_BASE_URL=http://cdn.com/base/
                             django-admin.py runserver



Configuration
   Fixtures. Consider      fixtures/polls.py:
    writing them in         from ..models import Poll, Choice
                            def apply():
    Python!                   p = Poll.objects.get_or_create(q=‘test q’,
       Testable                defaults=dict(pub_date=‘1980-01-01))
                              c1 = Choices.objects.get_or_create(poll=p,
       More resilient to
                                choice_text=‘option 1’)
        change
       Less pk pain        fixtures/tests/test_poll.py:
                            Class PollFixtureTestCase(TestCase):
                              def test_fixture_applied():
   Migrations!                 self.assertEquals(Poll.objects.get(q=‘test q’)
       Test them




        Application: Database
management/__init__.py:
from django.db.models.signals import post_syncdb
from south.signals import post_migrate
from .. import models, fixtures

def update_poll_fixtures(verbose=True):
    fixtures.poll.apply()
    if verbose:
        print "Updating dynamic fixtures for profile”

def update_fixtures_post_syncdb(sender, **kwargs):
  update_poll_fixtures()

def update_fixtures_post_migrate(app, **kwargs):
if app == ’polls':
  update_poll_fixtures()

post_syncdb.connect(fixtures_post_syncdb, sender=models)
post_migrate.connect(fixtures_post_migrate)
Interwebs
   Back Up Everything!
   Move files to Green
       Fabric?
       RPM?
       Tar?
       Git?
       Rsync?
                           App               App   Deploy / Test
   Update Stuff
       syncdb
       apply fixtures
   Test Green!
   Flip/Flop Blue/Green           Data
   (Roll back to Blue)


     Deployment: Blue/Green
Erik LaBianca, WiserTogether, Inc.
    erik.labianca@gmail.com
    @easel
    https://linkedin.com/in/eriklabianca/
    https://slideshare.net/easel1/
    https://github.com/easel/
    https://github.com/WiserTogether/




Questions?

More Related Content

What's hot

Test Driven Development with Puppet - PuppetConf 2014
Test Driven Development with Puppet - PuppetConf 2014Test Driven Development with Puppet - PuppetConf 2014
Test Driven Development with Puppet - PuppetConf 2014Puppet
 
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014Puppet
 
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...Puppet
 
Portland PUG April 2014: Beaker 101: Acceptance Test Everything
Portland PUG April 2014: Beaker 101: Acceptance Test EverythingPortland PUG April 2014: Beaker 101: Acceptance Test Everything
Portland PUG April 2014: Beaker 101: Acceptance Test EverythingPuppet
 
Puppet for SysAdmins
Puppet for SysAdminsPuppet for SysAdmins
Puppet for SysAdminsPuppet
 
Puppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionJoshua Thijssen
 
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...Puppet
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Puppet
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Puppet
 
Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Ivan Rossi
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REXSaewoong Lee
 
Test Driven Development with Puppet
Test Driven Development with Puppet Test Driven Development with Puppet
Test Driven Development with Puppet Puppet
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer ToolboxPablo Godel
 
10 Million hits a day with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day with WordPress using a $15 VPSPaolo Tonin
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartHenry Stamerjohann
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點William Yeh
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeDamien Seguin
 
Design Summit - Migrating to Ruby 2 - Joe Rafaniello
Design Summit - Migrating to Ruby 2 - Joe RafanielloDesign Summit - Migrating to Ruby 2 - Joe Rafaniello
Design Summit - Migrating to Ruby 2 - Joe RafanielloManageIQ
 

What's hot (20)

Test Driven Development with Puppet - PuppetConf 2014
Test Driven Development with Puppet - PuppetConf 2014Test Driven Development with Puppet - PuppetConf 2014
Test Driven Development with Puppet - PuppetConf 2014
 
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
 
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
Building and Testing from Scratch a Puppet Environment with Docker - PuppetCo...
 
Portland PUG April 2014: Beaker 101: Acceptance Test Everything
Portland PUG April 2014: Beaker 101: Acceptance Test EverythingPortland PUG April 2014: Beaker 101: Acceptance Test Everything
Portland PUG April 2014: Beaker 101: Acceptance Test Everything
 
Puppet for SysAdmins
Puppet for SysAdminsPuppet for SysAdmins
Puppet for SysAdmins
 
Puppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 Edition
 
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
Workshop: Know Before You Push 'Go': Using the Beaker Acceptance Test Framewo...
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
 
Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
Test Driven Development with Puppet
Test Driven Development with Puppet Test Driven Development with Puppet
Test Driven Development with Puppet
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
 
10 Million hits a day with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day with WordPress using a $15 VPS
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / Quickstart
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the like
 
Afl - 4fun and pr0fit
Afl - 4fun and pr0fitAfl - 4fun and pr0fit
Afl - 4fun and pr0fit
 
Design Summit - Migrating to Ruby 2 - Joe Rafaniello
Design Summit - Migrating to Ruby 2 - Joe RafanielloDesign Summit - Migrating to Ruby 2 - Joe Rafaniello
Design Summit - Migrating to Ruby 2 - Joe Rafaniello
 

Viewers also liked

12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Flask and Paramiko for Python VA
Flask and Paramiko for Python VAFlask and Paramiko for Python VA
Flask and Paramiko for Python VAEnrique Valenzuela
 
Django rest framework in 20 minuten
Django rest framework in 20 minutenDjango rest framework in 20 minuten
Django rest framework in 20 minutenAndi Albrecht
 
Do more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python wayDo more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python wayJaime Buelta
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesSpin Lai
 
Pythonic Deployment with Fabric 0.9
Pythonic Deployment with Fabric 0.9Pythonic Deployment with Fabric 0.9
Pythonic Deployment with Fabric 0.9Corey Oordt
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
Building a platform with Django, Docker, and Salt
Building a platform with Django, Docker, and SaltBuilding a platform with Django, Docker, and Salt
Building a platform with Django, Docker, and Saltbaremetal
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoTareque Hossain
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSHHemant Shah
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in DjangoMichael Auritt
 

Viewers also liked (16)

12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Flask and Paramiko for Python VA
Flask and Paramiko for Python VAFlask and Paramiko for Python VA
Flask and Paramiko for Python VA
 
Django rest framework in 20 minuten
Django rest framework in 20 minutenDjango rest framework in 20 minuten
Django rest framework in 20 minuten
 
Ansible on AWS
Ansible on AWSAnsible on AWS
Ansible on AWS
 
Do more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python wayDo more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python way
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best Practices
 
Pythonic Deployment with Fabric 0.9
Pythonic Deployment with Fabric 0.9Pythonic Deployment with Fabric 0.9
Pythonic Deployment with Fabric 0.9
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
Building a platform with Django, Docker, and Salt
Building a platform with Django, Docker, and SaltBuilding a platform with Django, Docker, and Salt
Building a platform with Django, Docker, and Salt
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with django
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
Scaling Django
Scaling DjangoScaling Django
Scaling Django
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSH
 
Django Best Practices
Django Best PracticesDjango Best Practices
Django Best Practices
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 

Similar to Django deployment best practices

Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suiteericholscher
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in pythonAndrés J. Díaz
 
Tiny Puppet Can Install Everything. Prove me wrong!
Tiny Puppet Can Install Everything. Prove me wrong!Tiny Puppet Can Install Everything. Prove me wrong!
Tiny Puppet Can Install Everything. Prove me wrong!Alessandro Franceschi
 
Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]Devon Bernard
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Deepak Garg
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytestHector Canto
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaSAppsembler
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceQuinlan Jung
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvMarkus Zapke-Gründemann
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentMark Niebergall
 
Django on Jython, PyCon 2009
Django on Jython, PyCon 2009Django on Jython, PyCon 2009
Django on Jython, PyCon 2009Leonardo Soto
 
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...Amazon Web Services
 

Similar to Django deployment best practices (20)

Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
Tiny Puppet Can Install Everything. Prove me wrong!
Tiny Puppet Can Install Everything. Prove me wrong!Tiny Puppet Can Install Everything. Prove me wrong!
Tiny Puppet Can Install Everything. Prove me wrong!
 
Django
DjangoDjango
Django
 
Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaS
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Defensive Apex Programming
Defensive Apex ProgrammingDefensive Apex Programming
Defensive Apex Programming
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update Service
 
Heroku pycon
Heroku pyconHeroku pycon
Heroku pycon
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 
Django on Jython, PyCon 2009
Django on Jython, PyCon 2009Django on Jython, PyCon 2009
Django on Jython, PyCon 2009
 
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:In...
 

Django deployment best practices

  • 1. Django Deployment { Tips, Tricks and Best Practices
  • 2. You mission, should you choose to accept it:  Make your application run with 1 click, everywhere it counts, every time.  Make your application run exactly the same way, everywhere it counts, every time.  Prove that the above are true. Reproducibility
  • 3. Reproducible Infrastructure  Reproducible Systems  Reproducible [Django] Applications  Dependencies  Configuration  Data  Deployment Steps to Reproducibility
  • 4. Systems: Virtual or Physical  Power Management  Console  Backup / Restore  Network Layer  Load Balancing  Security  Performance Infrastructure
  • 5. A Stable Foundation  Stable Operating System  Reproducible Installation  Kickstart Install  Base Image  Configuration Management  Puppet, Chef  Packaging Systems
  • 6. What Python?  How will you install packages?  How will you make it reproducible?  Database?  Backup / Restore  Failover  Performance  Caching?  HTTP  Objects  Queuing?  SSL? Application Environment
  • 7. It’s just code, right?  Probably Not Application
  • 8. Just use pip! lib/pypi-cache: Django-1.4.3.tar.gz  Not so fast.  Lots of external requirements.txt: dependencies Django==1.4.3  Eliminate them with a local Type this: pip install --no-index --find-links cache file://$(PWD)/lib/pypi-cache -r  Don’t’ forget requirements.txt virtualenv! Dependencies
  • 9. settings.py settings.py:  No logic allowed! from urlparse import urljoin  ‚unknown‛ from os import environ import times import dj_database_url #courtesy of Heroku  Critical  Local_settings.py DATABASES =  More of the same dj_database.config(default=‚xxx‛) BASE_URL = environ*‘DJANGO_BASE_URL’+  Consider pushing STATIC_URL = urljoin(BASE_URL, ‘static’) configuration in MEDIA_URL = urljoin(BASE_URL, ‘media’) externally via environ, Run this: configparser, etc DJANGO_BASE_URL=http://cdn.com/base/ django-admin.py runserver Configuration
  • 10. Fixtures. Consider fixtures/polls.py: writing them in from ..models import Poll, Choice def apply(): Python! p = Poll.objects.get_or_create(q=‘test q’,  Testable defaults=dict(pub_date=‘1980-01-01)) c1 = Choices.objects.get_or_create(poll=p,  More resilient to choice_text=‘option 1’) change  Less pk pain fixtures/tests/test_poll.py: Class PollFixtureTestCase(TestCase): def test_fixture_applied():  Migrations! self.assertEquals(Poll.objects.get(q=‘test q’)  Test them Application: Database
  • 11. management/__init__.py: from django.db.models.signals import post_syncdb from south.signals import post_migrate from .. import models, fixtures def update_poll_fixtures(verbose=True): fixtures.poll.apply() if verbose: print "Updating dynamic fixtures for profile” def update_fixtures_post_syncdb(sender, **kwargs): update_poll_fixtures() def update_fixtures_post_migrate(app, **kwargs): if app == ’polls': update_poll_fixtures() post_syncdb.connect(fixtures_post_syncdb, sender=models) post_migrate.connect(fixtures_post_migrate)
  • 12. Interwebs  Back Up Everything!  Move files to Green  Fabric?  RPM?  Tar?  Git?  Rsync? App App Deploy / Test  Update Stuff  syncdb  apply fixtures  Test Green!  Flip/Flop Blue/Green Data  (Roll back to Blue) Deployment: Blue/Green
  • 13. Erik LaBianca, WiserTogether, Inc. erik.labianca@gmail.com @easel https://linkedin.com/in/eriklabianca/ https://slideshare.net/easel1/ https://github.com/easel/ https://github.com/WiserTogether/ Questions?

Editor's Notes

  1. ----- Meeting Notes (2/12/13 12:10) -----json fixtures: primary key problems, skips model.save, fixtures get of date when model changes