from dev to devops - codemotion es 2012

75
From Dev to DevOps Carlos Sanchez @csanchez http://carlossanchez.eu http://maestrodev.com

Upload: carlos-sanchez

Post on 19-May-2015

3.459 views

Category:

Technology


1 download

DESCRIPTION

More info at http://blog.carlossanchez.eu/tag/devops Video en español: http://youtu.be/E_OE4l3t5BA The DevOps movement aims to improve communication between developers and operations teams to solve critical issues such as fear of change and risky deployments. But the same way that Agile development would likely fail without continuous integration tools, the DevOps principles need tools to make them real, and provide the automation required to actually be implemented. Most of the so called DevOps tools focus on the operations side, and there should be more than that, the automation must cover the full process, Dev to QA to Ops and be as automated and agile as possible. Tools in each part of the workflow have evolved in their own silos, and with the support of their own target teams. But a true DevOps mentality requires a seamless process from the start of development to the end in production deployments and maintenance, and for a process to be successful there must be tools that take the burden out of humans. Apache Maven has arguably been the most successful tool for development, project standardization and automation introduced in the last years. On the operations side we have open source tools like Puppet or Chef that are becoming increasingly popular to automate infrastructure maintenance and server provisioning. In this presentation we will introduce an end-to-end development-to-production process that will take advantage of Maven and Puppet, each of them at their strong points, and open source tools to automate the handover between them, automating continuous build and deployment, continuous delivery, from source code to any number of application servers managed with Puppet, running either in physical hardware or the cloud, handling new continuous integration builds and releases automatically through several stages and environments such as development, QA, and production.

TRANSCRIPT

Page 1: From Dev to DevOps - Codemotion ES 2012

From Dev to DevOps

Carlos Sanchez@csanchez

http://carlossanchez.euhttp://maestrodev.com

Page 3: From Dev to DevOps - Codemotion ES 2012

Dev... What?

Page 4: From Dev to DevOps - Codemotion ES 2012

Agile

planningiterative developmentcontinuous integration

release soon, release often

Page 5: From Dev to DevOps - Codemotion ES 2012
Page 6: From Dev to DevOps - Codemotion ES 2012

DevQaOps ?

Page 7: From Dev to DevOps - Codemotion ES 2012
Page 8: From Dev to DevOps - Codemotion ES 2012

DevOps addresses

Fear of changeRisky deployments

It works on my machine!Siloisation

Dev Change vs. Ops stability

Page 9: From Dev to DevOps - Codemotion ES 2012

Individuals and interactions over processes and tools

Working software over comprehensive documentation

Customer collaboration over contract negotiation

Responding to change over following a plan

Page 10: From Dev to DevOps - Codemotion ES 2012

Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.

Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive

advantage.Deliver working software frequently, from a couple of weeks

to a couple of months, with a preference to the shorter timescale.Business people and developers must work together daily

throughout the project.The most efficient and effective method of conveying information

to and within a development team is face-to-face conversation.

Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain

a constant pace indefinitely.

Page 11: From Dev to DevOps - Codemotion ES 2012
Page 12: From Dev to DevOps - Codemotion ES 2012

Dev

Page 13: From Dev to DevOps - Codemotion ES 2012
Page 14: From Dev to DevOps - Codemotion ES 2012
Page 15: From Dev to DevOps - Codemotion ES 2012
Page 16: From Dev to DevOps - Codemotion ES 2012

What developers do today to specify target environments is

NOT enough

Page 17: From Dev to DevOps - Codemotion ES 2012
Page 18: From Dev to DevOps - Codemotion ES 2012
Page 19: From Dev to DevOps - Codemotion ES 2012

Ops

Page 20: From Dev to DevOps - Codemotion ES 2012

requirements

Operating Systemconfig filespackages installedmulti stage configurationsdevQApre-productionproduction

Page 21: From Dev to DevOps - Codemotion ES 2012

Deployment

How do I deploy this?documentationmanual stepsprone to errors

Page 22: From Dev to DevOps - Codemotion ES 2012

Cloud

How do I deploy this?to hundreds of servers

Page 23: From Dev to DevOps - Codemotion ES 2012

DevOps

Page 24: From Dev to DevOps - Codemotion ES 2012
Page 25: From Dev to DevOps - Codemotion ES 2012

Should I worry about my OPS job?

