SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Jonas Nockert
                                                            jonasnockert@gmail.com
                                                                         @lemonad




Fabric
Django deployment
Stockholm Django User Group, November 9, 2009




http://jonasnockert.com/2009/11/fabric-django-deployment/



                                                                         Photo credit
Great! Your Django app is done!
Now all you have to do is...

• fix bugs and implement new    • keep track of local_settings
   features
                               • reload wsgi files
• git archive
                               • Change symbolic links (yay,
• move files from development      deployed!)
   to staging and production
   servers                     • empty and pre-warm cache
• install updates to django,   • oops! forgot to migrate data!
   reusable apps, pypi
   packages, etc.

• run backups
                                                 (for the rest of your life)
Wouldn’t it be nice if all you had to
            do was this?


     $ fab staging deploy

     $ fab production deploy (yay, backup’d
     and deployed!)
Fabric is easy!




                  Photo credit
Basic building blocks (the core API)

• run — run a command on a remote host.
• sudo — run a sudoed command on a remote host.
• local — run a command on the local host.
• get/put — copy a file from/to a remote host.
• prompt — ask the user for information

• For everything else there’s Python.
Execute commands

• Get output and return code:
   output = run(“command”)

• Chain commands:
   run(“workon project && git pull origin master”)

• start pseudo-daemons:
   run(“screen -d -m not-a-daemon”)




• Any return code except 0 is treated as an error and an exception is
   thrown (unless warn_only is set)
Move files

• Put a file (upload):
   put(“local-file”, “remote-file”, mode=0755)

• Get a file (download):
   get(“remote-file”, “local-file”)




• If a problem occurs while uploading or downloading files, fabric
   throws an exception.
Ask questions

• Validation:
    relase_name = prompt(“What do you want to “
                         “name the new release?: ”,
                         validate=”^[a-zA-Z0-9]+$”)

    proxy_port_number = prompt(“Proxy port: “,
                               validate=int)
•   Default:

    username = prompt(“Username: “,
                      default=”jonas”)
Keeping state (sort of)

