180
Michelin Starred Cooking with Chef Jon Cowie, Etsy.com [email protected] @jonlives

Michelin Starred Cooking with Chef

Embed Size (px)

Citation preview

Page 1: Michelin Starred Cooking with Chef

Michelin Starred Cooking with Chef

Jon Cowie, [email protected]

@jonlives

Page 2: Michelin Starred Cooking with Chef

What?

Page 3: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

Page 4: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

• Familiarity and Understanding

Page 5: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

• Familiarity and Understanding

• Critical Approach and Experimentation

Page 6: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

• Familiarity and Understanding

• Critical Approach and Experimentation

• Use The Source

Page 7: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

• Familiarity and Understanding

• Critical Approach and Experimentation

• Use The Source

• A liberal sprinkling of screwups

Page 8: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

• Familiarity and Understanding

• Critical Approach and Experimentation

• Use The Source

• A liberal sprinkling of screwups

• Open Sourced Goodness - We’re all here!

Page 9: Michelin Starred Cooking with Chef

What?

• Chef at Etsy

• Familiarity and Understanding

• Critical Approach and Experimentation

• Use The Source

• A liberal sprinkling of screwups

• Open Sourced Goodness - We’re all here!

• [x] = http://tiny.cc/velocity2012

Page 10: Michelin Starred Cooking with Chef

Opscode is Orange,Velocity is Blue.In Soviet Russia,

Cookbook writes you.

Page 11: Michelin Starred Cooking with Chef

Chef at Etsy

Page 12: Michelin Starred Cooking with Chef

Our Setup

Page 13: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

Page 14: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

• Backup to Opscode Platform

Page 15: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

• Backup to Opscode Platform

• ~800 self-hosted nodes (Mainly CentOS, some RHEL & mac)

Page 16: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

• Backup to Opscode Platform

• ~800 self-hosted nodes (Mainly CentOS, some RHEL & mac)

• KVM & lxc virts, self hosted too.

Page 17: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

• Backup to Opscode Platform

• ~800 self-hosted nodes (Mainly CentOS, some RHEL & mac)

• KVM & lxc virts, self hosted too.

• Never test in production!

Page 18: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

• Backup to Opscode Platform

• ~800 self-hosted nodes (Mainly CentOS, some RHEL & mac)

• KVM & lxc virts, self hosted too.

• Never test in production!

• Many chefs don’t spoil our soup

Page 19: Michelin Starred Cooking with Chef

Our Setup• Open Source chef server 0.10.4

• Backup to Opscode Platform

• ~800 self-hosted nodes (Mainly CentOS, some RHEL & mac)

• KVM & lxc virts, self hosted too.

• Never test in production!

• Many chefs don’t spoil our soup

Page 20: Michelin Starred Cooking with Chef

Familiarity and Understanding

Page 22: Michelin Starred Cooking with Chef
Page 23: Michelin Starred Cooking with Chef

• Insight

Page 24: Michelin Starred Cooking with Chef

• Insight

• Simplicity

Page 25: Michelin Starred Cooking with Chef

• Insight

• Simplicity

• Standards

Page 26: Michelin Starred Cooking with Chef

Insight

Page 27: Michelin Starred Cooking with Chef

Insight

• You should never have to say “I don’t know.”

Page 28: Michelin Starred Cooking with Chef

Insight

• You should never have to say “I don’t know.”

• What, where, when, why, how long?

Page 29: Michelin Starred Cooking with Chef

Insight

• You should never have to say “I don’t know.”

• What, where, when, why, how long?

• Easy, and I’ll show you how!

Page 30: Michelin Starred Cooking with Chef
Page 31: Michelin Starred Cooking with Chef

Chef Dashboard

Page 32: Michelin Starred Cooking with Chef

Chef Dashboard• Chef handler sends metrics to graphite [4]

Page 33: Michelin Starred Cooking with Chef

Chef Dashboard• Chef handler sends metrics to graphite [4]• git clone git://github.com/etsy/chef-handlers.git

Page 34: Michelin Starred Cooking with Chef