Page 26: From Dev to DevOps - Codemotion ES 2012

yesmy job is to make other

people’s jobs unnecessary

Page 27: From Dev to DevOps - Codemotion ES 2012

yesyou should see the NOOPS

guys

no

Page 28: From Dev to DevOps - Codemotion ES 2012
Page 29: From Dev to DevOps - Codemotion ES 2012

DevOps is NOT about the tools

Page 30: From Dev to DevOps - Codemotion ES 2012

Nice, BUT

how can I implement IT

Page 31: From Dev to DevOps - Codemotion ES 2012

Tools can enable change in behavior

and eventually change culture

Patrick Debois

Page 32: From Dev to DevOps - Codemotion ES 2012

DevOps tools

everyone is intelligent enoughevery tool is cloud enabledevery tool is DevOps(tm)

Page 33: From Dev to DevOps - Codemotion ES 2012

DevOps tools: infrastructure automation

infrastructure as codeit’s all invented, now it’s standardized

Page 34: From Dev to DevOps - Codemotion ES 2012

Infrastructure as Code

New solutions bring new challenges

Follow development best practicestagging

branchingreleasing

dev, QA, production

Page 35: From Dev to DevOps - Codemotion ES 2012

“MY MACHINES ARE BEING PROVISIONED”

DEVOPS

New solutions bring new problems

Page 36: From Dev to DevOps - Codemotion ES 2012
Page 37: From Dev to DevOps - Codemotion ES 2012

Puppet

manifestsruby-likeERB templates

exec { "maven-untar": command => "tar xf /tmp/x.tgz", cwd => "/opt", creates => "/opt/apache-maven-${version}", path => ["/bin"], } -> file { "/usr/bin/mvn": ensure => link, target => "/opt/apache-maven-${version}/bin/mvn", } file { "/usr/local/bin/mvn": ensure => absent, require => Exec["maven-untar"], } file { "$home/.mavenrc": mode => "0600", owner => $user, content => template("maven/mavenrc.erb"), require => User[$user], }

Page 38: From Dev to DevOps - Codemotion ES 2012

Puppet

infrastructure IS code

package { 'openssh-server': ensure => present,}

Page 39: From Dev to DevOps - Codemotion ES 2012

Puppet

declarative modelstate vs processno scripting

service { 'ntp': name => 'ntpd', ensure => running, }

Page 40: From Dev to DevOps - Codemotion ES 2012

Puppet

master - agent architecture

Page 41: From Dev to DevOps - Codemotion ES 2012

Vagrant

Page 42: From Dev to DevOps - Codemotion ES 2012

Vagrant

Oracle VirtualBox cmdline automationEasy Puppet and Chef provisioning

Keep VM configuration for different projectsShare boxes and configuration files across teams

base box + configuration files

Page 43: From Dev to DevOps - Codemotion ES 2012

Vagrant base boxes

www.vagrantbox.es

anywhere! just (big) files

Page 44: From Dev to DevOps - Codemotion ES 2012

using Vagrant

$ gem install vagrant$ vagrant box add centos-6.0-x86_64 \ http://dl.dropbox.com/u/1627760/centos-6.0-x86_64.box $ vagrant init myproject$ vagrant up$ vagrant ssh$ vagrant suspend$ vagrant resume$ vagrant destroy

Page 45: From Dev to DevOps - Codemotion ES 2012

Vagrant::Config.run do |config|

# Every Vagrant virtual environment requires a box to build off of. config.vm.box = "centos-6.0-x86_64"

# The url from where the 'config.vm.box' box will be fetched config.vm.box_url = "http://dl.dropbox.com/u/1627760/centos-6.0-x86_64.box"

# Boot with a GUI so you can see the screen. (Default is headless) #config.vm.boot_mode = :gui

# Assign this VM to a host only network IP, allowing you to access it via the IP. # config.vm.network "33.33.33.10"

# Forward a port from the guest to the host, which allows for outside # computers to access the VM, whereas host only networking does not. config.vm.forward_port "sonar", 9000, 19000

# Enable provisioning with Puppet stand alone. config.vm.share_folder("templates", "/tmp/vagrant-puppet/templates", "templates")

config.vm.provision :puppet do |puppet| puppet.manifest_file = "base.pp" puppet.module_path = "mymodules" puppet.options = ["--templatedir","/tmp/vagrant-puppet/templates"] puppet.options = "-v -d" end

