Top Banner
73

Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Aug 20, 2015

Download

Technology

Peter Leschev
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: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code
Page 2: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

@peterleschev

Husband, Father of 3 & Atlassian

Build Engineering

Peter Leschev

Page 3: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

A Build Engineering Team’s Journey of

Infrastructure as CodeNov-2014

Page 4: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Build platform & services used internally within the company• 90k builds per month• 43k automated tests just for JIRA• Developers expect a reliable infrastructure & fast CI feedback

Build Engineering today @ Atlassian

Page 5: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• 1000 build agents (own hardware + EC2 instances)• include SCM clients, JDKs, JVM build tools, databases, headless

browser testing, python builds, NodeJS, installers & more

• Maintain 20 AMIs of various build configurations• 8 Bamboo Servers• maven.atlassian.com / 6 Nexus instances • Monitoring - opsview / graphite / statsd

Build Engineering today @ Atlassian

Page 6: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Build Engineering today @ Atlassian

Page 7: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Infrastructure as Code

= Puppet + SCM ?

Page 8: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Manually maintained snowflakes• Started using puppet

4 years ago...

Page 9: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Production rollout

puppetmaster

build agents

Page 10: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Production rollout failure

puppetmaster

build agents

Page 11: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence of Change

Dev Rollout Soak in Prod

Page 12: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code
Page 13: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

atlassian.com/git

Page 14: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Style in Pull Requests

Page 15: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Automated style checking• Setup automated build that runs checks & posts results• Setup ratchet build to detect regressions

Puppet Lint https://github.com/rodjek/puppet-lintTim Sharpe

@rodjek

Page 16: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence of Change

Dev Code review Rollout Soak in Prod

initial + Code review

Page 17: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Coding on Puppet Master• Culture of manually modifying

production - Configuration Drift

• Impact on Builds

Using Staging for Development

puppetmaster

build agentsbuild agents

staging puppet environment

Page 18: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Easily spin up Infrastructure locally on your laptop• Reproducible / disposable environments• Machine provisioning via Virtual Box / VMWare / AWS• Configuration applied via Shell Scripts / Puppet / Chef• Develop and test infrastructure changes locally

Vagrant http://www.vagrantup.com/Mitchell Hashimoto

@mitchellh

Page 19: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Vagrant

Vagrantfile

vagrant basebox

http://www.vagrantup.com/Mitchell Hashimoto

@mitchellh

Page 20: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Vagrant

Spins up a local VM to a known state

Destroy the VM when done

Make some puppet changes and then run:

to apply your changes

SSH into your VM using:

to check your changes

http://www.vagrantup.com/Mitchell Hashimoto

@mitchellh

Page 21: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence of Change

Dev Code review Rollout Soak in Prod

initial + Code review + Vagrant

Page 22: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Vagrant basebox differences with production machines• Originally using publicly available vagrant baseboxes

• Installed packages biggest differences

• Generating a basebox manually was a painful process

Vagrant != Production

Page 23: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Packer http://packer.ioMitchell Hashimoto

@mitchellh

Vagrant box for Virtualbox

packer template JSON

Vagrant box for AWS

Page 24: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Latest basebox generated in CI & published to fileshare• No need to generate baseboxes locally

Basebox generation via CI

Page 25: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Code review Rollout Soak in Prod

initial + Code review + Vagrant + Packer

Page 26: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Developing locally

Rolling out to production

Broken build agents!

Rolling out to staging

Page 27: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Behaviour Driven Development

Cucumber https://github.com/cucumber/aruba

Page 28: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Cucumber & Vagrant

Vagrant

Custom Provisioner

Virtual Box

VM

puppet apply

cucumber *.features

via ssh

Page 29: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Requires cucumber dependencies to be installed on tested VM

• Tests run within the VM making testing firewall rules harder

Disadvantages

Page 30: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Code review Rollout Soak in Prod

initial + Code review + Vagrant + Packer + Cukes

Page 31: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

But it works on my machine!– Every Developer”“

Page 32: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• ‘From scratch’ provisioning• Confidence that you can rebuild in disaster

Continuous Integration

Page 33: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

The Cattle: you give them numbers. When

they get ill, you shoot them

The Pets: you give nice names,

you stroke them, and when they get ill,

you nurse them back to health,

taking a long time over it

– Tim Bell, CERN”

Page 34: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Code review CI & Rollout Soak in Prod

initial + Code review + Vagrant + Packer + Cukes + CI

Page 35: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Provisioning from scratch is slow

Page 36: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Spread out CI

provision VM #1

Moved from sequential to parallel provisioning

provision VM #2

provision VM #3

provision VM #4

provision VM #1

provision VM #2 provision VM #3

provision VM #4

Page 37: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

There are so many MacPros you can steal

Page 38: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

The ones I had my eye on....

Page 39: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Profiling Puppet Runs

