- Title
- Intro
- About Me
- Community Software Engineer at Chef
- Organizer of LA DevOps, HangOps, SysAdvent
- Co Host of Ops All The Things
- About Me
- What is Chef?
- Let's Talk About Testing
- Types
- Linting
- Unit Testing (Pre-Convergence)
- Convergence Testing (Does it compile)
- Integration Testing (Post-Converge)
- Linting
- Rubocop for Ruby
- Foodcritic for Chef
- Convergence Testing
- Kitchen Test Kitchen
- I <3 Digital Ocean
- Post Convergence Testing
- Serveserverspec
- BATS
- Types
- Demo Time!
- Build an app that does...
chef generate cookbook awesomeapp
echo "Make Chris' Environment More Standard"
export KITCHEN_YAML=.kitchen.yml
cd awesomeapp
vi .kitchen.yml
Content
---
driver_config:
digitalocean_client_id: <%= ENV['DIGITAL_OCEAN_CLIENT_ID'] %>
digitalocean_api_key: <%= ENV['DIGITAL_OCEAN_API_KEY'] %>
provisioner:
name: chef_zero
require_chef_omnibus: latest
platforms:
- name: ubuntu-14.04
driver_plugin: digital_ocean
driver_config:
size: 1gb
image: ubuntu-14-04-x64
region: <%= ENV['DIGITAL_OCEAN_REGION'] %>
suites:
- name: default
run_list:
- recipe[awesomeapp]
attributes: {}
mkdir -p test/integration/default/serverspec
vi test/integration/default/serverspec/spec_helper.rb
Content
require 'serverspec'
set :backend, :exec
set :path, '/sbin:/usr/sbin:/usr/local/sbin:$PATH'
vi test/integration/default/serverspec/default_spec.rb
Content
require 'spec_helper'
describe process('nginx') do
it { should be_running }
end
describe port('80') do
it { should be_listening }
end
kitchen list
kitchen converge
kitchen verify
Add nginx cookbook
vi metadata.rb
Add:
depends 'nginx'
vi recipes/default.rb
Add:
include_recipe 'nginx'
kitchen converge
kitchen verify
Start with Tests
vi test/integration/default/serverspec/an_site_spec.rb
Content
require 'spec_helper'
describe command('curl http://localhost') do
its(:stdout) { should match %r{An Site} }
end
Make 'em pass
vi recipes/default.rb
Add
directory '/var/www/nginx-default/' do
action :create
recursive true
group 'www-data'
owner 'www-data'
mode '0755'
end
file '/var/www/nginx-default/index.html' do
action :create
content 'An Site'
group 'www-data'
owner 'www-data'
mode '0644'
end
kitchen converge
kitchen verify
Start with tests
vi test/integration/default/serverspec/teh_site_spec.rb
Content
require 'spec_helper'
describe command("curl -H 'Host: teh.site.com' http://localhost/") do
its(:stdout) { should match %r{Teh Site} }
end
Make it Pass
vi recipes/default.rb
Add
template '/etc/nginx/sites-available/teh_site' do
action :create
source 'teh_site.erb'
owner 'root'
group 'root'
mode '0644'
end
nginx_site 'teh_site'
directory '/var/www/teh_site/' do
action :create
recursive true
group 'www-data'
owner 'www-data'
mode '0755'
end
file '/var/www/teh_site/index.html' do
action :create
content 'Teh Site'
group 'www-data'
owner 'www-data'
mode '0644'
end
mkdir -p templates/default
vi templates/default/teh_site.erb
Content:
server {
listen 80;
root /var/www/teh_site;
index index.html index.htm;
server_name teh.site.com;
}