Top Banner
Copyright © 2010 Opscode, Inc - All Rights Reserved Speaker: [email protected] @jtimberman www.opscode.com Joshua Timberman Sr. Solutions Engineer 1 Data Driven App Deploys Thursday, November 18, 2010
35

Data driven app deploys with chef frontdev

Nov 07, 2014

Download

Documents

jtimberman

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Speaker:

[email protected]‣ @jtimberman‣ www.opscode.com

Joshua Timberman Sr. Solutions Engineer

1

Data Driven App Deploys

Thursday, November 18, 2010

Page 2: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved 2http://www.flickr.com/photos/anotherphotograph/2100904507/sizes/o/

System administrator

Many environments

Opscode: Training, Services

Thursday, November 18, 2010

Page 3: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

http://www.flickr.com/photos/timyates/2854357446/sizes/l/

3

Rails Developers?Java Developers?Python Developers?

Thursday, November 18, 2010

Page 4: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved 4

Application Deployment

Thursday, November 18, 2010

Page 5: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Application Deployment

5

tar -x -C /app -f app.tarrsync ~/dev/app www:/appcap deploy

Thursday, November 18, 2010

Page 6: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Server Configuration

6Thursday, November 18, 2010

Page 7: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Server Configuration

Web ServersLoad BalancersDatabase Servers

7Thursday, November 18, 2010

Page 8: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Server Configuration

8

% vi /etc/mysql/my.cnf#!/bin/bashCapfile

Thursday, November 18, 2010

Page 9: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved 9http://www.brooklynstreetart.com/theBlog/wp-content/uploads/2008/12/swedish_chef_bork-sleeper-cell.jpg

Thursday, November 18, 2010

Page 10: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Chef Client runs on your systems

10Thursday, November 18, 2010

Page 11: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Clients talk to a Chef Server

11Thursday, November 18, 2010

Page 12: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved http://www.flickr.com/photos/peterrosbjerg/3913766224/ 12

We call each system you configure a Node

Thursday, November 18, 2010

Page 13: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Nodes have Attributes

13

{ "kernel": { "machine": "x86_64", "name": "Darwin", "os": "Darwin", "version": "Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386", "release": "10.4.0" }, "platform_version": "10.6.4", "platform": "mac_os_x", "platform_build": "10F569", "domain": "local", "os": "darwin", "current_user": "jtimberman", "ohai_time": 1278602661.60043, "os_version": "10.4.0", "uptime": "18 days 17 hours 49 minutes 18 seconds", "ipaddress": "10.13.37.116", "hostname": "cider", "fqdn": "cider.local", "uptime_seconds": 1619358 }

Kernel info!

Platform info!

Hostname and IP!

Thursday, November 18, 2010

Page 14: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Nodes have a Run List

14

What Roles or Recipes to applyin Order

Thursday, November 18, 2010

Page 15: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved 15http://www.flickr.com/photos/laenulfean/374398044/

Nodes have Roles

Thursday, November 18, 2010

Page 16: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reservedhttp://www.flickr.com/photos/roadsidepictures/2478953342/sizes/o/ 16

Recipes are lists of Resources

Thursday, November 18, 2010

Page 17: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Chef manages Resources on Nodes

17

cookbook_file

template

service

package

deploy

git

http_request

link

ruby_block

logbash

execute

remote_file

userThursday, November 18, 2010

Page 18: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Data bags store arbitrary data

18Thursday, November 18, 2010

Page 19: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Nodes, Roles, Data Bags are Searchable

19

% knife search node “role:webserver”

search(:users, “group:sysadmins”)

Thursday, November 18, 2010

Page 20: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Application Deployment

20

Application Repository‣ Source‣ CI / Build

Chef Repositorycider:~/dev/rails-quick-start (ruby-1.9.2-p0)master ✔ % ls -ltotal 16-rw-r--r-- 1 jtimberman staff 3521 Nov 5 13:09 README.md-rw-r--r-- 1 jtimberman staff 2171 Nov 5 13:09 Rakefiledrwxr-xr-x 3 jtimberman staff 102 Nov 5 13:09 certificates/drwxr-xr-x 3 jtimberman staff 102 Nov 5 13:09 config/drwxr-xr-x 26 jtimberman staff 884 Nov 12 08:16 cookbooks/drwxr-xr-x 4 jtimberman staff 136 Nov 5 13:25 data_bags/drwxr-xr-x 9 jtimberman staff 306 Nov 12 08:16 roles/