Add “--evaltrace” to puppet apply

+ =Collect and show the longest occurrences of: “Evaluated in ([\d\.]+) seconds”

Page 40: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Profiling Cucumber runs

http://itshouldbeuseful.wordpress.com/2010/11/10/find-your-slowest-running-cucumber-features/

Page 41: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Provision locally & for CI• Faster & different class of problems found• Matches production state

Delta Provisioning

‘from scratch’ provision delta provision

provision VM

export VM fileshare

import VM box

provision VMon success

Page 42: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Code review CI & Rollout Soak in Prod

initial + Code review + Vagrant + Packer + Cukes + CI+ Delta CI

Page 43: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Broken buildsmaster

Page 44: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Branch builds

BUILDENG-5670

BUILDENG-5669

master

Page 45: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Branch CI Code review CI & Rollout Soak in Prod

initial + Code review + Vagrant + Packer + Cukes+ CI + Delta CI + Branch CI

Page 46: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Slow builds

Page 47: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Vagrant-AWS https://github.com/mitchellh/vagrant-aws

Page 48: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• MacPros no longer required• They were limited in supply & old

• 2x speed improvement• Only limited by our credit card limit

Vagrant-AWS https://github.com/mitchellh/vagrant-aws

Page 49: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Catalog Diff

puppet master --logdest console --compile HOSTNAME

Step 1: Generate a hash of a node’s catalog

HOSTNAME.json

- Sort elements - Remove timestamps - Generate shasum

f50db91e6461f5bdcb56769a8f77da1fac26943d

Page 50: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Catalog Diff

Step 2: Compare the hash of master versus your branch to avoid unnecessary provisioning

Example 1:

f50db91e6461f5bdcb56769a8f77da1fac26943d f50db91e6461f5bdcb56769a8f77da1fac26943d=

Hash is the same, no build required

master branch

Example 2:

f50db91e6461f5bdcb56769a8f77da1fac26943d 18033e4d21b78bab6deb3ae1ff3c147ade5a37ca!=

Hash is different, build required

master branch

Page 51: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Catalog Diff

Step 3: Profit!Reduction in

feedback time +

$$$ saved

Images: http://pixabay.com/p-30984/ https://www.flickr.com/photos/williamnyk/3598113750/

Page 52: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code
Page 53: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Infrequent Releases

Page 54: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• Puppet runs impacted running builds• Disabling all the build agents

• Performing the roll out

• git clone / librarian-puppet / symlink update on puppetmaster

• Manually kick off puppet on all the build agents

• Enabling all the build agents

• Set of Puppet environments for every bamboo server

Painful Puppet Rollouts

Page 55: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Graceful Service restarts

+Bamboo Agent JVM process watches for touch file & shutdowns when Idle (written as a Bamboo Plugin)

Page 56: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• BEFORE - Multiple puppet envs for each Bamboo Server• jbac_staging

• jbac_production

• cbac_staging

• cbac_production

• etc

• AFTER - Changed to use ‘staging’ & ‘production’ only

Puppet Environments

Page 57: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• BEFORE: Manually on puppetmaster• git clone the puppet tree

• run librarian-puppet to pull external modules

• Update staging / production symlink

• AFTER: Bamboo build which performs the above steps automatically

Updates on Puppetmaster

Page 58: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Bot automation - ‘open prs’

Page 59: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Less Human interaction +

More automation =

Higher Confidence

Page 60: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Less Human Effort =

Increased frequency of releases

Page 61: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Branch CI Code review CI & Rollout Soak in Prod

initial + Code review + Vagrant + Packer+ Cukes + CI + Delta CI + Branch CI+ Frequent Releases

Page 62: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Should I be scared?– Peter Leschev, 3 months ago”“

I’m scared!– Peter Leschev, 3.5 years ago”“

Page 63: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Hipchat integration

Page 64: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Branch CI Code review CI & Rollout Soak in Prod

initial + Code review + Vagrant + Packer+ Cukes + CI + Delta CI + Branch CI+ Frequent Releases + Notification

Page 65: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

HIGH

NONE

Lifecycle of an infra change

confidence

Confidence in Change

Dev Branch CI Code review CI & Rollout Soak in Prod

before after

Page 66: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Confidence in Change

or

Finding & fixing problems sooner rather

than later

Page 67: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Snowflakes

Pets

Cattle

Stateless Machines

Page 68: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

We’re still on the Journey

Come join us!

atlassian.com/jobs

Page 69: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

one more thing…

Page 70: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

• https://forge.puppetlabs.com/atlassian/nexus_rest • Configure Nexus using Custom Puppet Provider Types

rather than XML files

Puppet Module for Sonatype Nexus

Page 71: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Thank you!

Page 72: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code

Questions?

Page 73: Puppet Camp Melbourne Nov 2014 - A Build Engineering Team’s Journey of Infrastructure as Code