Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Application deployment with Chef
Search
Igor Afonov
November 22, 2012
Programming
1.1k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Application deployment with Chef
Agile tour Riga 2012
Igor Afonov
November 22, 2012
More Decks by Igor Afonov
See All by Igor Afonov
Real-time application monitoring
iafonov
5
1k
Web servers - and how I created my own one
iafonov
8
1.2k
Chef - Infrastructure as code
iafonov
6
690
Other Decks in Programming
See All in Programming
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
340
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
1k
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
180
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
170
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
7.2k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
240
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
470
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
1k
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
170
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
190
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Webフレームワークの ベンチマークについて
yusukebe
0
190
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.1k
A Soul's Torment
seathinner
6
3k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
440
The agentic SEO stack - context over prompts
schlessera
0
840
HDC tutorial
michielstock
2
730
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
300
Leo the Paperboy
mayatellez
8
1.9k
WCS-LA-2024
lcolladotor
0
670
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
240
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
First, design no harm
axbom
PRO
2
1.2k
Producing Creativity
orderedlist
PRO
348
40k
Transcript
Application deployment with Chef Igor Afonov
‣ Ruby developer ‣ I’m participating in Chef development Developers
Sys Admins DevOps I’m here About Me
Configuration Management Chef Quick Intro Application Deployment FAQ Q &
A Agenda
Configuration Management
"Keep track of all the stuff you do to take
a system from 'bare metal' to 'doing its job'." - Adam Jacob
๏ Remember everything ๏ Keep notes in notepad ๏ Maintain
wiki ๏ Bash scripts ๏ Automation frameworks
Opscode Chef
๏ Configuration management framework ๏ Open source ๏ Created by
Adam Jacob ๏ Maintained by Opscode
๏ Client-server architecture ๏ Idempotence ๏ Declarative ๏ Ruby everywhere
Crash course
chef-server push pull VCS chef-client node chef-client node chef-client node
server chef repository developer Workflow
cookbook recipe chef-repository resource resource resource Code structure
Resource
package 'apache2' do action :install provider Chef::Provider::Package::Apt version '2.4' end
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
Provider
package apt pacman macports Resource Providers Interface Implementation
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
Recipe
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
Cookbook
cookbook |-attributes |-files |-libraries |-recipes |-templates |---metadata.rb
๏ Cookbooks should be data-driven ๏ Do not hardcode anything
๏ Control behavior via: ๏ Attributes ๏ Databags ๏ Search
Node
๏ Host that runs chef-client ๏ Has attributes ๏ Has
run list
Role
name "mail-server" description "Installs and configures postfix MTA" default_attributes :postfix
=> { "mydomain" => "domain.com", "myorigin" => "domain.com" } run_list "recipe[postfix]"
Chef repository
chef-repo |-cookbooks |-data_bags |-roles |-environments |---Rakefile https://github.com/opscode/chef-repo
chef-server push pull VCS chef-client node chef-client node chef-client node
server chef repository developer The big picture
๏ Authenticate node ๏ Synchronize cookbooks ๏ Compile ๏ Converge
chef-client run
๏ 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
Deployment
๏ Get the code from VCS ๏ Put the code
to the right place ๏ Do some rituals Three easy* steps * Not true
Real-world example
internet nginx unicorn unicorn unicorn Simple Rails deployment
Get the code & put it to the right place
application 'copycopter' do repository '
[email protected]
:iafonov/copycopter-server.git' revision 'master' path '/var/www/apps/copycopter' end
Pick the SCM strategy application 'copycopter' do repository '
[email protected]
:iafonov/copycopter-server.git' revision
'master' path '/var/www/apps/copycopter' strategy :deploy_revision # :deploy_timestamped end
Set the code owner application 'copycopter' do repository '
[email protected]
:iafonov/copycopter-server.git' revision
'master' path '/var/www/apps/copycopter' strategy :deploy_revision owner 'deploy' group 'deploy' end
Install library dependencies application 'copycopter' do repository '
[email protected]
:iafonov/copycopter-server.git' revision 'master'
path '/var/www/apps/copycopter' strategy :deploy_revision owner 'deploy' group 'deploy' packages ['libxml2-dev', 'libxslt-dev'] end
Run migrations application 'copycopter' do repository '
[email protected]
: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
Restart service application 'copycopter' do repository '
[email protected]
: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
๏ rails ๏ java_webapp ๏ tomcat ๏ django ๏ ...
Sub-resources
Rails application 'copycopter' do ... rails do gems ['bundler'] database
do username node['mysql']['username'] password node['mysql']['password'] database 'copycopter_production' end end end
Unicorn application 'copycopter' do ... rails do ... end unicorn
do worker_processes 4 port 8080 end end
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
๏ before_deploy ๏ before_migrate ๏ before_symlink ๏ before_restart ๏ after_restart
Callbacks
Run backups application 'copycopter' do ... before_deploy do execute 'run_backups'
do command 'rsync ....' end end end
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
๏ 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
FAQ
When you should automate your infrastructure?
Which tool should you use?
What are benefits of using automation tools?
Q & A
[email protected]
http://iafonov.github.com @iafonov
Thank You!
[email protected]
http://iafonov.github.com @iafonov