SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Best of both worlds
                             Deploying Django projects
                          with Capistrano and Supervisord

                                   Maciej Pasternacki
                                      SetJam, Inc.
                                 maciej@pasternacki.net

Wednesday, May 26, 2010                                     1
Best of both worlds

          Should we only use Python tools with Django,
           or rather pick and mix best tools available,
          regardless of the ecosystem they come from?




http://www.setjam.com/
Wednesday, May 26, 2010                                   2
Background

                          SetJam.com: an online TV guide
                          Started June 2009,
                          public beta December 2009,
                          incorporated February 2010
                          Agile & Open Source-based

http://www.setjam.com/
Wednesday, May 26, 2010                                    3
What’s this talk about?
                          Release management

                          Automated deployment

                          Upstream libraries

                          Process management

                          Scaling in cloud

                          Centralized logging

http://www.setjam.com/
Wednesday, May 26, 2010                          4
Release management


                          Weekly iterations
                          Devel → Staging → Production
                          All in git branches



http://www.setjam.com/
Wednesday, May 26, 2010                                  5
Capistrano
                               automating the deployment



                          Separate, independent releases
                          Mature & complete
                          Full workflow
                          Transactions and rollbacks


http://www.setjam.com/
Wednesday, May 26, 2010                                    6
Capistrano
                                      directory layout
                          releases    YYYYMMDDHHMMSS

                                        20100512210109

                                        20100514101512

                                        20100515085101

                                        20100515101756

                          current                                 log

                                              var/              solr_data
                          shared
                                                            processed_images
                                        local_settings.py
                                                                 …

                                               …
http://www.setjam.com/
Wednesday, May 26, 2010                                                        7
deploy:setup                                 Prepares one or more servers for
                                                                       deployment.


                          deploy:default                               Deploys your project.



                              deploy:update                            Copies your project and updates
                                                                       the symlink.


                                deploy:update_code                     Copies your project to the remote servers.

                                                    strategy.deploy!


                                 deploy:finalize_update                  [internal] Touches up the released code.



                                           deploy:symlink              Updates the symlink to the most recently
                                                                       deployed release


                                           deploy:restart              Restarts your application.

http:/
              Transaction
      /www.setjam.com/
                                                              http://www.capify.org/index.php/Default_Deployment_Path
Wednesday, May 26, 2010                                                                                                 8
Capistrano-offroad
                          an open source pack of Capistrano utils



                          Reset Capistrano’s railsy defaults
                          Handful of utility functions
                          Django and Supervisord recipes
                          Want to improve!


http://www.setjam.com/
Wednesday, May 26, 2010                                             9
Capistrano
                          configuration samples: settings
               # Capistrano-offroad modules
               load 'lib/capistrano-offroad/offroad.rb'
               offroad_modules 'defaults', 'django', 'supervisord'

               # Server config
               server "staging.setjam.com", :web, :db, :primary => true
               role :app, "molly.setjam.com"
               group :staging_fetch, :backend

               set :deploy_to, "/srv/staging"
               set :deploy_user, "staging"
               set :deploy_group, "staging"

               set :python, "/opt/python26/bin/python2.6"
               set :django_project_subdirectory, "setjam"
               set :django_use_south, true

http://www.setjam.com/
Wednesday, May 26, 2010                                                   10
Capistrano
                          configuration samples: dependencies




                          depend   :remote, :command, "make"
                          depend   :remote, :command, "s3cmd"
                          […]
                          depend   :remote,   :python_module,   "PIL"
                          depend   :remote,   :python_module,   "flup"
                          depend   :remote,   :python_module,   "lxml"
                          depend   :remote,   :python_module,   "MySQLdb"




http://www.setjam.com/
Wednesday, May 26, 2010                                                     11
Capistrano
                           configuration samples: tasks

         desc "[internal] finalize code update"
         task :finalize_update do
           run "ln -sfv #{shared_path}/local_settings*.py #{latest_release}/setjam/"
           run "make -C #{latest_release}/lib/ wait-for-cached download-cached"
           run "mv #{latest_release}/var #{latest_release}/var.orig"
           run "ln -sv #{shared_path}/var #{latest_release}/var"
           django_manage "synccompress", :roles => [:app, :web]
           _role_supervisord_conf :backend
           _role_supervisord_conf :app
         end

         desc "[internal] Wait until processes are reachable"
         task :wait, :roles => :app do
           run "#{current_path}/scripts/waitfcgi #{fcgi_port}"
           run "#{current_path}/scripts/waitfcgi #{fcgi_api_port}"
         end



