Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Infrastructure as Code with Atlassian Bamboo

ProdOps
December 17, 2013

Infrastructure as Code with Atlassian Bamboo

The infrastructure where applications are being deployed, is becoming easier to automate with the adoption of cloud and tools such as Chef and Puppet. But while application code has been using XP inspired procedures such as Test Driven Development, infrastructure code is still not there yet. This presentation will show a short overview of the available Chef testing possibilities, especially using the Atlassian Bamboo continuous integration server.

ProdOps

December 17, 2013
Tweet

More Decks by ProdOps

Other Decks in Technology

Transcript

  1. Continuous Integration ◦ 1997 Extreme Programming extremeprogramming.org/rules/integrateoften.html ◦ 2000 Martin

    Fowler martinfowler.com/articles/continuousIntegration.html ◦ 2007 Paul Duvall
  2. Infrastructure as Code “In today’s computer industry, we still typically

    install and maintain computers the way the automotive industry built cars in the early 1900s. An individual craftsman manually manipulates a machine into being, and manually maintains it afterwards. The automotive industry discovered first mass production, then mass customisation using standard tooling. The systems administration industry has a long way to go, but is getting there.” — infrastructures.org / 1997
  3. Infrastructure Test #!/usr/bin/env bats @test "git binary is found in

    PATH" { run which git [ "$status" -eq 0 ] }
  4. redis cookbook cookbooks/redis/recipes/default.rb package "redis-server" do action :upgrade end service

    "redis-server" do action :nothing supports status: true, restart: true end template "/etc/redis/redis.conf" do source "redis.conf.erb" owner "root" mode "0644" variables({ bind: node[:redis][:bind] }) notifies :restart, "service[redis-server]" end 1. cookbook/redis/attributes/default.rb 2. solo.json
  5. $ sudo chef-solo -c solo.rb -j solo.json Starting Chef Client,

    version 11.4.0 Compiling Cookbooks... Converging 3 resources Recipe: redis::default * package[redis-server] action upgrade (up to date) * service[redis-server] action nothing (up to date) * template[/etc/redis/redis.conf] action create - update template[/etc/redis/redis.conf] from 81b4f1 to 8a6cec --- /etc/redis/redis.conf 2011-07-27 17:26:50.000000000 +0000 +++ /tmp/chef-rendered-template20130406-2537-f8vlv6 2013-04-06 ... @@ -27,7 +27,7 @@ # If you want you can bind a single interface, if the bind option is not # specified all the interfaces will listen for incoming connections. # -bind 127.0.0.1 +bind 0.0.0.0 # Specify the path for the unix socket that will be used to listen for # incoming connections. There is no default, so Redis will not listen * service[redis-server] action restart - restart service service[redis-server] Chef Client finished, 2 resources updated install package run service configuration + restart
  6. Feature: Technical team members can log into team server So

    that we are more efficient with our time As a technical team We can connect to a shared server to collaborate on client work Scenario: Users can connect to server via ssh key Given a newly bootstrapped server When the technical users recipe is applied Then a user should be able to ssh to the server Scenario: Default shell is bash Given a newly bootstrapped server When the technical users recipe is applied And a user connects to the server via ssh Then their login shell should be "bash" 2 scenarios (2 undefined) 12 steps (7 undefined) 0m0.013s Given /^a newly bootstrapped server$/ do ... When /^the technical users recipe is applied$/ do ... Then /^a user should be able to ssh to the server$/ do When /^a user connects to the server via ssh$/ do ... Then /^their login shell should be "([^"]*)"$/ do |arg1| Given /^with a user's default shell changed to "([^"]*)"$/ do |arg1| ... When /^the user connects to the server via ssh$/ do ... Chef Testing - Cucumber
  7. # Test Cases class TestNginx < MiniTest::Chef::TestCase def test_config_file_exist assert

    File.exist?('/etc/nginx.conf') end def test_succeed assert run_status.success? end end Chef Testing - minitest # Spec Cases describe_recipe 'nginx:configuration' do it 'creates nginx.conf' it 'installs version 1.0.15' do node[:nginx][:version].should == '1.4.4' end end
  8. $ kitchen verify default-ubuntu-1204 -----> Starting Kitchen (v1.0.0) -----> Verifying

    <default-ubuntu-1204>... Removing /tmp/busser/suites/bats Uploading /tmp/busser/suites/bats/git_installed.bats (mode=0644) -----> Running bats test suite ✓ git binary is found in PATH 1 test, 0 failures Finished verifying <default-ubuntu-1204> (0m0.89s). -----> Kitchen is finished. (0m1.19s) Chef Testing - kitchen.ci
  9. ◦ Test application code (you know this one) ◦ Test

    infrastructure code! Test Chef cookbooks in CI = Working cookbooks Bamboo - Uses
  10. Bamboo + Chef: Usecases ◦ Automate Chef runs Run Chef

    cookbooks in CI = Painless deploys to test/stage/prod Eliminate “fat fingers errors” (aka “human errors”)
  11. ◦ Provision bamboo agents from bamboo, recursively, ad infinitum Imagine

    100 remote bamboo agents … = Lots of bamboo agents! Bamboo - Uses
  12. ◦ Build a daily “gold image” Chef runs in production

    are slow = Autoscale “frozen” images/docker Bamboo - Uses