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

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

E8ac626646da35420ffba5da02f4787d?s=128

Shuichi Ohsawa

April 05, 2018
Tweet

Transcript

  1. 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
  2. 4.
  3. 5.

    αʔόߏ੒ • ϩʔϧ • WebɺBatchɺDeploy etc • Webαʔό • ELB

    + EC2(c3.2xlarge × 20୆ऑ) • Batchαʔό • EC2(r3.xlarge × 20୆ڧ) • Deployαʔό • Web/BatchαʔόʹσϓϩΠ 5/20
  4. 7.

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

    Web/Batchαʔόશ୆Ұ੪ʹσϓϩΠ • σϓϩΠαʔό͔Β࣮ߦ • PushܕσϓϩΠ/In place/All at once 7/20
  5. 8.

    ैདྷͷσϓϩΠ • σϓϩΠεΫϦϓτ(Rakefile)ͰσϓϩΠ࣮ߦ • Capistrano 2ϕʔε • ΞϓϦຖʹCapλεΫϑΝΠϧͷੜ੒ • ฒྻͰෳ਺ΞϓϦΛσϓϩΠ

    • ϩʔϧ͸Chef ServerͷλάͰ؅ཧ • Web, BatchͰॲཧ͕ҟͳΔͨΊϩʔϧͰ۠ผ • knife tagίϚϯυͰ෇͚֎͢͠Δ 8/20
  6. 10.

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

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

    Capistrano • ݱߦͷCapistrano 2ͷεΫϦϓτΛվम • capistrano-stretcher ͸ Capistrano 3ͷΈରԠͳͷͰݟૹΓ •

    https://github.com/pepabo/capistrano-stretcher • Capistrano͔ΒStretcher + ConsulΛݺͼग़ͯ͠σϓϩΠ • ࢀߟʹͭͭ͠ॲཧΛ࣮૷ • ࠓ·Ͱ࣮ߦ͖ͯͨ͠capίϚϯυΛେ͖͘ม͑͗͢ͳ͍Α͏ʹ 11/20
  8. 12.

    Stretcher • https://github.com/fujiwara/stretcher • Consulͱ૊Έ߹ΘͤΔ͜ͱͰɺΠϕϯτΛτϦΨʔͱͨ͠PullܕσϓϩΠ͕Մೳ • ࠾༻ͨ͠ཧ༝ ! • ෳ਺ΞϓϦΛҰ੪ʹσϓϩΠͯ͠΋ૣ͍

    • 20ऑͷRailsΞϓϦΛฒྻσϓϩΠ͢Δͱ1ʙ2෼ఔ౓ͰऴΘΔ • ෳ਺ͷઃఆϑΝΠϧ(ϚχϑΣετϑΝΠϧ)Λ༻ҙ͢Δ͜ͱͰɺৼΔ෣͍Λม͑Δ͜ͱ͕Ͱ͖Δ • σϓϩΠϑΝΠϧ഑ஔ༻ • γϯϘϦοΫϦϯΫ੾ସ༻ • Consulͱͷ਌࿨ੑ͕ߴ͍ 12/20
  9. 13.

    Consul • https://www.consul.io/ • HashiCorpࣾఏڙͷΦʔέετϨʔγϣϯπʔϧ • αʔόͱΫϥΠΞϯτͱ͍͏̎ͭͷ໾ׂͰߏ੒͞ΕɺΫϥελΛܗ੒͢Δ • ো֐ݕ஌ɺ಺෦DNSɺKey/ValueετΞ(KVS) •

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

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

    ࠷৽ͷσϓϩΠϑΝΠϧΛ࣋ͬͯ͘Δ͚ͩ 3. GitHub/RubyGems͕མͪΔͱσϓϩΠͰ͖ͳ͍ • => S3ͳͷͰ΄΅໰୊ͳ͠ 17/20
  12. 18.

    ൿಗ৘ใͷ҉߸Խɾ෮߸ • DBύεϫʔυ΍Ωʔ৘ใΛઃఆϑΝΠϧ(YAML)ʹੜͰॻ͍͓ͯ ͘ͷ͸ةݥ • ൿಗ৘ใΛEC2 Parameter Storeʹอ͓͖࣋ͯ͠ɺઃఆϑΝΠϧ ʹ͸EC2 Parameter

    Storeͷσʔλ໊ʹஔ͖׵͑ • σϓϩΠ࣌ʹ෮߸͠ઃఆϑΝΠϧΛॻ͖׵͑ • σϓϩΠαʔό͔͠෮߸Ͱ͖ͳ͍Α͏ʹKMSͷIAMݖݶΛઃఆ 18/20
  13. 20.