Application deployment with Chef

Dd13a61bab3fe4243f3ebc683f9219eb?s=47 Igor Afonov
November 22, 2012

Application deployment with Chef

Agile tour Riga 2012

Dd13a61bab3fe4243f3ebc683f9219eb?s=128

Igor Afonov

November 22, 2012
Tweet

Transcript

  1. 5.

    "Keep track of all the stuff you do to take

    a system from 'bare metal' to 'doing its job'." - Adam Jacob
  2. 6.

    ๏ Remember everything ๏ Keep notes in notepad ๏ Maintain

    wiki ๏ Bash scripts ๏ Automation frameworks
  3. 13.
  4. 15.

    Cookbook File Cron Deploy Directory Env Execute* File Git Group

    HTTP Request Ifconfig Link Log Mount Ohai Package PowerShell Script User Remote Directory Remote File Route Ruby Block SCM Script Service Subversion Template Bundled resources
  5. 16.
  6. 18.

    service "redis" do action :start end Method call Parameter1 Parameter2

    # lib/chef/platform.rb - Chef::Platform :macosx => { :default => { ... :package => Chef::Provider::Package::Macports, :service => Chef::Provider::Service::Macosx, ... } } # lib/chef/provider/service/macosx.rb class Chef::Provider::Service::Macosx < Chef::Provider::Service::Simple def start if @current_resource.running Chef::Log.debug("#{@new_resource} already running, not starting") else shell_out!("launchctl load -w '#{@plist}'") end end end
  7. 19.
  8. 20.

    package "postfix" do action :install end %w{main master}.each do |config|

    template "/etc/postfix/#{config}.cf" do source "#{config}.cf.erb" owner "root" group "root" mode 0644 end end
  9. 21.
  10. 23.

    ๏ Cookbooks should be data-driven ๏ Do not hardcode anything

    ๏ Control behavior via: ๏ Attributes ๏ Databags ๏ Search
  11. 24.
  12. 26.
  13. 27.

    name "mail-server" description "Installs and configures postfix MTA" default_attributes :postfix

    => { "mydomain" => "domain.com", "myorigin" => "domain.com" } run_list "recipe[postfix]"
  14. 30.

    chef-server push pull VCS chef-client node chef-client node chef-client node

    server chef repository developer The big picture
  15. 32.

    ๏ Resource is a unit of work ๏ Provider take

    real action ๏ Recipe is collection of resources ๏ Cookbook is reusable set of recipes ๏ Code is pushed to chef-server ๏ Node pulls code from chef-server and runs it Recap
  16. 34.

    ๏ Get the code from VCS ๏ Put the code

    to the right place ๏ Do some rituals Three easy* steps * Not true
  17. 37.

    Get the code & put it to the right place

    application 'copycopter' do repository 'git@github.com:iafonov/copycopter-server.git' revision 'master' path '/var/www/apps/copycopter' end
  18. 38.

    Pick the SCM strategy application 'copycopter' do repository 'git@github.com:iafonov/copycopter-server.git' revision

    'master' path '/var/www/apps/copycopter' strategy :deploy_revision # :deploy_timestamped end
  19. 39.

    Set the code owner application 'copycopter' do repository 'git@github.com:iafonov/copycopter-server.git' revision

    'master' path '/var/www/apps/copycopter' strategy :deploy_revision owner 'deploy' group 'deploy' end
  20. 40.

    Install library dependencies application 'copycopter' do repository 'git@github.com:iafonov/copycopter-server.git' revision 'master'

    path '/var/www/apps/copycopter' strategy :deploy_revision owner 'deploy' group 'deploy' packages ['libxml2-dev', 'libxslt-dev'] end
  21. 41.

    Run migrations application 'copycopter' do repository 'git@github.com:iafonov/copycopter-server.git' revision 'master' path

    '/var/www/apps/copycopter' strategy :deploy_revision owner 'deploy' group 'deploy' packages ['libxml2-dev', 'libxslt-dev'] migrate true end
  22. 42.

    Restart service application 'copycopter' do repository 'git@github.com:iafonov/copycopter-server.git' revision 'master' path

    '/var/www/apps/copycopter' strategy :deploy_revision owner 'deploy' group 'deploy' packages ['libxml2-dev', 'libxslt-dev'] migrate true restart_command 'service copycopter restart' end
  23. 44.

    Rails application 'copycopter' do ... rails do gems ['bundler'] database

    do username node['mysql']['username'] password node['mysql']['password'] database 'copycopter_production' end end end
  24. 45.
  25. 46.

    nginx application 'copycopter' do ... rails do ... end unicorn

    do ... end nginx_load_balancer do static_files '/public' => 'public' application_server_role 'copycopter_app_server' end end
  26. 49.

    Notify monitoring system application 'copycopter' do ... before_deploy do execute

    'run_backups' do command 'rsync ....' end end after_restart do StatsD.gauge("#{node.name}.deploy") end end
  27. 50.

    ๏ Chef allows declaratively describe deploy process ๏ A lot

    of technology stacks are supported via sub-resources ๏ You can precisely control each step of process Recap
  28. 51.

    FAQ