Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Application deployment with Chef
Igor Afonov
November 22, 2012
Programming
6
600
Application deployment with Chef
Agile tour Riga 2012
Igor Afonov
November 22, 2012
Tweet
Share
More Decks by Igor Afonov
See All by Igor Afonov
Real-time application monitoring
iafonov
5
900
Web servers - and how I created my own one
iafonov
8
960
Chef - Infrastructure as code
iafonov
6
520
Other Decks in Programming
See All in Programming
Kueue入門/Kueue Introduction
bells17
0
510
Becoming an Android Librarian
skydoves
3
450
Kotlin KSP - Intro
taehwandev
1
470
dbtとBigQueryで始めるData Vault入門
kazk1018
0
180
Hapticをカスタマイズしてみよう / ZOZO Tech Talk #6 Customize Haptic
endoumari
0
270
Enterprise Angular: Frontend Moduliths with Nx and Standalone Components @jax2022
manfredsteyer
PRO
0
290
SPA/MPA 議論の俯瞰と 現代における設計のポイント - #tfcon 2022 フロントエンド設計
ahomu
3
1.6k
実録mruby組み込み体験
coe401_
0
100
スモールチームがAmazon Cognitoでコスパよく作るサービス間連携認証
tacke_jp
2
290
Git Rebase
bkuhlmann
7
1k
書籍『良いコード/悪いコードで学ぶ設計入門』でエンジニアリングの当たり前を変える
minodriven
3
1.1k
よりUXに近いSLI・SLOの運用による可用性の再設計
kazumanagano
3
480
Featured
See All Featured
Clear Off the Table
cherdarchuk
79
280k
Infographics Made Easy
chrislema
233
17k
Mobile First: as difficult as doing things right
swwweet
212
7.5k
Building Applications with DynamoDB
mza
83
4.6k
Automating Front-end Workflow
addyosmani
1351
200k
Principles of Awesome APIs and How to Build Them.
keavy
113
15k
Typedesign – Prime Four
hannesfritz
33
1.3k
Large-scale JavaScript Application Architecture
addyosmani
499
110k
4 Signs Your Business is Dying
shpigford
169
20k
Agile that works and the tools we love
rasmusluckow
319
19k
jQuery: Nuts, Bolts and Bling
dougneiner
56
6.4k
Building Your Own Lightsaber
phodgson
94
4.6k
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 'git@github.com:iafonov/copycopter-server.git' revision 'master' path '/var/www/apps/copycopter' end
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
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
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
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
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
๏ 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 afonov@gmail.com http://iafonov.github.com @iafonov
Thank You! afonov@gmail.com http://iafonov.github.com @iafonov