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

Itamaeを楽しく使うための工夫

 Itamaeを楽しく使うための工夫

itamae meetup #1

Takashi Kokubun

December 09, 2015
Tweet

More Decks by Takashi Kokubun

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Twitter, GitHub: @k0kubun • Itamaeίϛολʔ • Cookpad •

    2015ଔ • ٕज़෦։ൃج൫άϧʔϓ itamae-kitchen
  2. itamae generate / destroy • WikiͷϕετϓϥΫςΟεͷεέϧτϯੜ੒ • itamae [g|generate] [role|cookbook]

    [NAME] $ itamae g cookbook ruby create create default.rb create files/.keep create templates/.keep ϩά͓͔͍͚͠Ͳ cookbooks/ruby/ ҎԼʹ࡞ΒΕΔ
  3. Ϩγϐهड़ྔͷ࡟ݮ • include_recipe ͷҾ਺ʹ.rbෆཁʹͨ͠ • include_recipe 'foo.rb' ͸ϨΨγʔίʔυ • resource

    pluginͷautoload • foo resource͕ݺ͹Εͨ࣌ఆٛ͞Εͯͳ͚Ε͹ࣗಈͰ require itamae/plugin/resource/foo ͞ΕΔ
  4. Capistranoͷ׆༻ • झຯαʔόʔ΁ͷItamae applyʹ͸Capistrano࢖ͬͯΔ • ௕͍ίϚϯυΛଧͪࠐΈͨ͘ͳ͍ # before $ itamae

    ssh -h foo -u user -p port -r --dry-run ./lib/ recipe_helper.rb ./roles/name/default.rb $ itamae ssh -h foo -u user -p port -r ./lib/recipe_helper.rb ./roles/name/default.rb # after $ ROLES=name cap itamae dry-run $ ROLES=name cap itamae apply
  5. Capistranoͷ׆༻ • ެ։ͯ͠Δ࣮૷͸ͪ͜Β • GitHub: k0kubun/itamae-template • templateσΟϨΫτϦͷதʹ͋Γ·͢ • ߴ଎ԽͷͨΊitamae

    sshΛitamae localʹ͢Δࡶ࣮૷ೖΓ • https://github.com/k0kubun/itamae-template/tree/v0.1.4/template
  6. Rakeͷ׆༻ $ rake -T rake apply # apply configuretion for

    current OS rake debug # debugging apply for current OS rake dry-run # dry-run for current OS rake profile # profile configuration for current OS rake darwin # configure darwin rake linux # configure linux • task default: :apply ʹ͍ͯͯ͠ɺ͔ͭ Rakefile಺Ͱ require 'bundler/setup' ͯ͠bundle exec΋লུ
  7. Itamae applyͷϓϩϑΝΠϦϯά • k0kubun/dotfiles Ͱ rake profile ͢Δͱ stackprof_runner.rb ΛಡΈࠐΈϞϯΩʔύονͯ͠stackprofΛࠩ͠ࠐΉ

    module StackProfRunner def run(*) super StackProf.stop report = StackProf::Report.new(StackProf.results) report.print_text(false) end end Itamae::Runner.prepend(StackProfRunner) require 'stackprof' StackProf.start(mode: :wall, interval: 4, raw: false)
  8. Itamae applyͷϓϩϑΝΠϦϯά ================================== Mode: wall(4) Samples: 1763800 (86.86% miss rate)

    GC: 20875 (1.18%) ================================== TOTAL (pct) SAMPLES (pct) FRAME 349300 (19.8%) 336438 (19.1%) Specinfra::Backend::Exec#spawn_command 261870 (14.8%) 261870 (14.8%) String#to_snake_case 74045 (4.2%) 74045 (4.2%) block in Specinfra::Backend::Exec#with_env 65376 (3.7%) 65376 (3.7%) block in Class#subclasses • ී௨ʹίϚϯυ͕஗͍ • ద౰ʹinclude_recipeΛ࡟ͬͯΈΔͱhomebrew͕΍͹͍ • String#to_snake_case ...?
  9. package resource ͷߴ଎Խ • ࣮ମͷ ls "$(brew --prefix)/Celler" ʹͯ͠rubyܦ༝ͤ͞ͳ͍ •

    30ඵˠ11ඵ • (લͷεϥΠυͱ਺ࣈҧ͏ͷ͸ͦͷͱ͖։ൃதͩͬͨͨΊ) rake 5.21s user 2.21s system 65% cpu 11.302 total