Chef Dashboard• Chef handler sends metrics to graphite [4]• git clone git://github.com/etsy/chef-handlers.git

• Set your graphite server’s URL in graphite.rb

Page 35: Michelin Starred Cooking with Chef

Chef Dashboard• Chef handler sends metrics to graphite [4]• git clone git://github.com/etsy/chef-handlers.git

• Set your graphite server’s URL in graphite.rb

• Add the following to client.rb

Page 36: Michelin Starred Cooking with Chef

Chef Dashboard• Chef handler sends metrics to graphite [4]• git clone git://github.com/etsy/chef-handlers.git

• Set your graphite server’s URL in graphite.rb

• Add the following to client.rb• require "<clonedir>/graphite.rb"

graphite_handler = GraphiteReporting.newreport_handlers << graphite_handlerexception_handlers << graphite_handler

Page 37: Michelin Starred Cooking with Chef

Chef Dashboard• Chef handler sends metrics to graphite [4]• git clone git://github.com/etsy/chef-handlers.git

• Set your graphite server’s URL in graphite.rb

• Add the following to client.rb• require "<clonedir>/graphite.rb"

graphite_handler = GraphiteReporting.newreport_handlers << graphite_handlerexception_handlers << graphite_handler

• Etsy dashboards framework [5]

Page 38: Michelin Starred Cooking with Chef

[12:54:01] <irccat> Chef run failed on gfernandez.vm.ny4dev.etsy.com[12:54:02] <irccat> https://github.etsycorp.com/gist/384228[12:54:02] <irccat>

[12:54:07] <irccat> Chef run failed on buildtest11.ny4dev.etsy.com[12:54:07] <irccat> https://github.etsycorp.com/gist/384227[12:54:07] <irccat>

Page 39: Michelin Starred Cooking with Chef

Chef irccat Alerts

Page 40: Michelin Starred Cooking with Chef

Chef irccat Alerts

• Chef handler send fails to irc[4] via irccat [6]

Page 41: Michelin Starred Cooking with Chef

Chef irccat Alerts

• Chef handler send fails to irc[4] via irccat [6]• git clone git://github.com/etsy/chef-handlers.git

Page 42: Michelin Starred Cooking with Chef

Chef irccat Alerts

• Chef handler send fails to irc[4] via irccat [6]• git clone git://github.com/etsy/chef-handlers.git

• Set your irccat[6] server’s URL in logtoirc.rb

Page 43: Michelin Starred Cooking with Chef

Chef irccat Alerts

• Chef handler send fails to irc[4] via irccat [6]• git clone git://github.com/etsy/chef-handlers.git

• Set your irccat[6] server’s URL in logtoirc.rb

• Add the following to client.rb

Page 44: Michelin Starred Cooking with Chef

Chef irccat Alerts

• Chef handler send fails to irc[4] via irccat [6]• git clone git://github.com/etsy/chef-handlers.git

• Set your irccat[6] server’s URL in logtoirc.rb

• Add the following to client.rb• require "<clonedir>/logtoirc.rb"

exception_handlers << Etsy::LogToIRC.new

Page 45: Michelin Starred Cooking with Chef

~ > knife node lastrun buildtest11.ny4dev.etsy.comStatus failed Elapsed Time 4.628171438 Start Time 2012-06-18 10:06:28 +0000End Time 2012-06-18 10:06:32 +0000

Recipe Action Resource Type Resource

Backtrace<snip>

ExceptionChef::Exceptions::Package: package[php] (php::buildtest line 20) had an error: Version 5.3.10-1.el5 of php not found. Did you specify both version and release? (version-release, e.g. 1.84-10.fc6)

Page 46: Michelin Starred Cooking with Chef

~ > knife search node 'lastrun_debug_formatted_exception:Chef\:\:Exceptions\:\:Package*' -a lastrun.debug.formatted_exception

5 items found

id: masterrestore.ny4.etsy.comlastrun.debug.formatted_exception: Chef::Exceptions::Package: package[postgresql-server] (postgresql::server-8.3 line 1) had an error: Installed package postgresql-server-8.3.16-1PGDG_id is newer than candidate package postgresql-server-8.3.11-1PGDG_id.rhel5

