Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

itamae + Serverspecで テスト駆動インフラやってみた #shibuyarb

8,221 views

Published on

渋谷.rb[:20150318] の発表資料です https://shibuyarb.doorkeeper.jp/events/22056

Published in: Technology
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

itamae + Serverspecで テスト駆動インフラやってみた #shibuyarb

  1. 1. Copyright Drecom Co., Ltd. All Rights Reserved. itamae + Serverspecで テスト駆動インフラやってみた 2015/03/18 shibuya.rb @sue445
  2. 2. Copyright Drecom Co., Ltd. All Rights Reserved. sue445 ● drecom ○ 社内ツールとか社内ライブラリとか ○ サーバサイドをアプリからインフラまで浅く広く 見守り業務 ○ PO (Precure Ojisan) ● RubyKaja 2014 @Shibuya.rb 自己紹介
  3. 3. Copyright Drecom Co., Ltd. All Rights Reserved. 【今期の嫁】キュアトゥインクル
  4. 4. Copyright Drecom Co., Ltd. All Rights Reserved. 今期の黄色は肩背中が丸出し!!!!
  5. 5. Copyright Drecom Co., Ltd. All Rights Reserved. 【本妻】キュアピース
  6. 6. Copyright Drecom Co., Ltd. All Rights Reserved. ● 経緯 ● itamaeについて ● Serverspecについて ● 実際のテスト駆動インフラの流れ ● itamaeレシピを社内に公開した ● 参考書籍 ● 所感 Agenda
  7. 7. Copyright Drecom Co., Ltd. All Rights Reserved. ● 【目的】Railsミドル全部入りのOpenStackのJenkins Slave のスナップショットを作りたかった ● ミドル全部入りならインフラがchefで作ったスナップショットが あるとの情報 ● 差分はJenkinsユーザの作成とrbenvのインストールくらいあ ればよさそう ○ が、インフラのchefのレシピはカオスすぎて素人にはハードル高かった ● 全部入りスナップショット対して差分をitamaeでプロビジョニ ングすることに ● せっかくなので今流行のテスト駆動インフラに挑戦してみた 経緯
  8. 8. Copyright Drecom Co., Ltd. All Rights Reserved. itamae ● クックパッドが作ったプロビジョニングツール ○ http://itamae.kitchen/ ○ https://speakerdeck.com/ryotarai/itamae-infra-as- code-xian-zhuang-que-ren-hui ● Ruby製、シンプルで軽量なChefみたいなやつ ● DSLなので記述がシンプル ● DSLもRubyのコードなので適度にリファクタリングできる ● プラグインをgemから取り込める ○ 依存性をbundlerで管理できる ○ rubygems.orgに公開していればみんなが使える
  9. 9. Copyright Drecom Co., Ltd. All Rights Reserved. ● @mizzy氏が作ったインフラ構成をテストするためのツール ○ http://serverspec.org/ ○ http://www.oreilly.co.jp/books/9784873117096/ ● Ruby製 ○ RSpecベースだけどテンプレをコピペするだけなので RSpec使ったこと無くても問題ない ● 特定のプロビジョニングツール(itamaeとかChefとかPuppet とかAnsible)に依存しないで使える Serverspec
  10. 10. Copyright Drecom Co., Ltd. All Rights Reserved. ● OS毎のコマンドの違いを吸収するgem ○ https://github.com/serverspec/specinfra ○ Debianならapt-get install使うとか、yumならyum instll 使うとか ● Serverspecから切りだされてgem化されている ○ capistranoとsshkitのような関係 ● itamaeもSpecinfraに依存しているので、Specinfraの中身 を知ってたらitamaeとSercerspecの両方で役に立つ Specinfra
  11. 11. Copyright Drecom Co., Ltd. All Rights Reserved. 1. インフラの確認項目をテストコードで書く 2. 期待したエラーが出ることを確認 (Red) 3. サーバで適用したいインフラコードを書く 4. テストコードが通っていることを確認(Green) 5. ダメなら3に戻る 6. 必要ならリファクタリング (Refactor) 7. 1に戻る 実際のテスト駆動インフラの流れ
  12. 12. Copyright Drecom Co., Ltd. All Rights Reserved. http://www.slideshare.net/t_wada/the-spirit-of-tdd/27 テスト駆動インフラでもTDDの黄金の回転
  13. 13. Copyright Drecom Co., Ltd. All Rights Reserved. ● 新しいサーバを作ると自分のhomeディレクトリがないので手 軽に作りたい 【例】自分のhomeディレクトリを作る
  14. 14. Copyright Drecom Co., Ltd. All Rights Reserved. describe file("/home/sueyoshi_go") do it { should be_directory } it { should be_mode 700 } it { should be_owned_by "sueyoshi_go" } it { should be_grouped_into "drecom" } end TARGET_HOST=xxx.xxx.xxx.xxx rspec spec/myhome_spec.rb Serverspecのテストコード(myhome_spec.rb)
  15. 15. Copyright Drecom Co., Ltd. All Rights Reserved. Serverspecのテストコード(myhome_spec.rb) /home/sueyoshi_go が  ディレクトリで  パーミッション700で  ownerがsueyoshi_go で  drecom groupに所属していること describe file("/home/sueyoshi_go") do it { should be_directory } it { should be_mode 700 } it { should be_owned_by "sueyoshi_go" } it { should be_grouped_into "drecom" } end TARGET_HOST=xxx.xxx.xxx.xxx rspec spec/myhome_spec.rb
  16. 16. Copyright Drecom Co., Ltd. All Rights Reserved. Serverspecのテストコード(myhome_spec.rb) /home/sueyoshi_go が  ディレクトリで  パーミッション700で  ownerがsueyoshi_go で  drecom groupに所属していること describe file("/home/sueyoshi_go") do it { should be_directory } it { should be_mode 700 } it { should be_owned_by "sueyoshi_go" } it { should be_grouped_into "drecom" } end TARGET_HOST=xxx.xxx.xxx.xxx rspec spec/myhome_spec.rb それっぽく読める!
  17. 17. Copyright Drecom Co., Ltd. All Rights Reserved. directory "/home/sueyoshi_go" do mode "700" owner "sueyoshi_go" group "drecom" not_if "ls /home/sueyoshi_go" end itamae ssh -h xxx.xxx.xxx.xxx -p 10022 recipes/myhome.rb itamaeのレシピ (myhome.rb)
  18. 18. Copyright Drecom Co., Ltd. All Rights Reserved. itamaeのレシピ (myhome.rb) ディレクトリが存在していなければ /home/sueyoshi_go を作って  パーミッション700で  ownerがsueyoshi_goで  groupをdrecomにすること directory "/home/sueyoshi_go" do mode "700" owner "sueyoshi_go" group "drecom" not_if "ls /home/sueyoshi_go" end itamae ssh -h xxx.xxx.xxx.xxx -p 10022 recipes/myhome.rb
  19. 19. Copyright Drecom Co., Ltd. All Rights Reserved. itamaeのレシピ (myhome.rb) ディレクトリが存在していなければ /home/sueyoshi_go を作って  パーミッション700で  ownerがsueyoshi_goで  groupをdrecomにすること directory "/home/sueyoshi_go" do mode "700" owner "sueyoshi_go" group "drecom" not_if "ls /home/sueyoshi_go" end itamae ssh -h xxx.xxx.xxx.xxx -p 10022 recipes/myhome.rb それっぽく読める!
  20. 20. Copyright Drecom Co., Ltd. All Rights Reserved. ● 目視確認の自動化 ○ インフラコードを書く、適用、確認のサイクルを素早く回 せる ● インフラコードがリファクタリングできる ○ バグってもテストコードで検知できる テスト駆動インフラのメリット
  21. 21. Copyright Drecom Co., Ltd. All Rights Reserved. ● itamae-recipe-jenkins_slave (Jenkins slaveを作るための レシピ) ○ jenkinsユーザの作成 ○ sshの鍵の転送 ○ rbenvのインストール ○ jenkinsユーザの鍵を使ってのmasterからslaveへの疎 通確認 ○ mysqlやmemcachedなどの起動 ● (itamaeやServerspecを書いたことない状態から)開発期 間1週間ちょい itamaeレシピを社内に公開した
  22. 22. Copyright Drecom Co., Ltd. All Rights Reserved. source "https://rubygems.org" gem "itamae" gem "itamae-plugin-recipe-rbenv", ">= 0.2.2" group :test do gem "serverspec" end source "http://gem.xxxxxxx.com" do gem "itamae-plugin-resource-sudo_remote_file", ">= 0.0.2" gem "specinfra-plain_sudo", ">= 0.0.2" end Gemfile 社内gem
  23. 23. Copyright Drecom Co., Ltd. All Rights Reserved. ● itamae-plugin-resource-sudo_remote_file ○ レシピ実行ユーザが直接コピーできないファイルを remote_fileするためのプラグイン ○ sudo cp /tmp -> sudo chmod -> scp -> remove tmp_file な感じ ● specinfra-plain_sudo ○ 弊社環境だと sudo /bin/sh ~ が動かないことがあった のでspecinfraのsudo実行周辺にモンキーパッチあてて る ● どっちも弊社環境に起因していることが原因のような気がす るので社外公開はしない予定 作った社内gem
  24. 24. Copyright Drecom Co., Ltd. All Rights Reserved. ● WEB+DB PRESS vol.80 ○ http://gihyo. jp/magazine/wdpress/archive/2014/vol80 ○ テスト駆動インフラ特集 ● Serverspec ○ http://www.oreilly.co.jp/books/9784873117096/ ○ 体系的にまとまってる ○ 付録でitamaeについてもふれられてる 参考書籍
  25. 25. Copyright Drecom Co., Ltd. All Rights Reserved. ● itamaeはそんなにドキュメント充実してない ○ ソースは大した量じゃないのでサクッと読める ○ githubのスライドが一番よくまとまってるw ○ そんなに学習コスト高くない ● Serverspecはドキュメント充実してる ○ ベースはrspecなので普段から使ってるととっつきやす いはず ○ オライリー本おすすめ ● どっちも日本人が開発してるので日本語でググった時の資 料が充実してる ● コマンドの作業履歴(.bash_historyとか)をコードとして残せ るのはでかい 所感

×