http://www.setjam.com/
Wednesday, May 26, 2010                                                                12
Capistrano
                          configuration samples: hooks



             after "deploy:setup", "setjam:setup"
             before "deploy:finalize_update", "setjam:finalize_update"

             before "deploy:symlink", "smoke:offline"
             after "deploy:start", "smoke"
             after "deploy:restart", "smoke"
             before "smoke", "setjam:wait"

             before "deploy:cleanup" do set :use_sudo, true end
             after "deploy:cleanup" do set :use_sudo, false end




http://www.setjam.com/
Wednesday, May 26, 2010                                                  13
Upstream libraries
                                  how to get them?




                          System-wide?
                          Project-wide (shared?)
                          Release-wide!



http://www.setjam.com/
Wednesday, May 26, 2010                              14
Upstream libraries
                            standard approach: virtualenv+pip



                          pulling from upstream VC?
                          add local patches?
                          cache library set?
                          non-python dependencies?


http://www.setjam.com/
Wednesday, May 26, 2010                                         15
Upstream libraries
                               current approach: Makefile



                          Make tasks to get and patch libs
                          Timestamp files for dependencies
                          Cache versioned tarballs in S3
                          Symlinks to use downloaded stuff


http://www.setjam.com/
Wednesday, May 26, 2010                                      16
Upstream libraries
                            current approach: Makefile
                              all: Django.stamp _submodules.stamp 
                                  beautifulsoup.stamp 
                                  boto.stamp 
                                  concurrentloghandler.stamp 
                                  oauth.stamp 
                                  piston.stamp 
                                  httplib2.stamp 
                                  pyflakes.stamp 
                                  python-memcached.stamp 
                                  south.stamp 
                                  test_coverage.stamp 
                                  urllib3.stamp 
                                  pyyaml.stamp 
                                  feedparser.stamp 
                                  unittest2.stamp
                                      chmod -R a+rX .

      south.stamp: south.release south-return_status.diff
              rm -rf south
              hg clone -r `head -1 south.release` http://bitbucket.org/andrewgodwin/south/
              cd south && patch -p1 < ../south-return_status.diff
              date > $@
http://www.setjam.com/
Wednesday, May 26, 2010                                                                      17
Upstream libraries
                                 current approach: Makefile
                          .PHONY: _submodules.stamp
                          _submodules.stamp:
                                  cd .. && git submodule update --init
                                  date > $@
     DJANGO_VERSION=1.1.1
     DJANGO_BASENAME=Django-$(DJANGO_VERSION)
     $(DJANGO_BASENAME).tar.gz:
             wget -q -O $@ http://www.djangoproject.com/download/$(DJANGO_VERSION)/tarball/
             touch $@     # needed - wget doesn't update timestamp properly

     Django.stamp: $(DJANGO_BASENAME).tar.gz Django-test_suite.3.diff Django-unittest2.diff
             rm -rf $(DJANGO_BASENAME) Django
             tar -xzf $<
             cd $(DJANGO_BASENAME) && patch -p0 < ../Django-test_suite.3.diff
             cd $(DJANGO_BASENAME) && patch -p0 < ../Django-test-client-cookie-fix.diff
             cd $(DJANGO_BASENAME) && patch -p1 < ../Django-unittest2.diff
             ln -s $(DJANGO_BASENAME) Django
             date > $@


http://www.setjam.com/
Wednesday, May 26, 2010                                                                       18
Supervisord
                                 process management


                          Manages foreground processes
                          Easy to use locally
                          Easy to configure — .ini file
                          Easy to extend
                          Robust and reliable

http://www.setjam.com/
Wednesday, May 26, 2010                                  19
Supervisord
                              configuration sample
            [program:fcgi]
            command = python2.6 manage.py runfcgi daemonize=false …
            stopsignal = HUP
            directory = %(here)s/../setjam/

            [program:api_fcgi]
            command = python2.6 manage.py runfcgi daemonize=false …
            stopsignal = HUP
            directory = %(here)s/../setjam/
            environment = DJANGO_SETTINGS_MODULE=settings_api

            [program:classifier]
            command = python2.6 manage.py runreceiver classification
            directory = %(here)s/../setjam/
            autostart = false
            process_name = classify-%(process_num)s
            numprocs = 3


http://www.setjam.com/
Wednesday, May 26, 2010                                                20
Scaling in cloud

                   Few central servers
                   Symmetrical processes
                   Queuing to distribute work: django-sqs
                   EC2 security groups to mark roles:
                   capistrano-ec2group

http://www.setjam.com/
Wednesday, May 26, 2010                                     21
Scaling in cloud
                           deploying a new server


             Start new instance
             cap HOSTFILTER=… deploy:setup
             Copy local_settings.py

             cap HOSTFILTER=… deploy
             Maybe update central server config

http://www.setjam.com/
Wednesday, May 26, 2010                             22
Logging

               logging.handlers.SysLogHandler
               Central rsyslogd writes to MySQL
               phplogcon for log browsing
               Customized log reports from MySQL