id: buildtest11.ny4dev.etsy.comlastrun.debug.formatted_exception: Chef::Exceptions::Package: package[php] (php::buildtest line 20) had an error: Version 5.3.10-1.el5 of php not found. Did you specify both version and release? (version-release, e.g. 1.84-10.fc6)

<snip>

Page 47: Michelin Starred Cooking with Chef

Chef lastrun Info

Page 48: Michelin Starred Cooking with Chef

Chef lastrun Info

• Chef handler and knife plugin [7]

Page 49: Michelin Starred Cooking with Chef

Chef lastrun Info

• Chef handler and knife plugin [7]

• gem install knife-lastrun

Page 50: Michelin Starred Cooking with Chef

Chef lastrun Info

• Chef handler and knife plugin [7]

• gem install knife-lastrun

• Add the following to client.rb

Page 51: Michelin Starred Cooking with Chef

Chef lastrun Info

• Chef handler and knife plugin [7]

• gem install knife-lastrun

• Add the following to client.rb• require "lastrun_update"

handler = LastRunUpdateHandler.newreport_handlers << handlerexception_handlers << handler

Page 52: Michelin Starred Cooking with Chef

Chef lastrun Info

• Chef handler and knife plugin [7]

• gem install knife-lastrun

• Add the following to client.rb• require "lastrun_update"

handler = LastRunUpdateHandler.newreport_handlers << handlerexception_handlers << handler

• knife node lastrun <nodename>

Page 53: Michelin Starred Cooking with Chef

Simplicity

Page 54: Michelin Starred Cooking with Chef

Simplicity

• Think of yourself at 3AM!

Page 55: Michelin Starred Cooking with Chef

Simplicity

• Think of yourself at 3AM!

• Please, won’t you think of the new guy?

Page 56: Michelin Starred Cooking with Chef

Simplicity

• Think of yourself at 3AM!

• Please, won’t you think of the new guy?

• Minimize the logics!

Page 57: Michelin Starred Cooking with Chef

Simplicity

• Think of yourself at 3AM!

• Please, won’t you think of the new guy?

• Minimize the logics!

• As few logical steps from start to finish as possible.

Page 58: Michelin Starred Cooking with Chef

Simplicity - Not!Date: Mon Dec 05 2011 23:07:18 GMT+0000 (GMT)

Subject: so close to death

# Don't install v2 on search or Cent 5.6 nodes-if node[:fqdn] !~ /\b(^(preprod-)?search[0-9]{2}|ny4dev\.etsy\.com|^(preprod-)?giftsweb[0-9]{2}|^db(shard|spare|data)[0-9]{2}|^qa-web01|^devsearch[0-9]{2}|^nagios01|^webnest[0-9]{2}|^prodking[0-9]{2}|^sandboxweb[0-9]{2}|^virt((0[5-9])|(1[0-9]))|^msysmgr[0-9]{2}|^msysmta[0-9]{2}|^dbconvo[0-9]{2}|^dbshowcase01|atlasweb[0-9]{2}|devnagios[0-9]{2}|cimaster02|worker[0-9]{2}|^ganglia[0-9]{2}|^imgcache[0-9]{2}|imgconvert[0-9]{2}|^imgwriter[0-9]{2}|dev-img02|^datacache04|^graphite01|^graphite03|^webutil03|^webutil04|^statsd01|^maintweb[0-9]{2}|^(dev-|preprod-)?convosearch[0-9]{2}|deployinator[0-9]{2}|^wpadmin01|^(preprod-)?dbtasks[0-9]{2})\b/ and node.role?("Web56") == false and node.role?("Preprodweb56") == false and node.role?("Princess53") == false+if node[:fqdn] !~ /\b(^(preprod-)?search[0-9]{2}|ny4dev\.etsy\.com|^(preprod-)?giftsweb[0-9]{2}|^db(shard|spare|data)[0-9]{2}|^qa-web01|^devsearch[0-9]{2}|^nagios01|^webnest[0-9]{2}|^prodking[0-9]{2}|^sandboxweb[0-9]{2}|^virt((0[5-9])|(1[0-9]))|^msysmgr[0-9]{2}|^msysmta[0-9]{2}|^dbconvo[0-9]{2}|^dbshowcase01|atlasweb[0-9]{2}|devnagios[0-9]{2}|cimaster02|worker[0-9]{2}|^ganglia[0-9]{2}|^imgcache[0-9]{2}|imgconvert[0-9]{2}|^imgwriter[0-9]{2}|dev-img02|^datacache04|^graphite01|^graphite03|^webutil03|^webutil04|^statsd01|^maintweb[0-9]{2}|^(dev-|preprod-)?convosearch[0-9]{2}|deployinator[0-9]{2}|^wpadmin01|^(preprod-)?dbtasks[0-9]{2})\b/ and node.role?("Web56") == false and node.role?("Preprodweb56") == false and node.role?("Princess53") == false and node.role?("Auth") == false

