SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
Real-world Django Deployment with Chef

     DjangoCon 2011

      Noah Kantrowitz
        noah@opscode.com
            @kantrn
Who am I?




•   Django hacker
•   Ruby user
•   Developer
•   Sys admin
Who are you?




•   System administrators?
•   Designers?
•   Developers?
•   “Business” People?




                              http://www.flickr.com/photos/timyates/2854357446/sizes/l/
What are we talking
      about?

     http://www.flickr.com/photos/peterkaminski/2174679908/
Agenda




•   How’s and Why’s
•   Getting Started with Chef
•   Python-specific Tools
•   Case Study: Packaginator




                                http://www.flickr.com/photos/koalazymonkey/3590953001/
Infrastructure as Code
A technical domain
revolving around
building and
managing
infrastructure
programmatically
Enable the reconstruction
   of the business from
nothing but a source code
repository, an application
  data backup, and bare
     metal resources.
Configuration
Management
System Integration


     http://www.flickr.com/photos/opalsson/3773629074/
n-Tier Infrastructure



              Load Balancer




App Server   { {               App Server
                                                    •
                                                    •
                                                    •
                                                        Provision
                                                        Configure
                                                        Integrate


             Database Master
The Chef Framework


   With thanks (and apologies) to Stephen Nelson-Smith
The Chef Framework




•   Reasonability
•   Flexibility
•   Library & Primitives
The Chef Tool(s)


 With thanks (and apologies) to Stephen Nelson-Smith
The Chef Tool(s)




•   ohai
•   chef-client
•   chef-server
•   knife
The Chef API


With thanks (and apologies) to Stephen Nelson-Smith
The Chef API




•   Client/Server
•   RESTful API w/ JSON
•   Search Service
•   Derivative Services
The Chef Community


   With thanks (and apologies) to Stephen Nelson-Smith
The Chef Community




•   Apache License, Version 2.0
•   400+ Individual contributors
•   90+ Corporate contributors
    •   Dell, Rackspace,VMware, RightScale,
        Heroku, and more
•   240+ cookbooks
•   http://community.opscode.com/
Chef Enables Infrastructure as Code

                       package "haproxy" do
                         action :install
                       end

                       template "/etc/haproxy/haproxy.cfg" do
                         source "haproxy.cfg.erb"
•   Resources            owner "root"
                         group "root"
•   Recipes              mode 0644

•
                         notifies :restart, "service[haproxy]"
    Roles              end

•   Source Code        service "haproxy" do
                         supports :restart => true
                         action [:enable, :start]
                       end
Chef Resources

                                      package "haproxy" do
                                        action :install
                                      end

•   Have a type.                      template "/etc/haproxy/haproxy.cfg" do

•
                                        source "haproxy.cfg.erb"
    Have a name.                        owner "root"

•   Have parameters.                    group "root"
                                        mode 0644

•   Take action to put the resource     notifies :restart, "service[haproxy]"
                                      end
    in the declared state.
•   Can send notifications to other
                                      service "haproxy" do
                                        supports :restart => true
    resources.                          action [:enable, :start]
                                      end
Resources take action
 through Providers
Chef Providers




package “haproxy”
                    {   yum install haproxy
                        apt-get install haproxy
                        pacman sync haproxy
                        pkg_add -r haproxy
Common Resources




package "apache2"

template "/etc/apache2/httpd.conf"

cookbook_file "/etc/apache2/key.pem"

user "www-data"

execute "/etc/init.d/apache2 restart"
Idempotence




                    execute "createdb myapp" do
                      not_if "psql -c list | grep myapp"
                    end
•   Convergence
                    execute "createdb myapp" do
•   Guard clauses     only_if do
                        db.query("SELECT ...").first == 0
                      end
                    end
Recipes are collections
     of Resources
Chef Recipes

                                    package "haproxy" do
                                      action :install
                                    end

                                    template "/etc/haproxy/haproxy.cfg" do
                                      source "haproxy.cfg.erb"
•   Recipes are evaluated for         owner "root"
    resources in the order they       group "root"
                                      mode 0644
    appear.                           notifies :restart, "service[haproxy]"

•   Each resource object is added   end

    to the Resource Collection.     service "haproxy" do
                                      supports :restart => true
                                      action [:enable, :start]
                                    end
Chef Recipes




•   Recipes can include other   include_recipe
                                include_recipe
                                                 "apache2"
                                                 "apache2::mod_rewrite"
    recipes.                    include_recipe   "apache2::mod_deflate"

•   Included recipes are
                                include_recipe
                                include_recipe
                                                 "apache2::mod_headers"
                                                 "apache2::mod_php5"
    processed in order.
Chef Recipes




                            pool_members = search("node", "role:mediawiki")

                                 %w{ template "/etc/haproxy/haproxy.cfg" do
•   Extend recipes with     template php5 php5-dev php5-cgi }.each do |pkg|
                                      "/etc/haproxy/haproxy.cfg" do
                                       source "haproxy.cfg.erb"
                              source "haproxy.cfg.erb"
    Ruby.                              owner "root"
                                   package pkg do
                              owner "root"
                                       group "root"
•
                                      action :install
                              group "root"
    Dynamic configuration          end mode 0644
                              mode 0644
                                       notifies :restart, "service[haproxy]"
    through search.           variables :pool_members => pool_members
                                 end end:restart, "service[haproxy]"
                              notifies
                            end
Chef Roles

                                 name "mediawiki"
                                 description "mediawiki app server"
                                 run_list(
                                   "recipe[mysql::client]",
                                   "recipe[application]",
                                   "recipe[mediawiki::status]"
                                 )

•   Roles describe nodes.
                                 name "mediawiki_load_balancer"
•   Roles have a run list.       description "mediawiki load balancer"
                                 run_list(
•   Roles can have attributes.
                                 )
                                   "recipe[haproxy::app_lb]"

                                 override_attributes(
                                   "haproxy" => {
                                     "app_server_role" => "mediawiki"
                                   }
                                 )
Track it like source code...

% git log
commit d640a8c6b370134d7043991894107d806595cc35
Author: jtimberman <joshua@opscode.com>

    Import nagios version 1.0.0

commit c40c818498710e78cf73c7f71e722e971fa574e7
Author: jtimberman <joshua@opscode.com>

    installation and usage instruction docs

commit 99d0efb024314de17888f6b359c14414fda7bb91
Author: jtimberman <joshua@opscode.com>

    Import haproxy version 1.0.1

commit c89d0975ad3f4b152426df219fee0bfb8eafb7e4
Author: jtimberman <joshua@opscode.com>

    add mediawiki cookbook

commit 89c0545cc03b9be26f1db246c9ba4ce9d58a6700
Author: jtimberman <joshua@opscode.com>

    multiple environments in data bag for mediawiki
Other Chef Terms




•   Cookbooks are collections of recipes
•   Environments are pegged cookbook versions
•   Servers are Nodes
•   Data bags are JSON blobs
Python Cookbook




•   python::package, python::source — Install Python

•   python::pip, python::virtualenv — Make it dance

•   python::default — All of the above!

•   python_pip, python_virtualenv
Installing a package




python_virtualenv "/srv/myapp/env" do
  action :create
end

python_pip "django" do
  action :upgrade
  version "1.3"
  virtualenv "/srv/myapp/env"
end
Gunicorn Cookbook




•   gunicorn::default
•   gunicorn_config
Supervisor Cookbook




•   supervisor::default
    •   Debian-style for now
•   supervisor_service
Packaginator
Role: base




                     name "base"
                     description "Base role applied to all nodes."
                     run_list(

•   Install users      "recipe[users::sysadmins]",
                       "recipe[sudo]",


•
                       "recipe[apt]",
    Configure sudo   )
                       "recipe[build-essential]"



•
                     override_attributes(
    apt-get update     :authorization => {
                         :sudo => {

•   Install gcc
                         }
                           :users => ["ubuntu"],
                           :passwordless => true

                       }
                     )
Recipe: packaginator

                         application "packaginator" do
                           path "/srv/packaginator"
                           owner "nobody"
                           group "nogroup"
                           repository "https://github.com/coderanger/packaginator.git"
                           revision "master"
                           migrate true
                           packages ["libpq-dev", "git-core", "mercurial"]

                           django do
                             packages ["redis"]
                             requirements "requirements/mkii.txt"
                             settings_template "settings.py.erb"
                             debug true
                             database do
                               database "packaginator"




•
                               engine "postgresql_psycopg2"


    The good stuff
                               username "packaginator"
                               password "awesome_password"
                             end
                             database_master_role "packaginator_database_master"




•
                             collectstatic "build_static --noinput"
                           end

    General parameters     gunicorn do
                             only_if { node['roles'].include? 'packaginator_application_server' }




•
                             app_module :django
                             port 8080

    Sub-resources          end

                           celery do
                             only_if { node['roles'].include? 'packaginator_application_server' }
                             config "celery_settings.py"
                             django true
                             celerybeat true
                             celerycam true
                             broker do
                               transport "redis"
                             end
                           end

                           nginx_load_balancer do
                             only_if { node['roles'].include? 'packaginator_load_balancer' }
                             application_port 8080
                             static_files "/site_media" => "site_media"
                           end

                         end
Application Resource




                          application "packaginator" do
•   Who are we?             path "/srv/packaginator"
•   Where are we going?     owner "nobody"
                            group "nogroup"
Application Resource




directory "/srv/packaginator"

directory "/srv/packaginator/shared"

deploy_revision "packaginator" do
  deploy_to "/srv/packaginator"
  owner "nobody"
  group "nogroup"
Application Resource




                       repository "https://github.com/..."
•   Source code        revision "master"
•   Migration status   migrate true
                       packages ["libpq-dev",
•   Base packages
                                 "git-core","mercurial"]
Django Resource




•   Python packages
•   pip requirements
                       django do
                         packages ["redis"]

•   Settings file
                         requirements "requirements/mkii.txt"
                         settings_template "settings.py.erb"

•   Debug mode
                         debug true
                         collectstatic "build_static --noinput"

•   Static files
Django Resource




python_pip "redis"

execute "pip -E ... -r ..."

template "shared/local_settings.py"

execute "manage.py build_static"
Folder Layout




•   /srv/myapp

    •   /srv/myapp/shared

        •   /srv/myapp/shared/releases

            •   /srv/myapp/shared/releases/4faedb2ee...

            •   /srv/myapp/shared/releases/9457be295...

            •   ...

    •   /srv/myapp/current
Folder Layout




•   /srv/myapp

    •   ...9457be295/local_settings.py -> ../shared/local_settings.py

    •   /srv/myapp/current -> .../releases/9457be295...
Django Resource




               database do
                 database "packaginator"
•   Database     engine "postgresql_psycopg2"
                 username "packaginator"
•   Where?       password "awesome_password"
               end
               database_master_role "packaginator_database_master"
Django Resource




                        if node["roles"].include? ...
•   Check local first     node
                        else
•   Cloud IP!             search(:node, "roles:...").first
                        end
Gunicorn Resource




                        gunicorn do
                          only_if do
•   Only on frontends       node["roles"].include? ...
•   Use Django mode       end
                          app_module :django
•   Internal port
                          port 8080
                        end
Gunicorn Resource




•   Write out config   gunicorn_config ...
•   Symlink it in
                       supervisor_service ...
•   Load service
Celery Resource




                         celery do
                           only_if ...
                           config "celery_settings.py"
•   Where?
                           django true
•   Django-mode            celerybeat true
•   Enable all three       celerycam true
                           broker do
•   Broker and results       transport "redis"
                           end
                         end
Nginx Resource




                          nginx_load_balancer do
                            only_if ...
                            application_port 8080
•   Internal port again     static_files({
•   Static map                "/site_media" =>
                                 "site_media"
    •   URL => path
                              })
                          end
https://github.com/coderanger/djangocon2011
Noah Kantrowitz
        @kantrn
    noah@opscode.com

Mais conteúdo relacionado

Mais procurados

PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopPuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopWalter Heck
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Chef
 
Chef for OpenStack - OpenStack Fall 2012 Summit
Chef for OpenStack  - OpenStack Fall 2012 SummitChef for OpenStack  - OpenStack Fall 2012 Summit
Chef for OpenStack - OpenStack Fall 2012 SummitMatt Ray
 
Atmosphere 2014: Really large scale systems configuration - Phil Dibowitz
Atmosphere 2014: Really large scale systems configuration - Phil DibowitzAtmosphere 2014: Really large scale systems configuration - Phil Dibowitz
Atmosphere 2014: Really large scale systems configuration - Phil DibowitzPROIDEA
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chefLeanDog
 
Apache Hive micro guide - ConfusedCoders
Apache Hive micro guide - ConfusedCodersApache Hive micro guide - ConfusedCoders
Apache Hive micro guide - ConfusedCodersYash Sharma
 
Using Nagios with Chef
Using Nagios with ChefUsing Nagios with Chef
Using Nagios with ChefBryan McLellan
 
OSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy HawkinsOSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy HawkinsNETWAYS
 
AWS ElasticBeanstalk Advanced configuration
AWS ElasticBeanstalk Advanced configurationAWS ElasticBeanstalk Advanced configuration
AWS ElasticBeanstalk Advanced configurationLionel LONKAP TSAMBA
 
Chef for OpenStack: OpenStack Spring Summit 2013
Chef for OpenStack: OpenStack Spring Summit 2013Chef for OpenStack: OpenStack Spring Summit 2013
Chef for OpenStack: OpenStack Spring Summit 2013Matt Ray
 
Network Automation Tools
Network Automation ToolsNetwork Automation Tools
Network Automation ToolsEdwin Beekman
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chefkevsmith
 
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopAtlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopMatt Ray
 
Debugging Hive with Hadoop-in-the-Cloud by David Chaiken of Altiscale
Debugging Hive with Hadoop-in-the-Cloud by David Chaiken of AltiscaleDebugging Hive with Hadoop-in-the-Cloud by David Chaiken of Altiscale
Debugging Hive with Hadoop-in-the-Cloud by David Chaiken of AltiscaleData Con LA
 
Preppingthekitchen 1.0.3
Preppingthekitchen 1.0.3Preppingthekitchen 1.0.3
Preppingthekitchen 1.0.3Sean OMeara
 
The First Class Integration of Solr with Hadoop
The First Class Integration of Solr with HadoopThe First Class Integration of Solr with Hadoop
The First Class Integration of Solr with Hadooplucenerevolution
 

Mais procurados (19)

PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & HadoopPuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
PuppetCamp SEA 1 - Using Vagrant, Puppet, Testing & Hadoop
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
 
Chef for OpenStack - OpenStack Fall 2012 Summit
Chef for OpenStack  - OpenStack Fall 2012 SummitChef for OpenStack  - OpenStack Fall 2012 Summit
Chef for OpenStack - OpenStack Fall 2012 Summit
 
Atmosphere 2014: Really large scale systems configuration - Phil Dibowitz
Atmosphere 2014: Really large scale systems configuration - Phil DibowitzAtmosphere 2014: Really large scale systems configuration - Phil Dibowitz
Atmosphere 2014: Really large scale systems configuration - Phil Dibowitz
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
 
Apache Hive micro guide - ConfusedCoders
Apache Hive micro guide - ConfusedCodersApache Hive micro guide - ConfusedCoders
Apache Hive micro guide - ConfusedCoders
 
Using Nagios with Chef
Using Nagios with ChefUsing Nagios with Chef
Using Nagios with Chef
 
OSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy HawkinsOSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy Hawkins
 
AWS ElasticBeanstalk Advanced configuration
AWS ElasticBeanstalk Advanced configurationAWS ElasticBeanstalk Advanced configuration
AWS ElasticBeanstalk Advanced configuration
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Hdfs java api
Hdfs java apiHdfs java api
Hdfs java api
 
Chef for OpenStack: OpenStack Spring Summit 2013
Chef for OpenStack: OpenStack Spring Summit 2013Chef for OpenStack: OpenStack Spring Summit 2013
Chef for OpenStack: OpenStack Spring Summit 2013
 
Network Automation Tools
Network Automation ToolsNetwork Automation Tools
Network Automation Tools
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopAtlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
 
Debugging Hive with Hadoop-in-the-Cloud by David Chaiken of Altiscale
Debugging Hive with Hadoop-in-the-Cloud by David Chaiken of AltiscaleDebugging Hive with Hadoop-in-the-Cloud by David Chaiken of Altiscale
Debugging Hive with Hadoop-in-the-Cloud by David Chaiken of Altiscale
 
Preppingthekitchen 1.0.3
Preppingthekitchen 1.0.3Preppingthekitchen 1.0.3
Preppingthekitchen 1.0.3
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
The First Class Integration of Solr with Hadoop
The First Class Integration of Solr with HadoopThe First Class Integration of Solr with Hadoop
The First Class Integration of Solr with Hadoop
 

Semelhante a Real world Django deployment using Chef

SELF 2011: Deploying Django Application Stacks with Chef
SELF 2011: Deploying Django Application Stacks with ChefSELF 2011: Deploying Django Application Stacks with Chef
SELF 2011: Deploying Django Application Stacks with ChefChef Software, Inc.
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Software, Inc.
 
Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Chef
 
SCALE 2011 Deploying OpenStack with Chef
SCALE 2011 Deploying OpenStack with ChefSCALE 2011 Deploying OpenStack with Chef
SCALE 2011 Deploying OpenStack with ChefMatt Ray
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefAll Things Open
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Software, Inc.
 
Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Jennifer Davis
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowMatt Ray
 
Introduction to Cooking with Chef
Introduction to Cooking with ChefIntroduction to Cooking with Chef
Introduction to Cooking with ChefJohn Osborne
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackMatt Ray
 
Agiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As CodeAgiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As CodeMario IC
 
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...rhatr
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerGeorge Miranda
 
OC Big Data Monthly Meetup #5 - Session 1 - Altiscale
OC Big Data Monthly Meetup #5 - Session 1 - AltiscaleOC Big Data Monthly Meetup #5 - Session 1 - Altiscale
OC Big Data Monthly Meetup #5 - Session 1 - AltiscaleBig Data Joe™ Rossi
 

Semelhante a Real world Django deployment using Chef (20)

SELF 2011: Deploying Django Application Stacks with Chef
SELF 2011: Deploying Django Application Stacks with ChefSELF 2011: Deploying Django Application Stacks with Chef
SELF 2011: Deploying Django Application Stacks with Chef
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
 
Configuration management with Chef
Configuration management with ChefConfiguration management with Chef
Configuration management with Chef
 
Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1
 
SCALE 2011 Deploying OpenStack with Chef
SCALE 2011 Deploying OpenStack with ChefSCALE 2011 Deploying OpenStack with Chef
SCALE 2011 Deploying OpenStack with Chef
 
Chef advance
Chef advanceChef advance
Chef advance
 
Chef advance
Chef advanceChef advance
Chef advance
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
 
Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015
 
Chef for OpenStack- Fall 2012.pdf
Chef for OpenStack- Fall 2012.pdfChef for OpenStack- Fall 2012.pdf
Chef for OpenStack- Fall 2012.pdf
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
 
Introduction to Cooking with Chef
Introduction to Cooking with ChefIntroduction to Cooking with Chef
Introduction to Cooking with Chef
 
Chef: Smart infrastructure automation
Chef: Smart infrastructure automationChef: Smart infrastructure automation
Chef: Smart infrastructure automation
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStack
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
 
Agiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As CodeAgiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As Code
 
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
OC Big Data Monthly Meetup #5 - Session 1 - Altiscale
OC Big Data Monthly Meetup #5 - Session 1 - AltiscaleOC Big Data Monthly Meetup #5 - Session 1 - Altiscale
OC Big Data Monthly Meetup #5 - Session 1 - Altiscale
 

Último

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Real world Django deployment using Chef

  • 1. Real-world Django Deployment with Chef DjangoCon 2011 Noah Kantrowitz noah@opscode.com @kantrn
  • 2. Who am I? • Django hacker • Ruby user • Developer • Sys admin
  • 3. Who are you? • System administrators? • Designers? • Developers? • “Business” People? http://www.flickr.com/photos/timyates/2854357446/sizes/l/
  • 4. What are we talking about? http://www.flickr.com/photos/peterkaminski/2174679908/
  • 5. Agenda • How’s and Why’s • Getting Started with Chef • Python-specific Tools • Case Study: Packaginator http://www.flickr.com/photos/koalazymonkey/3590953001/
  • 7. A technical domain revolving around building and managing infrastructure programmatically
  • 8. Enable the reconstruction of the business from nothing but a source code repository, an application data backup, and bare metal resources.
  • 10. System Integration http://www.flickr.com/photos/opalsson/3773629074/
  • 11. n-Tier Infrastructure Load Balancer App Server { { App Server • • • Provision Configure Integrate Database Master
  • 12.
  • 13. The Chef Framework With thanks (and apologies) to Stephen Nelson-Smith
  • 14. The Chef Framework • Reasonability • Flexibility • Library & Primitives
  • 15. The Chef Tool(s) With thanks (and apologies) to Stephen Nelson-Smith
  • 16. The Chef Tool(s) • ohai • chef-client • chef-server • knife
  • 17. The Chef API With thanks (and apologies) to Stephen Nelson-Smith
  • 18. The Chef API • Client/Server • RESTful API w/ JSON • Search Service • Derivative Services
  • 19. The Chef Community With thanks (and apologies) to Stephen Nelson-Smith
  • 20. The Chef Community • Apache License, Version 2.0 • 400+ Individual contributors • 90+ Corporate contributors • Dell, Rackspace,VMware, RightScale, Heroku, and more • 240+ cookbooks • http://community.opscode.com/
  • 21. Chef Enables Infrastructure as Code package "haproxy" do action :install end template "/etc/haproxy/haproxy.cfg" do source "haproxy.cfg.erb" • Resources owner "root" group "root" • Recipes mode 0644 • notifies :restart, "service[haproxy]" Roles end • Source Code service "haproxy" do supports :restart => true action [:enable, :start] end
  • 22. Chef Resources package "haproxy" do action :install end • Have a type. template "/etc/haproxy/haproxy.cfg" do • source "haproxy.cfg.erb" Have a name. owner "root" • Have parameters. group "root" mode 0644 • Take action to put the resource notifies :restart, "service[haproxy]" end in the declared state. • Can send notifications to other service "haproxy" do supports :restart => true resources. action [:enable, :start] end
  • 23. Resources take action through Providers
  • 24. Chef Providers package “haproxy” { yum install haproxy apt-get install haproxy pacman sync haproxy pkg_add -r haproxy
  • 25. Common Resources package "apache2" template "/etc/apache2/httpd.conf" cookbook_file "/etc/apache2/key.pem" user "www-data" execute "/etc/init.d/apache2 restart"
  • 26. Idempotence execute "createdb myapp" do not_if "psql -c list | grep myapp" end • Convergence execute "createdb myapp" do • Guard clauses only_if do db.query("SELECT ...").first == 0 end end
  • 27. Recipes are collections of Resources
  • 28. Chef Recipes package "haproxy" do action :install end template "/etc/haproxy/haproxy.cfg" do source "haproxy.cfg.erb" • Recipes are evaluated for owner "root" resources in the order they group "root" mode 0644 appear. notifies :restart, "service[haproxy]" • Each resource object is added end to the Resource Collection. service "haproxy" do supports :restart => true action [:enable, :start] end
  • 29. Chef Recipes • Recipes can include other include_recipe include_recipe "apache2" "apache2::mod_rewrite" recipes. include_recipe "apache2::mod_deflate" • Included recipes are include_recipe include_recipe "apache2::mod_headers" "apache2::mod_php5" processed in order.
  • 30. Chef Recipes pool_members = search("node", "role:mediawiki") %w{ template "/etc/haproxy/haproxy.cfg" do • Extend recipes with template php5 php5-dev php5-cgi }.each do |pkg| "/etc/haproxy/haproxy.cfg" do source "haproxy.cfg.erb" source "haproxy.cfg.erb" Ruby. owner "root" package pkg do owner "root" group "root" • action :install group "root" Dynamic configuration end mode 0644 mode 0644 notifies :restart, "service[haproxy]" through search. variables :pool_members => pool_members end end:restart, "service[haproxy]" notifies end
  • 31. Chef Roles name "mediawiki" description "mediawiki app server" run_list( "recipe[mysql::client]", "recipe[application]", "recipe[mediawiki::status]" ) • Roles describe nodes. name "mediawiki_load_balancer" • Roles have a run list. description "mediawiki load balancer" run_list( • Roles can have attributes. ) "recipe[haproxy::app_lb]" override_attributes( "haproxy" => { "app_server_role" => "mediawiki" } )
  • 32. Track it like source code... % git log commit d640a8c6b370134d7043991894107d806595cc35 Author: jtimberman <joshua@opscode.com> Import nagios version 1.0.0 commit c40c818498710e78cf73c7f71e722e971fa574e7 Author: jtimberman <joshua@opscode.com> installation and usage instruction docs commit 99d0efb024314de17888f6b359c14414fda7bb91 Author: jtimberman <joshua@opscode.com> Import haproxy version 1.0.1 commit c89d0975ad3f4b152426df219fee0bfb8eafb7e4 Author: jtimberman <joshua@opscode.com> add mediawiki cookbook commit 89c0545cc03b9be26f1db246c9ba4ce9d58a6700 Author: jtimberman <joshua@opscode.com> multiple environments in data bag for mediawiki
  • 33. Other Chef Terms • Cookbooks are collections of recipes • Environments are pegged cookbook versions • Servers are Nodes • Data bags are JSON blobs
  • 34. Python Cookbook • python::package, python::source — Install Python • python::pip, python::virtualenv — Make it dance • python::default — All of the above! • python_pip, python_virtualenv
  • 35. Installing a package python_virtualenv "/srv/myapp/env" do action :create end python_pip "django" do action :upgrade version "1.3" virtualenv "/srv/myapp/env" end
  • 36. Gunicorn Cookbook • gunicorn::default • gunicorn_config
  • 37. Supervisor Cookbook • supervisor::default • Debian-style for now • supervisor_service
  • 39. Role: base name "base" description "Base role applied to all nodes." run_list( • Install users "recipe[users::sysadmins]", "recipe[sudo]", • "recipe[apt]", Configure sudo ) "recipe[build-essential]" • override_attributes( apt-get update :authorization => { :sudo => { • Install gcc } :users => ["ubuntu"], :passwordless => true } )
  • 40. Recipe: packaginator application "packaginator" do path "/srv/packaginator" owner "nobody" group "nogroup" repository "https://github.com/coderanger/packaginator.git" revision "master" migrate true packages ["libpq-dev", "git-core", "mercurial"] django do packages ["redis"] requirements "requirements/mkii.txt" settings_template "settings.py.erb" debug true database do database "packaginator" • engine "postgresql_psycopg2" The good stuff username "packaginator" password "awesome_password" end database_master_role "packaginator_database_master" • collectstatic "build_static --noinput" end General parameters gunicorn do only_if { node['roles'].include? 'packaginator_application_server' } • app_module :django port 8080 Sub-resources end celery do only_if { node['roles'].include? 'packaginator_application_server' } config "celery_settings.py" django true celerybeat true celerycam true broker do transport "redis" end end nginx_load_balancer do only_if { node['roles'].include? 'packaginator_load_balancer' } application_port 8080 static_files "/site_media" => "site_media" end end
  • 41. Application Resource application "packaginator" do • Who are we? path "/srv/packaginator" • Where are we going? owner "nobody" group "nogroup"
  • 42. Application Resource directory "/srv/packaginator" directory "/srv/packaginator/shared" deploy_revision "packaginator" do deploy_to "/srv/packaginator" owner "nobody" group "nogroup"
  • 43. Application Resource repository "https://github.com/..." • Source code revision "master" • Migration status migrate true packages ["libpq-dev", • Base packages "git-core","mercurial"]
  • 44. Django Resource • Python packages • pip requirements django do packages ["redis"] • Settings file requirements "requirements/mkii.txt" settings_template "settings.py.erb" • Debug mode debug true collectstatic "build_static --noinput" • Static files
  • 45. Django Resource python_pip "redis" execute "pip -E ... -r ..." template "shared/local_settings.py" execute "manage.py build_static"
  • 46. Folder Layout • /srv/myapp • /srv/myapp/shared • /srv/myapp/shared/releases • /srv/myapp/shared/releases/4faedb2ee... • /srv/myapp/shared/releases/9457be295... • ... • /srv/myapp/current
  • 47. Folder Layout • /srv/myapp • ...9457be295/local_settings.py -> ../shared/local_settings.py • /srv/myapp/current -> .../releases/9457be295...
  • 48. Django Resource database do database "packaginator" • Database engine "postgresql_psycopg2" username "packaginator" • Where? password "awesome_password" end database_master_role "packaginator_database_master"
  • 49. Django Resource if node["roles"].include? ... • Check local first node else • Cloud IP! search(:node, "roles:...").first end
  • 50. Gunicorn Resource gunicorn do only_if do • Only on frontends node["roles"].include? ... • Use Django mode end app_module :django • Internal port port 8080 end
  • 51. Gunicorn Resource • Write out config gunicorn_config ... • Symlink it in supervisor_service ... • Load service
  • 52. Celery Resource celery do only_if ... config "celery_settings.py" • Where? django true • Django-mode celerybeat true • Enable all three celerycam true broker do • Broker and results transport "redis" end end
  • 53. Nginx Resource nginx_load_balancer do only_if ... application_port 8080 • Internal port again static_files({ • Static map "/site_media" => "site_media" • URL => path }) end
  • 55. Noah Kantrowitz @kantrn noah@opscode.com