Thursday, November 18, 2010

Page 21: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Chef Repository

RolesCookbooksApplication Information

‣ Data Bag!

21Thursday, November 18, 2010

Page 22: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Application Information

Data BagJSON

22Thursday, November 18, 2010

Page 23: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Walkthrough

23Thursday, November 18, 2010

Page 24: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved 24

{ "id": "radiant", "server_roles": [ "radiant" ], "type": { "radiant": [ "rails", "unicorn" ] }, "database_master_role": [ "radiant_database_master" ], "repository": "git://github.com/radiant/radiant.git", "revision": { "production": "0.9.1" },

Thursday, November 18, 2010

Page 25: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved 25

base.rbproduction.rbradiant.rbradiant_database_master.rbradiant_load_balancer.rbradiant_run_migrations.rb

Server Roles

Thursday, November 18, 2010

Page 26: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Base Role

26

name "base"description "Base role applied to all nodes."run_list( "recipe[apt]", "recipe[git]", "recipe[build-essential]", "recipe[ruby]")

Thursday, November 18, 2010

Page 27: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Production Role

27

name "production"description "Nodes in the production environment."default_attributes( "app_environment" => "production")

Thursday, November 18, 2010

Page 28: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Radiant Role

28

name "radiant"description "radiant front end application server."run_list( "recipe[mysql::client]", "recipe[application]")

Thursday, November 18, 2010

Page 29: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Application Recipe

29

search(:apps) do |app| (app["server_roles"] & node.run_list.roles).each do |app_role| app["type"][app_role].each do |thing| node.run_state[:current_app] = app include_recipe "application::#{thing}" end endend

node.run_state.delete(:current_app)

Thursday, November 18, 2010

Page 30: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Application Rails Recipe

30

deploy_revision app['id'] do revision app['revision'][node.app_environment] repository app['repository'] user app['owner'] group app['group'] deploy_to app['deploy_to'] environment 'RAILS_ENV' => node.app_environment action app['force'][node.app_environment] ? :force_deploy : :deploy

...

Thursday, November 18, 2010

Page 31: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Radiant Database Master Role

31

name "radiant_database_master"description "Database master for the radiant application."run_list( "recipe[database::master]")

Thursday, November 18, 2010

Page 32: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Database Master Recipe

32

search(:apps) do |app| (app['database_master_role'] & node.run_list.roles).each do |dbm_role| app['databases'].each do |env,db| if env =~ /#{node[:app_environment]}/ root_pw = node["mysql"]["server_root_password"] mysql_database "create #{db['database']}" do host "localhost" username "root" password root_pw database db['database'] action [:create_db] end end end endend

Thursday, November 18, 2010

Page 33: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Radiant Load Balancer Role

33

name "radiant_load_balancer"description "radiant load balancer"run_list( "recipe[haproxy::app_lb]")override_attributes( "haproxy" => { "app_server_role" => "radiant" })

Thursday, November 18, 2010

Page 34: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Haproxy App Load Balancer Recipe

34

pool_members = search("node", "role:#{node['haproxy']['app_server_role']} AND app_environment:#{node['app_environment']}") || []

template "/etc/haproxy/haproxy.cfg" do source "haproxy-app_lb.cfg.erb" owner "root" group "root" mode 0644 variables :pool_members => pool_members notifies :restart, resources(:service => "haproxy")end

Thursday, November 18, 2010

Page 35: Data driven app deploys with chef frontdev

Copyright © 2010 Opscode, Inc - All Rights Reserved

Resources/Questions

35

www.opscode.com/chefIRC and Mailing lists‣ irc.freenode.net #chef‣ lists.opscode.com

Twitter:‣ @opscode, #opschef‣ @jtimberman

Questions?

Thursday, November 18, 2010