Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

51
A power point by R Tyler Croy Mr. Kanies 6 th Period GitHub Decentral High School 2014 http://tiny.cc/MrKaniesIsTheBest

description

Continuous Infrastructure: Modern Puppet for the Jenkins Project - R.Tyler Croy, Jenkins

Transcript of Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Page 1: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

A power point by R Tyler Croy

Mr. Kanies 6th PeriodGitHub Decentral High School 2014

http://tiny.cc/MrKaniesIsTheBest

Page 2: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Who is Tyler!● GitHub Decentral High Senior (GO CATS!)● Member of the Ruby Pep Band● Mathelete● DevOps Lab Safety Marshal● Open Source Debate Team Secretary

Page 3: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

● Core Systems, Team Captain● JRuby Club President● AP Distributed Systems

Page 4: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Mr. Jenkins● Free & open Source continugous integration

server● Built with Java but can do other things to● Uses Puppet but didn't use to

Page 5: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 6: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 7: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

The Services● Many web applications● LDAP● Atlassian services● Jenkins● IRC robots● DNS● MirrorBrain

Page 8: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

The Wares● 2 physical machines● 3 KVM-based VMs● Assortment of EC2/Rackspace instances● 10+ mirrors

Page 9: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

The People● Zero “full-time” contributors● Small group of Owners● Sporadic drive-by-committers

Page 10: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 11: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

At Sun/Oracle● Scavenged machines● Dubious locations within the company● Questionable ownership of physical assets● Manually managed, no audit trail/history● Completely unreproducible

Page 12: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

“What if we used 'PUPPET?'”

Page 13: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Masterless Puppet● Needed something after leaving Sun/Oracle● Centralized audit logging in Git repo● Not everything is Puppetized because time● Some parts reproducible, others special

snowflakes● Code structure is messy and bad, also awful

Page 14: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

The Year 3000● Puppet Enterprise● Clearer definition of separation between

Puppet modules and “our code”● Git log of changes● Some snowflakes killed, some new ones

Page 15: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 16: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Why Puppet Entperirse● Higher visibility into changes being applied

– Reporting (email, irc)– PE Console

● MCollective for basic ad-hoc orchestration● Debian/Yum repo for agent bootstrap● Easy breezy beautiful, cover girl

Page 17: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Special Thanks to Puppet Labs

Page 18: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 19: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

C:\ PuppetCode.bat

Page 20: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Masterless Puppet● 80 .pp files● 0 tests● github.com/jenkinsci/infra-puppet● librarian-puppet for dependency

“management”● All secrets managed out of band

Page 21: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Code Layout

infrapuppet/ ├── Gemfile ├── Gemfile.lock ├── Puppetfile ├── Puppetfile.lock ├── confluence.deb/

     │ ├── build.sh ├── features/ ├── localmodules/

     │ ├── apache2 ├── manifests/

     │ ├── cabbage.pp     │ ├── cucumber.pp     │ ├── eggplant.pp     │ ├── kale.pp     │ ├── lettuce.pp     │ ├── spinach.pp     │ └── vagrant.pp └── run.sh

Page 22: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

