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

インフラエンジニアがConsulとStretcherをつかったデプロイ改善で開発効率の向上に貢献した話(短縮版 + α) / omotesando.rb #33

インフラエンジニアがConsulとStretcherをつかったデプロイ改善で開発効率の向上に貢献した話(短縮版 + α) / omotesando.rb #33

E8ac626646da35420ffba5da02f4787d?s=128

Shuichi Ohsawa

April 05, 2018
Tweet

Transcript

  1. ΠϯϑϥΤϯδχΞ͕ ConsulͱStretcherΛ͔ͭͬͨσϓϩΠվળͰ ։ൃޮ཰ͷ޲্ʹߩݙͨ͠࿩ (୹ॖ൛ + α) දࢀಓ.rb #33 ~Deploy~ Shuichi

    Ohsawa (@ohsawa0515) 1/20
  2. ࣗݾ঺հ • େᖒलҰ (@ohsawa0515) • Blog΍ͬͯ·͢ http://blog.jicoman.info/ • Sansanגࣜձࣾ Data

    Strategy & Operation Center • σʔλԽγεςϜͷΠϯϑϥߏஙɾӡ༻ɾվળɺ͓ۚ ͷܭࢉͳͲΛ୲౰ • AWSϦιʔεͷແବݣ͍͍ͯ͠ΔਓΛಛఆ͠஫ҙ͢Δਓ • ࢖༻ݴޠ: PHP(ݩ΃ͪͺʔ), Golang(গ͠), Ruby(গ͠) • Ruby͸FluentdϓϥάΠϯͱ͔ͭͬͨ͘͜ͱ͋Δ͚Ͳ͋·Γॻ͚ͳ͍ • GolangͰAutoScaling + Blue-Green Deployment πʔϧ͚ͭͬͨ͘Ͳ͋·Γॻ͚ͳ͍ 2/20
  3. ຊεϥΠυʹ͍ͭͯ July Tech Festa 2017Ͱ࿩ͨ͠ࢿྉΛ୹ॖ൛+αͱͯ͠·ͱΊͨ΋ͷ Ͱ͢ɻ ίϯςφͷ࿩͸Ͱ·ͤΜɻ͢΂ͯEC2Ͱ͢ɻ ৄࡉ΍αϯϓϧίʔυͳͲ͸ͪ͜ΒͷεϥΠυΛ͝ࢀরͩ͘͞ ͍ɻ https://speakerdeck.com/ohsawa0515/jtf2017-consul-stretcher-

    deploy 3/20
  4. ΞδΣϯμ • αʔόߏ੒ • ΞϓϦέʔγϣϯߏ੒ • ैདྷͷσϓϩΠͱ՝୊఺ • ৽σϓϩΠ •

    σϓϩΠϑϩʔ • ൿಗ৘ใͷ҉߸Խɾ෮߸ (+αͷ෦෼) 4/20
  5. αʔόߏ੒ • ϩʔϧ • WebɺBatchɺDeploy etc • Webαʔό • ELB

    + EC2(c3.2xlarge × 20୆ऑ) • Batchαʔό • EC2(r3.xlarge × 20୆ڧ) • Deployαʔό • Web/BatchαʔόʹσϓϩΠ 5/20
  6. ΞϓϦέʔγϣϯߏ੒ • Web/Batchαʔόͱ΋ʹ20ऑͷRailsΞϓϦ͕ಉډ • ίετ࡟ݮ • සൟʹϦΫΤετ͞Εͳ͍αʔϏε • Apache +

    Passenger 6/20
  7. ैདྷͷσϓϩΠ • ఆظϦϦʔε(िҰ) • ͢΂ͯͷRailsΞϓϦΛσϓϩΠ • ඞཁʹԠͯ͡hotfixϦϦʔε(िʹ਺ճ) • ඞཁͳΞϓϦ͚ͩσϓϩΠ •

    Web/Batchαʔόશ୆Ұ੪ʹσϓϩΠ • σϓϩΠαʔό͔Β࣮ߦ • PushܕσϓϩΠ/In place/All at once 7/20
  8. ैདྷͷσϓϩΠ • σϓϩΠεΫϦϓτ(Rakefile)ͰσϓϩΠ࣮ߦ • Capistrano 2ϕʔε • ΞϓϦຖʹCapλεΫϑΝΠϧͷੜ੒ • ฒྻͰෳ਺ΞϓϦΛσϓϩΠ

    • ϩʔϧ͸Chef ServerͷλάͰ؅ཧ • Web, BatchͰॲཧ͕ҟͳΔͨΊϩʔϧͰ۠ผ • knife tagίϚϯυͰ෇͚֎͢͠Δ 8/20
  9. ՝୊఺ 1. σϓϩΠʹ͕͔͔࣌ؒΔ 2. αʔόͷ௥Ճ͕໘౗ 3. GitHub/RubyGems͕མͪΔͱσϓϩΠͰ͖ͳ͍ 9/20

  10. Capistrano + Stretchr + Consul • PullܕσϓϩΠ • αʔόࣗ਎͕σϓϩΠ͢Δ •

    σϓϩΠ͕࣌ؒҰఆ(୆਺ʹൺྫ͠ͳ͍) • Amazon S3ʹϏϧυࡁͷϑΝΠϧΛ഑ஔ • μ΢ϯϩʔυ͠഑ஔɺ࠶ىಈ͢Δ͚ͩͰσϓϩΠ׬ྃ • S3ͷՄ༻ੑ͸99.99ˋ • In place/All at once • Capistarnoͷ࢓૊Έ(γϯϘϦοΫϦϯΫʹΑΔ੾Γସ͑)Λ׆༻ • ConsulʹΑΔαʔϏεσΟεΧόϦػೳͰϗετͷొ࿥ɾ࡟আ͸ࣗಈ 10/20
  11. Capistrano • ݱߦͷCapistrano 2ͷεΫϦϓτΛվम • capistrano-stretcher ͸ Capistrano 3ͷΈରԠͳͷͰݟૹΓ •

    https://github.com/pepabo/capistrano-stretcher • Capistrano͔ΒStretcher + ConsulΛݺͼग़ͯ͠σϓϩΠ • ࢀߟʹͭͭ͠ॲཧΛ࣮૷ • ࠓ·Ͱ࣮ߦ͖ͯͨ͠capίϚϯυΛେ͖͘ม͑͗͢ͳ͍Α͏ʹ 11/20
  12. Stretcher • https://github.com/fujiwara/stretcher • Consulͱ૊Έ߹ΘͤΔ͜ͱͰɺΠϕϯτΛτϦΨʔͱͨ͠PullܕσϓϩΠ͕Մೳ • ࠾༻ͨ͠ཧ༝ ! • ෳ਺ΞϓϦΛҰ੪ʹσϓϩΠͯ͠΋ૣ͍

    • 20ऑͷRailsΞϓϦΛฒྻσϓϩΠ͢Δͱ1ʙ2෼ఔ౓ͰऴΘΔ • ෳ਺ͷઃఆϑΝΠϧ(ϚχϑΣετϑΝΠϧ)Λ༻ҙ͢Δ͜ͱͰɺৼΔ෣͍Λม͑Δ͜ͱ͕Ͱ͖Δ • σϓϩΠϑΝΠϧ഑ஔ༻ • γϯϘϦοΫϦϯΫ੾ସ༻ • Consulͱͷ਌࿨ੑ͕ߴ͍ 12/20
  13. Consul • https://www.consul.io/ • HashiCorpࣾఏڙͷΦʔέετϨʔγϣϯπʔϧ • αʔόͱΫϥΠΞϯτͱ͍͏̎ͭͷ໾ׂͰߏ੒͞ΕɺΫϥελΛܗ੒͢Δ • ো֐ݕ஌ɺ಺෦DNSɺKey/ValueετΞ(KVS) •

    Πϕϯτൃߦ • ֤ConsulΫϥΠΞϯτ͸ΠϕϯτΛ଴ͪड͚͍ͯΔঢ়ଶͰɺಛఆͷΠϕϯτ͕ൃߦ͞ΕͨΒ೚ҙͷΞΫγϣϯΛ࣮ ߦ • αʔϏελάʹΑΔϩʔϧ؅ཧ • αʔϏεσΟεΧόϦ • ىಈ࣌ʹΫϥελ΁ࣗಈδϣΠϯ 13/20
  14. σϓϩΠϑϩʔ 14/20

  15. ·ͱΊͯσϓϩΠ͢Δ ͢΂ͯͷΞϓϦΛϚϧνεϨουͰฒྻσϓϩΠ task deploy_all: :setup do deploy_projects = "application_A,apllication_B,..." threads_count

    = ENV['THREADS'] Parallel.map(deploy_projects, in_threads: threads_count.to_i) do |project| # Ϗϧυαʔό΁ͷσϓϩΠ # ϚχϑΣετϑΝΠϧͷੜ੒ # S3΁ͷΞοϓϩʔυ # ΞϓϦέʔγϣϯαʔόʹ഑෍ end end task release_all: :setup do deploy_projects = "application_A,apllication_B,..." threads_count = ENV['THREADS'] Parallel.map(deploy_projects, in_threads: threads_count.to_i) do |project| # σϓϩΠ(γϯϘϦοΫϦϯΫ੾ସ) end end 15/20
  16. Slack SlackͰσϓϩΠঢ়گ͕֬ೝͰ͖Δ ໰୊͕ੜͨ͡৔߹͸όοΫτϨʔε͕ද ࣔ 16/20

  17. ݁Ռ 1. σϓϩΠʹ͕͔͔࣌ؒΔ • => ϦϦʔε࣌ؒͷ୹ॖ(30෼->5෼) 2. αʔόͷ௥Ճ͕໘౗ • =>

    ࠷৽ͷσϓϩΠϑΝΠϧΛ࣋ͬͯ͘Δ͚ͩ 3. GitHub/RubyGems͕མͪΔͱσϓϩΠͰ͖ͳ͍ • => S3ͳͷͰ΄΅໰୊ͳ͠ 17/20
  18. ൿಗ৘ใͷ҉߸Խɾ෮߸ • DBύεϫʔυ΍Ωʔ৘ใΛઃఆϑΝΠϧ(YAML)ʹੜͰॻ͍͓ͯ ͘ͷ͸ةݥ • ൿಗ৘ใΛEC2 Parameter Storeʹอ͓͖࣋ͯ͠ɺઃఆϑΝΠϧ ʹ͸EC2 Parameter

    Storeͷσʔλ໊ʹஔ͖׵͑ • σϓϩΠ࣌ʹ෮߸͠ઃఆϑΝΠϧΛॻ͖׵͑ • σϓϩΠαʔό͔͠෮߸Ͱ͖ͳ͍Α͏ʹKMSͷIAMݖݶΛઃఆ 18/20
  19. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ 19/20

  20. 20/20