http://www.setjam.com/
Wednesday, May 26, 2010                            23
http://www.setjam.com/
Wednesday, May 26, 2010   24
http://www.setjam.com/
Wednesday, May 26, 2010   25
Future work

                          Monitoring and status - Nagios?

                          Automate machine administration - Chef?

                          Polish and gemify capistrano-offroad

                          Rake instead of make for upstream libs

                          Capistrano rendering configs from templates


http://www.setjam.com/
Wednesday, May 26, 2010                                                26
Questions?
            More info: www.setjam.com/blog/
            Code: github.com/mpasternacki/
            More code: gist.github.com/mpasternacki/
            E-mail: maciej@pasternacki.net
            Twitter: @mpasternacki

http://www.setjam.com/
Wednesday, May 26, 2010                                27

Más contenido relacionado

Último

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Best Of Both Worlds

  • 1. Best of both worlds Deploying Django projects with Capistrano and Supervisord Maciej Pasternacki SetJam, Inc. maciej@pasternacki.net Wednesday, May 26, 2010 1
  • 2. Best of both worlds Should we only use Python tools with Django, or rather pick and mix best tools available, regardless of the ecosystem they come from? http://www.setjam.com/ Wednesday, May 26, 2010 2
  • 3. Background SetJam.com: an online TV guide Started June 2009, public beta December 2009, incorporated February 2010 Agile & Open Source-based http://www.setjam.com/ Wednesday, May 26, 2010 3
  • 4. What’s this talk about? Release management Automated deployment Upstream libraries Process management Scaling in cloud Centralized logging http://www.setjam.com/ Wednesday, May 26, 2010 4
  • 5. Release management Weekly iterations Devel → Staging → Production All in git branches http://www.setjam.com/ Wednesday, May 26, 2010 5
  • 6. Capistrano automating the deployment Separate, independent releases Mature & complete Full workflow Transactions and rollbacks http://www.setjam.com/ Wednesday, May 26, 2010 6
  • 7. Capistrano directory layout releases YYYYMMDDHHMMSS 20100512210109 20100514101512 20100515085101 20100515101756 current log var/ solr_data shared processed_images local_settings.py … … http://www.setjam.com/ Wednesday, May 26, 2010 7
  • 8. deploy:setup Prepares one or more servers for deployment. deploy:default Deploys your project. deploy:update Copies your project and updates the symlink. deploy:update_code Copies your project to the remote servers. strategy.deploy! deploy:finalize_update [internal] Touches up the released code. deploy:symlink Updates the symlink to the most recently deployed release deploy:restart Restarts your application. http:/ Transaction /www.setjam.com/ http://www.capify.org/index.php/Default_Deployment_Path Wednesday, May 26, 2010 8
  • 9. Capistrano-offroad an open source pack of Capistrano utils Reset Capistrano’s railsy defaults Handful of utility functions Django and Supervisord recipes Want to improve! http://www.setjam.com/ Wednesday, May 26, 2010 9
  • 10. Capistrano configuration samples: settings # Capistrano-offroad modules load 'lib/capistrano-offroad/offroad.rb' offroad_modules 'defaults', 'django', 'supervisord' # Server config server "staging.setjam.com", :web, :db, :primary => true role :app, "molly.setjam.com" group :staging_fetch, :backend set :deploy_to, "/srv/staging" set :deploy_user, "staging" set :deploy_group, "staging" set :python, "/opt/python26/bin/python2.6" set :django_project_subdirectory, "setjam" set :django_use_south, true http://www.setjam.com/ Wednesday, May 26, 2010 10
  • 11. Capistrano configuration samples: dependencies depend :remote, :command, "make" depend :remote, :command, "s3cmd" […] depend :remote, :python_module, "PIL" depend :remote, :python_module, "flup" depend :remote, :python_module, "lxml" depend :remote, :python_module, "MySQLdb" http://www.setjam.com/ Wednesday, May 26, 2010 11
  • 12. Capistrano configuration samples: tasks desc "[internal] finalize code update" task :finalize_update do run "ln -sfv #{shared_path}/local_settings*.py #{latest_release}/setjam/" run "make -C #{latest_release}/lib/ wait-for-cached download-cached" run "mv #{latest_release}/var #{latest_release}/var.orig" run "ln -sv #{shared_path}/var #{latest_release}/var" django_manage "synccompress", :roles => [:app, :web] _role_supervisord_conf :backend _role_supervisord_conf :app end desc "[internal] Wait until processes are reachable" task :wait, :roles => :app do run "#{current_path}/scripts/waitfcgi #{fcgi_port}" run "#{current_path}/scripts/waitfcgi #{fcgi_api_port}" end http://www.setjam.com/ Wednesday, May 26, 2010 12
  • 13. Capistrano configuration samples: hooks after "deploy:setup", "setjam:setup" before "deploy:finalize_update", "setjam:finalize_update" before "deploy:symlink", "smoke:offline" after "deploy:start", "smoke" after "deploy:restart", "smoke" before "smoke", "setjam:wait" before "deploy:cleanup" do set :use_sudo, true end after "deploy:cleanup" do set :use_sudo, false end http://www.setjam.com/ Wednesday, May 26, 2010 13
  • 14. Upstream libraries how to get them? System-wide? Project-wide (shared?) Release-wide! http://www.setjam.com/ Wednesday, May 26, 2010 14
  • 15. Upstream libraries standard approach: virtualenv+pip pulling from upstream VC? add local patches? cache library set? non-python dependencies? http://www.setjam.com/ Wednesday, May 26, 2010 15
  • 16. Upstream libraries current approach: Makefile Make tasks to get and patch libs Timestamp files for dependencies Cache versioned tarballs in S3 Symlinks to use downloaded stuff http://www.setjam.com/ Wednesday, May 26, 2010 16
  • 17. Upstream libraries current approach: Makefile all: Django.stamp _submodules.stamp beautifulsoup.stamp boto.stamp concurrentloghandler.stamp oauth.stamp piston.stamp httplib2.stamp pyflakes.stamp python-memcached.stamp south.stamp test_coverage.stamp urllib3.stamp pyyaml.stamp feedparser.stamp unittest2.stamp chmod -R a+rX . south.stamp: south.release south-return_status.diff rm -rf south hg clone -r `head -1 south.release` http://bitbucket.org/andrewgodwin/south/ cd south && patch -p1 < ../south-return_status.diff date > $@ http://www.setjam.com/ Wednesday, May 26, 2010 17
  • 18. Upstream libraries current approach: Makefile .PHONY: _submodules.stamp _submodules.stamp: cd .. && git submodule update --init date > $@ DJANGO_VERSION=1.1.1 DJANGO_BASENAME=Django-$(DJANGO_VERSION) $(DJANGO_BASENAME).tar.gz: wget -q -O $@ http://www.djangoproject.com/download/$(DJANGO_VERSION)/tarball/ touch $@ # needed - wget doesn't update timestamp properly Django.stamp: $(DJANGO_BASENAME).tar.gz Django-test_suite.3.diff Django-unittest2.diff rm -rf $(DJANGO_BASENAME) Django tar -xzf $< cd $(DJANGO_BASENAME) && patch -p0 < ../Django-test_suite.3.diff cd $(DJANGO_BASENAME) && patch -p0 < ../Django-test-client-cookie-fix.diff cd $(DJANGO_BASENAME) && patch -p1 < ../Django-unittest2.diff ln -s $(DJANGO_BASENAME) Django date > $@ http://www.setjam.com/ Wednesday, May 26, 2010 18
  • 19. Supervisord process management Manages foreground processes Easy to use locally Easy to configure — .ini file Easy to extend Robust and reliable http://www.setjam.com/ Wednesday, May 26, 2010 19
  • 20. Supervisord configuration sample [program:fcgi] command = python2.6 manage.py runfcgi daemonize=false … stopsignal = HUP directory = %(here)s/../setjam/ [program:api_fcgi] command = python2.6 manage.py runfcgi daemonize=false … stopsignal = HUP directory = %(here)s/../setjam/ environment = DJANGO_SETTINGS_MODULE=settings_api [program:classifier] command = python2.6 manage.py runreceiver classification directory = %(here)s/../setjam/ autostart = false process_name = classify-%(process_num)s numprocs = 3 http://www.setjam.com/ Wednesday, May 26, 2010 20
  • 21. Scaling in cloud Few central servers Symmetrical processes Queuing to distribute work: django-sqs EC2 security groups to mark roles: capistrano-ec2group http://www.setjam.com/ Wednesday, May 26, 2010 21
  • 22. Scaling in cloud deploying a new server Start new instance cap HOSTFILTER=… deploy:setup Copy local_settings.py cap HOSTFILTER=… deploy Maybe update central server config http://www.setjam.com/ Wednesday, May 26, 2010 22
  • 23. Logging logging.handlers.SysLogHandler Central rsyslogd writes to MySQL phplogcon for log browsing Customized log reports from MySQL http://www.setjam.com/ Wednesday, May 26, 2010 23
  • 26. Future work Monitoring and status - Nagios? Automate machine administration - Chef? Polish and gemify capistrano-offroad Rake instead of make for upstream libs Capistrano rendering configs from templates http://www.setjam.com/ Wednesday, May 26, 2010 26
  • 27. Questions? More info: www.setjam.com/blog/ Code: github.com/mpasternacki/ More code: gist.github.com/mpasternacki/ E-mail: maciej@pasternacki.net Twitter: @mpasternacki http://www.setjam.com/ Wednesday, May 26, 2010 27