end

Vagrant

Page 46: From Dev to DevOps - Codemotion ES 2012

manifests/base.pp

package { jdk: ensure => installed, name => $operatingsystem ? { centOS => "java-1.6.0-openjdk-devel", Ubuntu => "openjdk-6-jdk", default => "jdk", },}

Page 47: From Dev to DevOps - Codemotion ES 2012

VeeWee

Page 48: From Dev to DevOps - Codemotion ES 2012

VeeWee

easily build Vagrant base boxeshttps://github.com/jedi4ever/veewee

Page 49: From Dev to DevOps - Codemotion ES 2012

using VeeWee

$ gem install veewee$ vagrant basebox templates$ vagrant basebox define 'my-ubuntu-server' 'ubuntu-11.04-server-amd64'# customize definitions/my-ubuntu-server$ vagrant basebox build 'my-ubuntu-server'$ vagrant basebox validate 'my-ubuntu-server'$ vagrant basebox export 'my-ubuntu-server'$ vagrant box add 'my-ubuntu-server' 'my-ubuntu-server.box'$ vagrant init 'my-ubuntu-server'

Page 50: From Dev to DevOps - Codemotion ES 2012

Geppetto

Page 52: From Dev to DevOps - Codemotion ES 2012

Puppet DSL

Page 53: From Dev to DevOps - Codemotion ES 2012

Puppet resources

user { 'dave': ensure => present, uid => '507', gid => 'admin', shell => '/bin/zsh', home => '/home/dave', managehome => true,}

Page 54: From Dev to DevOps - Codemotion ES 2012

Puppet standalone

$ puppet apply my_test_manifest.pp

Page 55: From Dev to DevOps - Codemotion ES 2012

ordering

file {'/tmp/test1': ensure => present, content => "Hi.",}

notify {'/tmp/test1 has already been synced.': require => File['/tmp/test1'],}

Page 56: From Dev to DevOps - Codemotion ES 2012

ordering

file {'/tmp/test1': ensure => present, content => "Hi.",} ->

notify {'/tmp/test1 has already been synced.':}

Page 57: From Dev to DevOps - Codemotion ES 2012

variables

$longthing = "Imagine I have something really long in here. Like an SSH key, let's say."

file {'authorized_keys': path => '/root/.ssh/authorized_keys', content => $longthing,}

Page 58: From Dev to DevOps - Codemotion ES 2012

facts

host {'self': ensure => present, name => $::fqdn, host_aliases => ['puppet', $::hostname], ip => $::ipaddress,}

file {'motd': ensure => file, path => '/etc/motd', mode => 0644, content => "Welcome to ${::hostname},\na ${::operatingsystem} island in the sea of ${::domain}.\n",}

Page 59: From Dev to DevOps - Codemotion ES 2012

conditionals

case $operatingsystem { centos, redhat: { $apache = "httpd" } debian, ubuntu: { $apache = "apache2" } default: { fail("Unrecognized operating system for webserver") }}