Page 59: Michelin Starred Cooking with Chef

Simplicity - Better!if node.chef_environment == "libmemcached_upgrade"

package "libmemcached" do

version "1.0.4-1"

action :install

end

<snip>

else

package "libmemcached" do

version "0.53-1.1"

action :install

end

<snip>

end

Page 60: Michelin Starred Cooking with Chef

Simplicity - Complexity

Page 61: Michelin Starred Cooking with Chef

Simplicity - Complexity

• Sometimes you need complex behaviour

Page 62: Michelin Starred Cooking with Chef

Simplicity - Complexity

• Sometimes you need complex behaviour

• Don’t fight it, try to abstract it.

Page 63: Michelin Starred Cooking with Chef

Simplicity - Complexity

• Sometimes you need complex behaviour

• Don’t fight it, try to abstract it.

• Case in point: Syslog-ng refactor

Page 64: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

Page 65: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• 36 recipes

Page 66: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• 36 recipes

• 30 versions of syslog-ng.conf

Page 67: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• 36 recipes

• 30 versions of syslog-ng.conf

• 27 manually configured files in /etc/syslog-ng.d on central server

Page 68: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• 36 recipes

• 30 versions of syslog-ng.conf

• 27 manually configured files in /etc/syslog-ng.d on central server

• Edge cases and exceptions galore

Page 69: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

Page 70: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• Down to:

Page 71: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• Down to:

• 2 recipes (one client, one server)

Page 72: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• Down to:

• 2 recipes (one client, one server)

• 2 templates (one for syslog-ng.conf, one for stuff in /etc/syslog-ng.d)

Page 73: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• Down to:

• 2 recipes (one client, one server)

• 2 templates (one for syslog-ng.conf, one for stuff in /etc/syslog-ng.d)

• Attributes in roles

Page 74: Michelin Starred Cooking with Chef

Case Study: Syslog-ng

• Down to:

• 2 recipes (one client, one server)

• 2 templates (one for syslog-ng.conf, one for stuff in /etc/syslog-ng.d)

• Attributes in roles