A “module”class base {  # Unfortunately this module only supports Ubuntu  if ($operatingsystem == 'Ubuntu') {    include nagios::client  }

  stage {    'pre' :      before => Stage['main'];    'post' :      require => Stage['main'];  }

  class {    'base::pre' :      stage => 'pre';

    'base::post' :      stage => 'post';

    'puppet' :      ensure => '2.7.191puppetlabs2';

Page 23: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

“deployment” aka “testing”

●git pull –rebase●librarianpuppet install●puppet apply manifests/`hostname`.pp● manual guess and check

Page 24: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 25: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 26: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Code Layout

jenkinsinfra/ ├── Gemfile ├── Gemfile.lock ├── Puppetfile ├── README.md ├── Rakefile ├── Vagrantfile ├── ci/

     │ └── 00_setupgems.sh ├── dist/

     │ └── role/     │ └── profile/ ├── hieradata/

     │ └── common.yaml ├── manifests/

     │ └── site.pp └── spec/

     │ └── classes/     │ └── server/

Page 27: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

ci/

for f in ci/*.sh; do \  echo “> Running ci/$f”; \  bash $f; \done

Page 28: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

dist/

dist/ ├── profile/

     │ ├── files     │ ├── manifests     │ ├── templates     │ └── tests

 └── role/      └── manifests

Page 29: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

profile/manifests/

dist/profile/manifests/ ├── accounts.pp ├── apachemisc.pp ├── apt.pp ├── archives.pp ├── ... ├── sudo.pp └── vagrant.pp

Page 30: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

spec/spec/

 ├── classes/     │ ├── profile/     │ └── role/

 ├── fixtures     │ ├── ...

 ├── server/     │ ├── celery/     │ ├── ...     │ ├── spec_helper.rb     │ └── support

 ├── spec_helper.rb └── support/

Page 31: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

A “module”

Page 32: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Our modules● puppet-groovy (fork)● puppet-irc (fork)● puppet-apache-log-compressor● puppet-account (fork)● garethr-docker (fork)

Page 33: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

TOP SECRETS● All secrets in Hiera● Heavy use of hiera-eyaml● Private repository for sharing keys

Page 34: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Testing● rspec-puppet for catalogue logic● serverspec + vagrant-serverspec for

masterless integration testing● Manual testing with puppet agent -t for

final sanity check

Page 35: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

describe 'profile::archives' do  let(:facts) {    {:operatingsystem => 'Ubuntu',     :osfamily => 'Debian' }  }

  it { should contain_class 'profile::apachemisc' }  it { should contain_class 'lvm' }  it { should contain_class 'apache' }

  # …

  it { should contain_apache__mod 'bw' }end

Page 36: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Vagrant + ServerSpec● Relies Vagrant's ability to use multiple

provisioners– Shell– Puppet– Serverspec

● Dynamically creates a machine per role

Page 37: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

require_relative './../spec_helper'

describe 'spinach' do  it_behaves_like "a standard Linux machine"  it_behaves_like "a DNS server"

  context 'groovy support' do    describe file('/etc/profile.d/groovy.sh') do      it { should be_file }    end

    describe file('/opt/groovy2.3.1/bin/groovy') do      it { should be_file }    end  endend

Page 38: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

% ./vagrantaws up spinach==> spinach: Running provisioner: shell...<SNIP>==> spinach: Running provisioner: puppet...<SNIP>==> spinach: Running provisioner: serverspec...

spinach  behaves like a standard Linux machine    File "/etc/ssh/sshd_config"      should contain "PasswordAuthentication no"    User "kohsuke"      should exist []      should have home directory "/home/kohsuke"    Port "22"      should be listening    Cron      should have entry "20 2 * * * aptget update"  groovy support    File "/etc/profile.d/groovy.sh"      should be file    File "/opt/groovy2.3.1/bin/groovy"      should be file

Page 39: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

deployment

1.Create pull request

2.Merge changes into staging branch

3.Create pull request

4.Merge changes into production branch

5.R10k webhook updates master

6.Agents consume ~15 minutes

7.Report back to PE Console

Page 40: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 41: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 42: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Docker'd● 3 dockered services

– bind– supybot– custom java bot

Page 43: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

bind/Dockerfile

FROM ubuntu:trustyRUN aptget install y bind9 dnsutilsRUN ln f s /etc/bind/local/named.conf.local /etc/bind/RUN mkdir /var/run/named

EXPOSE 53 53/udp

# config filesVOLUME ["/etc/bind/local"]

CMD /usr/sbin/named g

Page 44: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Quality● 20+ spec files● < 5% Puppet runs have failed● All pull requests tested before merge● > 250 successful builds in CI

Page 45: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014
Page 46: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Testing with Puppet Enterprise

Page 47: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

Automating Confluence and JIRA

Page 48: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

OS UPGRADES

Page 49: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

keeping up

Page 50: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

you can help!● find us on IRC: #jenkins-infra● [email protected]● github.com/jenkins-infra

Page 51: Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf 2014

THanks!

http://tiny.cc/MrKaniesIsTheBest

@agentderogithub.com/[email protected]