$apache = $operatingsystem ? { centos => 'httpd', redhat => 'httpd', /(?i)(ubuntu|debian)/ => "apache2-$1", # (Don't actually use that package name.) default => undef, }

Page 60: From Dev to DevOps - Codemotion ES 2012

class definition

class ntp {

package { 'ntp': ensure => installed, } service { 'ntp': name => 'ntpd', ensure => running, enable => true, subscribe => File['ntp.conf'], }}

Page 61: From Dev to DevOps - Codemotion ES 2012

parameterized classes

class paramclassexample ($value1, $value2 = "Default value") { notify {"Value 1 is ${value1}.":} notify {"Value 2 is ${value2}.":}}

class {'paramclassexample': value1 => 'Something', value2 => 'Something else',}

class {'paramclassexample': value1 => 'Something',}

Page 62: From Dev to DevOps - Codemotion ES 2012

modules

{module}/

files/ lib/ manifests/ init.pp {class}.pp {defined type}.pp {namespace}/ {class}.pp {class}.pp templates/ tests/

Page 63: From Dev to DevOps - Codemotion ES 2012

templating

file {'/etc/foo.conf': ensure => file, require => Package['foo'], content => template('foo/foo.conf.erb'),}

Page 64: From Dev to DevOps - Codemotion ES 2012

templates/foo.conf.erb

OS is <%= $::operatingsystem %>

Page 65: From Dev to DevOps - Codemotion ES 2012

node configuration

# nodes.pp

node 'someserver.domain.com' inherits basenode { $web_fqdn = 'www.domain.com' include genericwebserver include some_other_service}

node 'ldapmaster.domain.com' inherits basenode { include s_ldap::master}

node 'humanresources.domain.com' inherits basenode { include c_humanresources}

Page 66: From Dev to DevOps - Codemotion ES 2012

Examples

Page 67: From Dev to DevOps - Codemotion ES 2012

Tomcat cluster + postgres

postgres databasedb.acme.com

tomcat serverswww1.acme.com

www2.acme.com

...

webapp

Page 68: From Dev to DevOps - Codemotion ES 2012

Modules required

git clone \ https://github.com/maestrodev/puppet-postgres \ modules/postgresgit clone \ https://github.com/camptocamp/puppet-tomcat \ modules/tomcatgit clone \ https://github.com/maestrodev/puppet-maven \ modules/maven

Page 69: From Dev to DevOps - Codemotion ES 2012

modules/example/database.pp

class 'database' ($db_password = 'password') {

class { "postgres" : password => 'postgres' } -> postgres::initdb{ "initdb": } -> postgres::enable { "enable": } -> postgres::user { "web": passwd => $db_password } -> postgres::createdb { "web": owner=> "web" }}

Page 70: From Dev to DevOps - Codemotion ES 2012

modules/example/webserver.pp

class 'webserver'($db_server = 'localhost', $db_password = 'password') {

package { "java-1.6.0-openjdk-devel": ensure => "latest" }

class { 'tomcat': } -> tomcat::instance {"mytomcat": } ->

class { 'maven::maven': } -> maven { "/srv/tomcat/${mytomcat}/webapps/mywebapp.war": id => "com.acme:mywebapp:1.0:war", }

file { '/etc/acme.conf': content => "db = ${db_server}password = ${db_password}", }}

Page 71: From Dev to DevOps - Codemotion ES 2012

manifests/site.pp

node 'base' { $db_password = 'web'}

node 'db.acme.com' inherits base { class {'database': db_password => $db_password }}

# www1.acme.com, www2.acme.com, www3.acme.com,...node /^www\d+\.acme\.com$/ inherits base { class {'webserver': db_server => 'db.acme.com', db_password => $db_password, }}

Page 72: From Dev to DevOps - Codemotion ES 2012

spec/hosts/ db_spec.pp & www_spec.pp

require 'rspec-puppet'

describe 'db.acme.com' do it { should contain_package('postgres') }end

require 'rspec-puppet'

describe 'www55.acme.com' do it 'should have valid config file' do content = catalogue.resource('file', '/etc/acme.conf').send(:parameters)[:content] content.should match /db\.acme\.com/ content.should match /password = web/ endend

Page 73: From Dev to DevOps - Codemotion ES 2012

Example code and slides

Available athttp://slideshare.carlossanchez.eu

http://github.carlossanchez.euhttp://blog.carlossanchez.eu

https://github.com/maestrodev/puppet-modules

Page 74: From Dev to DevOps - Codemotion ES 2012

[email protected]@apache.org

@csanchez

Gracias!

http://blog.carlossanchez.euhttp://maestrodev.com

Page 75: From Dev to DevOps - Codemotion ES 2012

Photo Credits

Son of Man Lego - Alex Eylarhttp://www.flickr.com/photos/hoyvinmayvin/4702772452/

Brick wall - Luis Argerichhttp://www.flickr.com/photos/lrargerich/4353397797/

Agile vs. Iterative flow - Christopher Littlehttp://en.wikipedia.org/wiki/File:Agile-vs-iterative-flow.jpg

DevOps - Rajiv.Panthttp://en.wikipedia.org/wiki/File:Devops.pngPimientos de Padron - Howard Walfish

http://www.flickr.com/photos/h-bomb/4868400647/

Compiling - XKCDhttp://xkcd.com/303/

Printer in 1568 - Meggs, Philip Bhttp://en.wikipedia.org/wiki/File:Printer_in_1568-ce.png

Relativity - M. C. Escherhttp://en.wikipedia.org/wiki/File:Escher%27s_Relativity.jpg

Teacher and class - Herald Posthttp://www.flickr.com/photos/heraldpost/5169295832/