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
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
440
初めてのKubernetes 本番運用でハマった話
oku053
0
130
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
170
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
130
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
えっ!!コードを読まずに開発を!?
hananouchi
0
220
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
590
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.9k
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
140
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
510
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
140
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
170
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
470
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
350
The Language of Interfaces
destraynor
162
27k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.4k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
320
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
630
Evolving SEO for Evolving Search Engines
ryanjones
0
240
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
390
Making Projects Easy
brettharned
120
6.7k
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