• Directories:
   with cd(“xmpp/”):
       run(“git clone git://git/something.git”)
       run(“mkvirtualenv --no-site-packages something“)

• For those running from trunk:
   with prefix(“workon something”):
       run(“pip install Django>=1.1”)

   Observe that the name is not set in stone yet.
   c.f. http://stackoverflow.com/questions/1180411/activate-a-virtualenv-via-fabric-as-deploy-user
Contrib

• Contrib is a collection of useful tools. Search and replace in remote
   files amongst other things.

• However, it is not as evolved as the Fabric core API and contains, in
   Jeff Forcier’s own words, “approaches that work for Jeff on two
   different Linux distros and that’s about it.”
Append text to files

• Appends text unless it already exist in file as a discrete line:
   from fabric.contrib.files import append
       append(“DATABASE_NAME = 'hello.db'”,
              “local_settings.py”)
Search and replace

• Use fabric’s sed function to modify content of files:
   from fabric.contrib.files import sed
       sed(“local_settings.py”,
           “^DEBUG = True$”,
           “DEBUG = False”)
Example

from fabric.api import run

def install_django():
    run('workon myproject && pip install django')



$ fab -H localhost,djangodev install_django




This will install Django within the myproject virtualenv on both the local
machine and on the host djangodev
While Fabric is easy,
deployment is hard!
      (but rewarding)




                        Photo credit
Rebuilding from scratch?

• Define scratch                      Depends to some degree on
                                     what you want to achieve
   Do you start from a given         and if it’s limited to
   virtual machine image?            deployment purposes.

   ...or just your application and   Perhaps you just want to be
   its dependencies?                 able to easily test against a
                                     new release of Ubuntu,
   ...or just your application?      perhaps a new release of
                                     Django.
What about the database?

• Do you migrate the current      • Apply migrations to a copy?
   one?
                                     When you’ve deployed, the
   You could backup and              copy becomes the new
   restore if something goes         production DB.
   wrong.
                                     Make sure you have a way
   But you can’t reliably keep       of finding out the name of
   the site up while migrating.      your current production DB
                                     (in order to deploy the next
                                     time).

                                     Database-level permissions
                                     might need to be handled.
Testing?

• Cancel and revert deployment if the test suite fails!
• This is actually pretty simple:
   run(“workon project && python manage.py test”)

   Django returns the number of failed tests or 0 if all tests pass, and
   run throws an exception if the return code is anything but 0.

   All you have to worry about is reverting to the state before
   deployment started.
What about the live site?

• Show an update banner on        • Set database layer to read-
    the site?                        only?


•   Set Django application to        Have you designed your
                                     application to handle SQL
    read-only?
                                     errors nicely?
    Have you separated code
    that reads from the DB from   • Shut down Apache? What if
    code that writes?                you have multiple
                                     applications?


                                  • You’ll probably need to work
                                     on a separate DB while
                                     updating and migrating,
                                     right?
Trying to combine it all

1. Get source code
2. Create virtualenv
3. Use buildout to install dependencies
4. Copy local configuration for testing and production from local
   repository (as to avoid checking in passwords)
5. Show upgrade banner on site
6. Close database for writing
7. Fetch the name of the current production database
8. Clone database
9. Modify Django settings to point at cloned database
10.Migrate using South
11.Run tests with testing configuration
12.Re-index site using your chosen search backend
13.Switch symlink from pointing to previous production site to new (site
   should reload automatically since wsgi file is updated)
14.Open DB for writing
Good luck!




             Photo credit

Weitere ähnliche Inhalte

Was ist angesagt?

The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer ToolboxPablo Godel
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.Graham Dumpleton
 
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
IBM Drupal Users Group Discussion on Managing and Deploying ConfigurationIBM Drupal Users Group Discussion on Managing and Deploying Configuration
IBM Drupal Users Group Discussion on Managing and Deploying ConfigurationDevelopment Seed
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony AppsPablo Godel
 
Puppet for SysAdmins
Puppet for SysAdminsPuppet for SysAdmins
Puppet for SysAdminsPuppet
 
Tap into the power of slaves with Jenkins by Kohsuke Kawaguchi
Tap into the power of slaves with Jenkins by Kohsuke KawaguchiTap into the power of slaves with Jenkins by Kohsuke Kawaguchi
Tap into the power of slaves with Jenkins by Kohsuke KawaguchiZeroTurnaround
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Django deployment best practices
Django deployment best practicesDjango deployment best practices
Django deployment best practicesErik LaBianca
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java binOlve Hansen
 
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
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011tobiascrawley
 
Introduction to Puppet Scripting
Introduction to Puppet ScriptingIntroduction to Puppet Scripting
Introduction to Puppet ScriptingAchieve Internet
 
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Puppet
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet CampPuppet
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011tobiascrawley
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點William Yeh
 
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
 

Was ist angesagt? (20)

The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.
 
Scaling Django
Scaling DjangoScaling Django
Scaling Django
 
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
IBM Drupal Users Group Discussion on Managing and Deploying ConfigurationIBM Drupal Users Group Discussion on Managing and Deploying Configuration
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
 
Puppet for SysAdmins
Puppet for SysAdminsPuppet for SysAdmins
Puppet for SysAdmins
 
Tap into the power of slaves with Jenkins by Kohsuke Kawaguchi
Tap into the power of slaves with Jenkins by Kohsuke KawaguchiTap into the power of slaves with Jenkins by Kohsuke Kawaguchi
Tap into the power of slaves with Jenkins by Kohsuke Kawaguchi
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Django deployment best practices
Django deployment best practicesDjango deployment best practices
Django deployment best practices
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java bin
 
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 & Jenkins
Puppet & JenkinsPuppet & Jenkins
Puppet & Jenkins
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
 
Introduction to Puppet Scripting
Introduction to Puppet ScriptingIntroduction to Puppet Scripting
Introduction to Puppet Scripting
 
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
 
ABCs of docker
ABCs of dockerABCs of docker
ABCs of docker
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
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...
 

Ähnlich wie Django Deployment with Fabric

[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...Ambassador Labs
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Deepak Garg
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ TokopediaQasim Zaidi
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?Dmitri Shiryaev
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
Devoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best PracticesDevoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best PracticesEric Bottard
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodeKris Buytaert
 
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...MarcinStachniuk
 
Docker module 1
Docker module 1Docker module 1
Docker module 1Liang Bo
 
Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaSAppsembler
 
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDocker, Inc.
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-wayRobert Lujo
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers WorkshopJody Garnett
 
Continuous integration by Rémy Virin
Continuous integration by Rémy VirinContinuous integration by Rémy Virin
Continuous integration by Rémy VirinCocoaHeads France
 
Avoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and VagrantAvoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and Vagrantandygale
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at ScaleKris Buytaert
 
Docker for Development
Docker for DevelopmentDocker for Development
Docker for Developmentallingeek
 

Ähnlich wie Django Deployment with Fabric (20)

[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ Tokopedia
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Devoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best PracticesDevoxx France 2013 Cloud Best Practices
Devoxx France 2013 Cloud Best Practices
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as Code
 
Test like a_boss
Test like a_bossTest like a_boss
Test like a_boss
 
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
Java Web Start czyli jak żyć z tą dziwną technologią? & Continuous Delivery w...
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaS
 
Js tacktalk team dev js testing performance
Js tacktalk team dev js testing performanceJs tacktalk team dev js testing performance
Js tacktalk team dev js testing performance
 
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers Workshop
 
Continuous integration by Rémy Virin
Continuous integration by Rémy VirinContinuous integration by Rémy Virin
Continuous integration by Rémy Virin
 
Avoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and VagrantAvoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and Vagrant
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at Scale
 
Docker for Development
Docker for DevelopmentDocker for Development
Docker for Development
 

Kürzlich hochgeladen

Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Django Deployment with Fabric

  • 1. Jonas Nockert jonasnockert@gmail.com @lemonad Fabric Django deployment Stockholm Django User Group, November 9, 2009 http://jonasnockert.com/2009/11/fabric-django-deployment/ Photo credit
  • 2. Great! Your Django app is done!
  • 3. Now all you have to do is... • fix bugs and implement new • keep track of local_settings features • reload wsgi files • git archive • Change symbolic links (yay, • move files from development deployed!) to staging and production servers • empty and pre-warm cache • install updates to django, • oops! forgot to migrate data! reusable apps, pypi packages, etc. • run backups (for the rest of your life)
  • 4. Wouldn’t it be nice if all you had to do was this? $ fab staging deploy $ fab production deploy (yay, backup’d and deployed!)
  • 5. Fabric is easy! Photo credit
  • 6. Basic building blocks (the core API) • run — run a command on a remote host. • sudo — run a sudoed command on a remote host. • local — run a command on the local host. • get/put — copy a file from/to a remote host. • prompt — ask the user for information • For everything else there’s Python.
  • 7. Execute commands • Get output and return code: output = run(“command”) • Chain commands: run(“workon project && git pull origin master”) • start pseudo-daemons: run(“screen -d -m not-a-daemon”) • Any return code except 0 is treated as an error and an exception is thrown (unless warn_only is set)
  • 8. Move files • Put a file (upload): put(“local-file”, “remote-file”, mode=0755) • Get a file (download): get(“remote-file”, “local-file”) • If a problem occurs while uploading or downloading files, fabric throws an exception.
  • 9. Ask questions • Validation: relase_name = prompt(“What do you want to “ “name the new release?: ”, validate=”^[a-zA-Z0-9]+$”) proxy_port_number = prompt(“Proxy port: “, validate=int) • Default: username = prompt(“Username: “, default=”jonas”)
  • 10. Keeping state (sort of) • Directories: with cd(“xmpp/”): run(“git clone git://git/something.git”) run(“mkvirtualenv --no-site-packages something“) • For those running from trunk: with prefix(“workon something”): run(“pip install Django>=1.1”) Observe that the name is not set in stone yet. c.f. http://stackoverflow.com/questions/1180411/activate-a-virtualenv-via-fabric-as-deploy-user
  • 11. Contrib • Contrib is a collection of useful tools. Search and replace in remote files amongst other things. • However, it is not as evolved as the Fabric core API and contains, in Jeff Forcier’s own words, “approaches that work for Jeff on two different Linux distros and that’s about it.”
  • 12. Append text to files • Appends text unless it already exist in file as a discrete line: from fabric.contrib.files import append append(“DATABASE_NAME = 'hello.db'”, “local_settings.py”)
  • 13. Search and replace • Use fabric’s sed function to modify content of files: from fabric.contrib.files import sed sed(“local_settings.py”, “^DEBUG = True$”, “DEBUG = False”)
  • 14. Example from fabric.api import run def install_django(): run('workon myproject && pip install django') $ fab -H localhost,djangodev install_django This will install Django within the myproject virtualenv on both the local machine and on the host djangodev
  • 15. While Fabric is easy, deployment is hard! (but rewarding) Photo credit
  • 16. Rebuilding from scratch? • Define scratch Depends to some degree on what you want to achieve Do you start from a given and if it’s limited to virtual machine image? deployment purposes. ...or just your application and Perhaps you just want to be its dependencies? able to easily test against a new release of Ubuntu, ...or just your application? perhaps a new release of Django.
  • 17. What about the database? • Do you migrate the current • Apply migrations to a copy? one? When you’ve deployed, the You could backup and copy becomes the new restore if something goes production DB. wrong. Make sure you have a way But you can’t reliably keep of finding out the name of the site up while migrating. your current production DB (in order to deploy the next time). Database-level permissions might need to be handled.
  • 18. Testing? • Cancel and revert deployment if the test suite fails! • This is actually pretty simple: run(“workon project && python manage.py test”) Django returns the number of failed tests or 0 if all tests pass, and run throws an exception if the return code is anything but 0. All you have to worry about is reverting to the state before deployment started.
  • 19. What about the live site? • Show an update banner on • Set database layer to read- the site? only? • Set Django application to Have you designed your application to handle SQL read-only? errors nicely? Have you separated code that reads from the DB from • Shut down Apache? What if code that writes? you have multiple applications? • You’ll probably need to work on a separate DB while updating and migrating, right?
  • 20. Trying to combine it all 1. Get source code 2. Create virtualenv 3. Use buildout to install dependencies 4. Copy local configuration for testing and production from local repository (as to avoid checking in passwords) 5. Show upgrade banner on site 6. Close database for writing 7. Fetch the name of the current production database 8. Clone database 9. Modify Django settings to point at cloned database 10.Migrate using South 11.Run tests with testing configuration 12.Re-index site using your chosen search backend 13.Switch symlink from pointing to previous production site to new (site should reload automatically since wsgi file is updated) 14.Open DB for writing
  • 21. Good luck! Photo credit