• Not open sourced yet, sorry :(

Page 75: Michelin Starred Cooking with Chef

Case Study: Syslog-ng"syslog": {

"group": "preprod_web",

"items": {

"web_apache_access_log": {

"source": "/var/log/httpd/access_log",

"source_program_override": "APACHEACCESS: ",

"destination": "<snip>/access.log",

"destination_filters": [

"host('^preprod-web')",

"match('APACHEACCESS')"

],

"destination_options": [

"template_escape(no)"

]

},

}

}

Page 76: Michelin Starred Cooking with Chef

Remember, No Panacea!

Page 77: Michelin Starred Cooking with Chef

Remember, No Panacea!

• A new package hits the repo.

Page 78: Michelin Starred Cooking with Chef

Remember, No Panacea!

• A new package hits the repo.

• Are you in control of when it goes out?

Page 79: Michelin Starred Cooking with Chef

Remember, No Panacea!

• A new package hits the repo.

• Are you in control of when it goes out?

• Memcached Outage

Page 80: Michelin Starred Cooking with Chef

Remember, No Panacea!

• A new package hits the repo.

• Are you in control of when it goes out?

• Memcached Outage

• Do you know what services are going to restart and when?

Page 81: Michelin Starred Cooking with Chef

Remember, No Panacea!

• A new package hits the repo.

• Are you in control of when it goes out?

• Memcached Outage

• Do you know what services are going to restart and when?

• Image Service Outage

Page 82: Michelin Starred Cooking with Chef

Standards

Page 83: Michelin Starred Cooking with Chef

Standards

• Not going to talk about testing [8]!

Page 84: Michelin Starred Cooking with Chef

Standards

• Not going to talk about testing [8]!

• But I don’t have time for standards!

Page 85: Michelin Starred Cooking with Chef

Standards - No Time!

Page 86: Michelin Starred Cooking with Chef

Standards - No Time!

• I won’t say “Make Time”, but you should...

Page 87: Michelin Starred Cooking with Chef

Standards - No Time!

• I won’t say “Make Time”, but you should...

• For a quick win, try Foodcritic

Page 88: Michelin Starred Cooking with Chef

Standards - No Time!

• I won’t say “Make Time”, but you should...

• For a quick win, try Foodcritic

• Good out of the box rules

Page 89: Michelin Starred Cooking with Chef

Standards - No Time!

• I won’t say “Make Time”, but you should...

• For a quick win, try Foodcritic

• Good out of the box rules

• Jenkins integration in seconds

Page 90: Michelin Starred Cooking with Chef

Standards - No Time!

• I won’t say “Make Time”, but you should...

• For a quick win, try Foodcritic

• Good out of the box rules

• Jenkins integration in seconds

• Supports custom rules

Page 91: Michelin Starred Cooking with Chef

Standards - No Time!

• I won’t say “Make Time”, but you should...

• For a quick win, try Foodcritic

• Good out of the box rules

• Jenkins integration in seconds

• Supports custom rules

• Plays well with others

Page 92: Michelin Starred Cooking with Chef

Foodcritic

Page 93: Michelin Starred Cooking with Chef

Foodcritic•gem install foodcritic

Page 94: Michelin Starred Cooking with Chef

Foodcritic•gem install foodcritic

•foodcritic <cookbook_repo>

Page 95: Michelin Starred Cooking with Chef

Foodcritic•gem install foodcritic

•foodcritic <cookbook_repo>

•Simple Jenkins job:

Page 96: Michelin Starred Cooking with Chef

Foodcritic•gem install foodcritic

•foodcritic <cookbook_repo>

•Simple Jenkins job:

#!/usr/bin/env rvm-shell 1.9.3foodcritic -f correctness .

Page 97: Michelin Starred Cooking with Chef

Standards at Etsy

Page 98: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

Page 99: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

Page 100: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

Page 101: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

• ETSY003 - Execute resource used to run curl or wget commands

Page 102: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

• ETSY003 - Execute resource used to run curl or wget commands

• ETSY004 - Execute resource defined without conditional or action :nothing

Page 103: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

• ETSY003 - Execute resource used to run curl or wget commands

• ETSY004 - Execute resource defined without conditional or action :nothing

• ETSY005 - Action :restart sent to a core service

Page 104: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

• ETSY003 - Execute resource used to run curl or wget commands

• ETSY004 - Execute resource defined without conditional or action :nothing

• ETSY005 - Action :restart sent to a core service

• ETSY006 - Execute resource used to run chef-provided command

Page 105: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

• ETSY003 - Execute resource used to run curl or wget commands

• ETSY004 - Execute resource defined without conditional or action :nothing

• ETSY005 - Action :restart sent to a core service

• ETSY006 - Execute resource used to run chef-provided command

• ETSY007 - Package or yum_package resource used to install core package without specific version number

Page 106: Michelin Starred Cooking with Chef

Standards at Etsy• “style” not “correctness”[9]

• ETSY001 - Package or yum_package resource used with :upgrade action

• ETSY002 - Execute resource used to run git commands

• ETSY003 - Execute resource used to run curl or wget commands

• ETSY004 - Execute resource defined without conditional or action :nothing

• ETSY005 - Action :restart sent to a core service

• ETSY006 - Execute resource used to run chef-provided command

• ETSY007 - Package or yum_package resource used to install core package without specific version number

Page 107: Michelin Starred Cooking with Chef

Standards at Etsy

Page 108: Michelin Starred Cooking with Chef

Standards at Etsy

• ETSY001 - Written after Memcached Outage

Page 109: Michelin Starred Cooking with Chef

Standards at Etsy

• ETSY001 - Written after Memcached Outage

• Package or yum_package resource used with :upgrade action

Page 110: Michelin Starred Cooking with Chef

Standards at Etsy

• ETSY001 - Written after Memcached Outage

• Package or yum_package resource used with :upgrade action

•package "memcached" do action :upgradeend

Page 111: Michelin Starred Cooking with Chef

Standards at Etsy

Page 112: Michelin Starred Cooking with Chef

Standards at Etsy

• ETSY005 - Written after a total Image service outage

Page 113: Michelin Starred Cooking with Chef

Standards at Etsy

• ETSY005 - Written after a total Image service outage

• Action :restart sent to a core service

Page 114: Michelin Starred Cooking with Chef

Standards at Etsy

• ETSY005 - Written after a total Image service outage

• Action :restart sent to a core service• cookbook_file "/etc/httpd/conf.d/myvhost.conf" do

source "myvhost.conf" notifies :restart, resources(:service => "httpd")end

Page 115: Michelin Starred Cooking with Chef

Critical Approach and Experimentation

Page 116: Michelin Starred Cooking with Chef

CA&E

Page 117: Michelin Starred Cooking with Chef

CA&E

• Chef is by necessity generic

Page 118: Michelin Starred Cooking with Chef

CA&E

• Chef is by necessity generic

• ...so don’t take Opscode’s word for it.

Page 119: Michelin Starred Cooking with Chef

CA&E

• Chef is by necessity generic

• ...so don’t take Opscode’s word for it.

• If it doesn’t work well for you, change it!

Page 120: Michelin Starred Cooking with Chef

CA&E

• Chef is by necessity generic

• ...so don’t take Opscode’s word for it.

• If it doesn’t work well for you, change it!

• Case Study - Etsy Environments rollout

Page 121: Michelin Starred Cooking with Chef

Environments Rollout

Page 122: Michelin Starred Cooking with Chef

Environments Rollout

• We knew we needed them

Page 123: Michelin Starred Cooking with Chef

Environments Rollout

• We knew we needed them

• Simple enough, right?

Page 124: Michelin Starred Cooking with Chef

Environments Rollout

• We knew we needed them

• Simple enough, right?

• Let’s look at the workflow...

Page 125: Michelin Starred Cooking with Chef

Env: Standard Workflow

Page 126: Michelin Starred Cooking with Chef

Env: Standard Workflow

• knife cookbook show php

Page 127: Michelin Starred Cooking with Chef

Env: Standard Workflow

• knife cookbook show php

• Change version number in metadata.rb

Page 128: Michelin Starred Cooking with Chef

Env: Standard Workflow

• knife cookbook show php

• Change version number in metadata.rb

• Change version constraint in foo.json

Page 129: Michelin Starred Cooking with Chef

Env: Standard Workflow

• knife cookbook show php

• Change version number in metadata.rb

• Change version constraint in foo.json

• Commit and push changes to git

Page 130: Michelin Starred Cooking with Chef

Env: Standard Workflow

• knife cookbook show php

• Change version number in metadata.rb

• Change version constraint in foo.json

• Commit and push changes to git

• knife cookbook upload php --freeze

Page 131: Michelin Starred Cooking with Chef

Env: Standard Workflow

• knife cookbook show php

• Change version number in metadata.rb

• Change version constraint in foo.json

• Commit and push changes to git

• knife cookbook upload php --freeze

• knife environment from file foo.json

Page 132: Michelin Starred Cooking with Chef

Env: Our Issues

Page 133: Michelin Starred Cooking with Chef

Env: Our Issues

• 41 people with Chef repo access

Page 134: Michelin Starred Cooking with Chef

Env: Our Issues

• 41 people with Chef repo access

• Most with knife keys

Page 135: Michelin Starred Cooking with Chef

Env: Our Issues

• 41 people with Chef repo access

• Most with knife keys

• All editing the same 2 files with every change...

Page 136: Michelin Starred Cooking with Chef

Env: Solutions?

Page 137: Michelin Starred Cooking with Chef

Env: Solutions?

• Go with it and hope for the best?

Page 138: Michelin Starred Cooking with Chef

Env: Solutions?

• Go with it and hope for the best?

• Don’t use environments?

Page 139: Michelin Starred Cooking with Chef

Env: Solutions?

• Go with it and hope for the best?

• Don’t use environments?

• Write a totally new workflow?

Page 140: Michelin Starred Cooking with Chef

Env: Solutions?

• Go with it and hope for the best?

• Don’t use environments?

• Write a totally new workflow?

• Tweak the existing one with some tooling?

Page 141: Michelin Starred Cooking with Chef

Env: Solution!

Page 142: Michelin Starred Cooking with Chef

Env: Solution!

• Tweak with some tooling!

Page 143: Michelin Starred Cooking with Chef

Env: Solution!

• Tweak with some tooling!

• Presenting knife-spork [10]...

Page 144: Michelin Starred Cooking with Chef

Spork: Workflow

Page 145: Michelin Starred Cooking with Chef

Spork: Workflow

• Wrapper around standard environments workflow

Page 146: Michelin Starred Cooking with Chef

Spork: Workflow

• Wrapper around standard environments workflow

• check - cookbook versioning

Page 147: Michelin Starred Cooking with Chef

Spork: Workflow

• Wrapper around standard environments workflow

• check - cookbook versioning

• bump - increment version component

Page 148: Michelin Starred Cooking with Chef

Spork: Workflow

• Wrapper around standard environments workflow

• check - cookbook versioning

• bump - increment version component

• upload - upload and freeze

Page 149: Michelin Starred Cooking with Chef

Spork: Workflow

• Wrapper around standard environments workflow

• check - cookbook versioning

• bump - increment version component

• upload - upload and freeze

• promote - set env constraints

Page 150: Michelin Starred Cooking with Chef

Spork: Check$> knife spork check apache2

Checking versions for cookbook apache2...

Current local version: 1.0.6

Remote versions (Max. 5 most recent only):*1.0.6, frozen1.0.5, frozen<snip>

DANGER: Your local cookbook has same version number as the starred version above!

Please bump your local version or you won't be able to upload.

Page 151: Michelin Starred Cooking with Chef

Spork: Bump

$> knife spork bump apache2 <major|minor|patch|manual>

Bumping patch level of the apache2 cookbook from 1.0.6 to 1.0.7

Page 152: Michelin Starred Cooking with Chef

Spork: Upload

$> knife spork upload apache2

Uploading and freezing apache2 [1.0.7]upload complete

Page 153: Michelin Starred Cooking with Chef

Spork: Promote$> knife spork promote foo php

Adding version constraint php = 1.0.6

Saving changes into foo.json

Promotion complete! Please remember to upload your changed Environment file to the Chef Server.

---

$> knife spork promote foo php --remoteAdding version constraint php = 0.1.0

Saving changes into foo.json

Uploading foo to server

Page 154: Michelin Starred Cooking with Chef

Spork

Page 155: Michelin Starred Cooking with Chef

Spork

• Worked well, avoided the issues it was designed for

Page 156: Michelin Starred Cooking with Chef

Spork

• Worked well, avoided the issues it was designed for

• Subsequently evolved

Page 157: Michelin Starred Cooking with Chef

Spork

• Worked well, avoided the issues it was designed for

• Subsequently evolved

• A lot of input & work came from Devs

Page 158: Michelin Starred Cooking with Chef

Spork

• Worked well, avoided the issues it was designed for

• Subsequently evolved

• A lot of input & work came from Devs

• Organic evolution

Page 159: Michelin Starred Cooking with Chef

Spork

• Worked well, avoided the issues it was designed for

• Subsequently evolved

• A lot of input & work came from Devs

• Organic evolution

• Open sourced, of course

Page 160: Michelin Starred Cooking with Chef

Spork: Evolution

Page 161: Michelin Starred Cooking with Chef

Spork: Evolution

• Safety Checks

Page 162: Michelin Starred Cooking with Chef

Spork: Evolution

• Safety Checks

• Extra Features

Page 163: Michelin Starred Cooking with Chef

Spork: Safety Checks

Page 164: Michelin Starred Cooking with Chef

Spork: Safety Checks

• Before promoting, check version is uploaded...

Page 165: Michelin Starred Cooking with Chef

Spork: Safety Checks

$> knife spork promote php --remote

<snip>

WARNING: It looks like you have multiple cookbook paths defined so I can't tell if you're running inside a git repo.

Checking that php version 0.1.93 exists on the server before promoting (any error means it hasn't been uploaded yet)...

ERROR: The object you are looking for could not be found

Response: Cannot find a cookbook named php with version 0.1.93

Page 166: Michelin Starred Cooking with Chef

Spork: Safety Checks

• Before promoting, check version is uploaded...

• Check if you’re promoting changes to more than you thought....

Page 167: Michelin Starred Cooking with Chef

Spork: Safety ChecksWARNING: You're about to promote changes to several cookbooks:

WARNING: ganglia: = 0.1.26 changed to = 0.1.25installerz: = 0.1.66 changed to = 0.1.65php: = 0.1.92 changed to = 0.1.93

Are you sure you want to continue? (Y/N) N

You said no, so I'm done here.

Would you like to reset your local development.json to match the server?? (Y/N) Y

<snip>

development.json reset.

Page 168: Michelin Starred Cooking with Chef

Spork: Features

Page 169: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

Page 170: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

• Git support

Page 171: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

• Git support

• Chat notifications + Gist (upload and promote)

Page 172: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

• Git support

• Chat notifications + Gist (upload and promote)

• IRCCat

Page 173: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

• Git support

• Chat notifications + Gist (upload and promote)

• IRCCat

• Hipchat (courtesy of Secondmarket)

Page 174: Michelin Starred Cooking with Chef

Features: Chat Notifications

[19:43:46] <irccat> CHEF: pmcdonnell uploaded and froze cookbook immount version 0.0.24

[19:44:00] <irccat> CHEF: pmcdonnell uploaded environment production https://github.etsycorp.com/gist/385043

[19:44:01] <irccat> CHEF: pmcdonnell uploaded environment development https://github.etsycorp.com/gist/385044

Page 175: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

• Git support

• Chat notifications + Gist (upload and promote)

• IRCCat

• Hipchat (courtesy of Secondmarket)

• Graphite (on promote)

Page 176: Michelin Starred Cooking with Chef

Features: Graphite

Page 177: Michelin Starred Cooking with Chef

Spork: Features• Default Environments

• Git support

• Chat notifications + Gist (upload and promote)

• IRCCat

• Hipchat (courtesy of Secondmarket)

• Graphite (on promote)

• Foodcritic (on upload)

Page 178: Michelin Starred Cooking with Chef

Features: Foodcritic

$> knife spork upload system

<snip>

Lint checking system...

ERROR: Lint check failed. Halting upload.

ERROR: Lint check output:

ERROR: ETSY003: Execute resource used to run curl or wget commands: /Users/jcowie/dev/etsy/chef/cookbooks/system/recipes/dev-ssl.rb:41

Page 179: Michelin Starred Cooking with Chef

Use the Source!

tiny.cc/velocity2012

Page 180: Michelin Starred Cooking with Chef

We’re hiring!

BoF on Tuesdayor just come and say Hi :)