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

快適なサービス開発を支える技術/Cookpad TechConf 2017

快適なサービス開発を支える技術/Cookpad TechConf 2017

Cookpad TechConf 2017
https://techconf.cookpad.com/2017/

08d5432a5bc31e6d9edec87b94cb1db1?s=128

Takashi Kokubun

January 21, 2017
Tweet

Transcript

  1. շదͳαʔϏε։ൃΛࢧ͑Δٕज़ Cookpad TechConf 2017 Takashi Kokubun

  2. ࣗݾ঺հ ▸ ࠃ෼ ਸࢤ / Takashi Kokubun ▸ ٕज़෦ ։ൃج൫άϧʔϓ

    ▸ GitHub, Twitter: @k0kubun @k0kubun
  3. ΫοΫύου͸ ։ൃޮ཰޲্ͷͨΊʹ ԿΛ͍ͯ͠Δͷ͔

  4. ࠓ೔࿩͢͜ͱ ΫοΫύου͕Ձ஋Λಧ͚ΔαΠΫϧ 2. ։ൃ 3. ςετ 4. σϓϩΠ 5. ؂ࢹ

    1. ։ൃ؀ڥͷ ηοτΞοϓ
  5. ࠓ೔࿩͢͜ͱ ΫοΫύου͕Ձ஋Λಧ͚ΔαΠΫϧ 2. ։ൃ 3. ςετ 4. σϓϩΠ 5. ؂ࢹ

    1. ։ൃ؀ڥͷ ηοτΞοϓ ▸ ͜ͷதͰͲͷΑ͏ͳ޻෉Λ ߦ͍ͬͯΔ͔঺հ͠·͢ (WebΞϓϦͷ࿩Λத৺ʹ࿩͠·͢)
  6. ։ൃ؀ڥΛ੔͑Δ্Ͱେ੾ʹ͍ͯ͠Δ͜ͱ ࠓ೔࿩͢͜ͱ ▸ αʔϏε։ൃऀͷੜ࢈ੑΛୈҰʹߟ͑ͯ։ൃ؀ڥΛ ੔͍͑ͯΔ ▸ ͨͩ͠ɺ໨త͸Ϣʔβʔʹ͢͹΍͘Ձ஋Λಧ͚Δ͜ͱͰ͋Δ ͜ͱΛ๨Εͳ͍

  7. 1. BOOTSTRAP EFFORTS TO IMPROVE PRODUCTIVITY IN

  8. 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉ ▸ curl https://ͻΈͭ/setup.sh | bash ▸ ͜ͷίϚϯυҰൃͰ Rails,

    iOS(macOSͷΈ), Android, ػցֶश ͷ։ൃ؀ڥ͕੔͏ ▸ ͦͷޙͷߋ৽΍ద༻΋ίϚϯυҰൃ ։ൃ؀ڥͷηοτΞοϓํ๏
  9. setup.sh ͸ macOS, Linux ͷͲͪΒͰ΋ಈ࡞ ▸ ΫοΫύουͷ։ൃऀ͸جຊmacOSΛར༻ ▸ LinuxΛ࢖͍͍ͨਓ޲͚ʹLinux΋αϙʔτ 1.

    ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉
  10. setup.sh ͰԿΛ͍ͯ͠Δͷ͔ ▸ ߏ੒؅ཧεΫϦϓτͷμ΢ϯϩʔυ ▸ Chef෩ͷRuby DSLͰهड़͞Ε͍ͯΔ ▸ DSLʹΑͬͯOSͳͲͷ؀ڥͷࠩҟΛٵऩ͠΍͍͢ ▸

    ߏ੒؅ཧπʔϧͷ࣮ߦ ▸ mrubyͰ࡞ΒΕͨMItamaeͱ͍͏πʔϧΛར༻͍ͯ͠Δ 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉
  11. setup.sh ͰԿΛ͍ͯ͠Δͷ͔ ▸ Chef෩ͷRuby DSL (Itamae DSL) 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉ package

    'memcached' package 'postgresql'
  12. setup.sh ͰԿΛ͍ͯ͠Δͷ͔ ▸ Chef෩ͷRuby DSL (Itamae DSL) 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉ package

    'memcached' package 'postgresql' brew install memcached brew install postgresql macOS
  13. setup.sh ͰԿΛ͍ͯ͠Δͷ͔ ▸ Chef෩ͷRuby DSL (Itamae DSL) 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉ package

    'memcached' package 'postgresql' apt-get install -y memcached apt-get install -y postgresql brew install memcached brew install postgresql Ubuntu macOS
  14. mrubyͰ࡞ΒΕͨߏ੒؅ཧπʔϧ: MItamae ▸ https://github.com/k0kubun/mitamae ▸ ChefϥΠΫͰܰྔͳߏ੒؅ཧπʔϧItamaeͷmruby࣮૷ ▸ ϩʔΧϧ؀ڥ΁ͷద༻ʹಛԽ͓ͯ͠ΓɺItamaeΑΓߴ଎ ▸ γϯάϧόΠφϦͰϦϦʔε

    ▸ mrubyͰ࡞͍ͬͯΔͨΊɺRubyͷॲཧܥ͕ͳͯ͘΋ ࣮ߦՄೳ 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉
  15. ͳͥmrubyͰ࡞ΒΕͨπʔϧΛ࢖͍ͬͯΔͷ͔ ▸ Rubyͩͱ࠷௿Ͱ΋Itamae gemΛ࢖͏ඞཁ͕͋Γɺ࣮ߦ࣌ͷ ґଘ͕ଟ͘ͳΔ ▸ ։ൃऀͷRubyͷ؀ڥΛ࢖࣮ͬͯߦ͢Δͱɺ։ൃऀͷRubyͷ ؀ڥ͕յΕͨ࣌ʹ࠶౓ηοτΞοϓͰ͖ͳ͘ͳΔ ▸ ͦͷ఺mrubyͩͱόΠφϦ͑͋͞Ε͹ಈ͘

    ▸ Ruby͕ೖͬͯͳ͍LinuxσΟετϦϏϡʔγϣϯͰ΋ɺ εΫϦϓτ࣮ߦલʹRubyΛ͍Ε͓ͯ͘ඞཁ͕ͳ͍ 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉
  16. ؀ڥηοτΞοϓʹ͓͚Δ޻෉ ·ͱΊ ▸ ίϚϯυΛҰൃୟ͚ͩ͘Ͱ։ൃ͕࢝ΊΒΕΔ ▸ mrubyΛ࢖ͬͯηοτΞοϓπʔϧͷґଘΛݮΒ͠ɺ յΕʹͨ͘͘͠ 1. ։ൃ؀ڥͷηοτΞοϓʹ͓͚Δ޻෉

  17. 2. DEVELOPMENT EFFORTS TO IMPROVE PRODUCTIVITY IN

  18. ڞ༻ͷ։ൃ༻σʔλϕʔε ▸ ։ൃ؀ڥͷWebΞϓϦ͸ڞ༻ͷ։ൃ༻σʔλϕʔεʹ઀ଓ ͞Ε͍ͯΔ ▸ ͜ͷσʔλϕʔε͸ຊ൪͔Βσʔλ͕ϨϓϦ͞Εͯ͘Δ ▸ cookpad.com͚ͩͰͳ͘ଟ͘ͷΞϓϦͰ։ൃ؀ڥ޲͚ʹ ϨϓϦΛઃఆ͍ͯ͠Δ 2.

    ։ൃʹ͓͚Δ޻෉
  19. ։ൃ༻σʔλϕʔεͷ޻෉ ▸ ςʔϒϧ໊΍ΧϥϜ໊ʹsecure_ΛؚΉ৔߹͸ϨϓϦ͠ͳ͍ ▸ ΧϥϜΛ૿΍ͯ͠΋ϨϓϦ͕ࢭ·Βͳ͘͢Δ ▸ ϨϓϦ͞Εͯ͘Δσʔλͱ։ൃ؀ڥͰೖΕͨσʔλͱ ίϯϑϦΫτͤ͞ͳ͍ ▸ ݖݶΛద੾ʹ؅ཧ͠ɺ҆қʹσʔλϕʔεΛDROPͤ͞ͳ͍

    2. ։ൃʹ͓͚Δ޻෉
  20. ։ൃ༻σʔλϕʔεͷ޻෉ ▸ ςετσʔλΛ౤ߘ͢Δ࣌Ͱ΋ɺຊ൪؀ڥʹ౤ߘ͢Δ ͭ΋ΓͰಈ࡞֬ೝΛߦ͏ ▸ มͳσʔλΛ͍ΕΔͱຊ൪Ͱͷମݧͱ։ൃ࣌ͷମݧ͕ ҟͳͬͯ͠·͏ ▸ ৗʹϢʔβʔͷମݧΛҙࣝͯ͠։ൃ͢Δ 2.

    ։ൃʹ͓͚Δ޻෉
  21. ϚΠΫϩαʔϏεԽ ▸ Ҏલ͸શͯͷνʔϜͰҰͭͷWebΞϓϦΛ։ൃ͍͕ͯͨ͠ɺ ։ൃ͕େมͩͬͨ ▸ ςετ͕૿͑ɺCIʹ͔͔Δ͕࣌ؒංେԽ ▸ ΫΤϦ΍ґଘ͢ΔϞδϡʔϧ͕ଟ͘ɺ։ൃ؀ڥ͕ॏ͍ ▸ मਖ਼͕ٴ΅͢Өڹൣғ΍୲౰ػೳͷڥք͕Θ͔Βͳ͘ͳΔ

    ▸ ෦ॺ΍νʔϜ୯ҐͰαʔϏεΛ੾Γग़͢͜ͱͰ ։ൃ͠΍ͨ͘͢͠ 2. ։ൃʹ͓͚Δ޻෉
  22. ϚΠΫϩαʔϏεԽΛαϙʔτ͢Δπʔϧ ▸ Garage: API༻ͷϑϨʔϜϫʔΫΛ༻͍ͯ ΠϯλʔϑΣʔεΛ౷Ұ ▸ Pact: αʔϏεؒ௨৴ʹ͓͚ΔഁյతมߋΛCI Ͱݕग़ ▸

    Expeditor: αʔϏεڥքͰͷฒྻԽͱো֐ͷϋϯυϦϯά 2. ։ൃʹ͓͚Δ޻෉
  23. ։ൃʹ͓͚Δ޻෉ ·ͱΊ ▸ ຊ൪͔ΒϨϓϦ͞ΕΔσʔλϕʔεΛ࢖͍ɺ Ͱ͖Δ͚ͩຊ൪ʹ͍ۙϢʔβʔମݧΛ࠶ݱ ▸ ։ൃ͠΍͢͞Λ୲อ͠ͳ͕Βద੾ͳ୯ҐͰ ΞϓϦέʔγϣϯΛ෼ׂ͍ͯ͠Δ 2. ։ൃʹ͓͚Δ޻෉

  24. 3. TESTING EFFORTS TO IMPROVE PRODUCTIVITY IN

  25. JenkinsΛ࢖ͬͨࣗಈςετ ▸ JenkinsΛ࢖ͬͯmasterͷίϛοτ΍PR୯ҐͰςετΛ ࣮ߦ͠ɺૉૣ͘໰୊ʹؾ෇͚ΔΑ͏ʹ͍ͯ͠Δ ▸ JenkinsδϣϒͰςετ͕௨ͬͨϦϏδϣϯ͚͕ͩσϓϩΠ ͞ΕΔΑ͏ʹ͍ͯ͠Δ ▸ Ϣʔβʔʹ໎࿭͕͔͔Βͳ͍Α͏ʹ͢ΔͨΊ 3.

    ςετʹ͓͚Δ޻෉
  26. ςετΛࣦഊͤͨ͞ϢʔβʔʹSlackͰϝϯγϣϯ ▸ ςετ͕མͪͨίϛοτΛͨ͠ਓʹSlackͰϝϯγϣϯ͢Δ ಠࣗJenkinsϓϥάΠϯ ▸ 2016೥ʹHipChat→SlackʹҠߦ ▸ GHE΍SlackͳͲͷΞΧ΢ϯτ৘ใΛ·ͱΊΔࣾ಺ γεςϜͱ࿈ܞ 3.

    ςετʹ͓͚Δ޻෉
  27. ςετΛࣦഊͤͨ͞ϢʔβʔʹSlackͰϝϯγϣϯ 3. ςετʹ͓͚Δ޻෉

  28. ςετ༻ΞϓϦέʔγϣϯͷࣗಈσϓϩΠ ▸ खಈͰಈ࡞֬ೝ͢ΔͨΊͷ؀ڥʹΞϓϦ͕ࣗಈͰσϓϩΠ ͞ΕΔ ▸ ΄΅ຊ൪ʹ͍ۙ؀ڥΛ࠶ݱ ▸ ಈ࡞֬ೝΛ࢓૊ΈԽ͢Δ͜ͱͰ඼࣭Λ୲อ 3. ςετʹ͓͚Δ޻෉

  29. ߴ଎ͳςετ࣮ߦ: RRRSpec ▸ ςετ͕ଟ͍ΞϓϦέʔγϣϯͰ΋ߴ଎ʹςετ͕ ऴΘΔΑ͏෼ࢄ࣮ߦ ▸ εϙοτΠϯελϯεΛ׆༻ͯ҆͠Ձʹ࣮ݱ 3. ςετʹ͓͚Δ޻෉

  30. ςετʹ͓͚Δ޻෉ ·ͱΊ ▸ ࣗಈͰߴ଎ʹςετ͠ɺૉૣ͘໰୊ʹؾ෇͚ΔΑ͏ʹ ͍ͯ͠Δ ▸ ಈ࡞֬ೝΛָʹ͢Δ࢓૊ΈΛ࡞ΓɺͳΔ΂͘Ϣʔβʔʹ ໎࿭͕͔͔Βͳ͍Α͏ʹ͍ͯ͠Δ 3. ςετʹ͓͚Δ޻෉

  31. 4. DEPLOYMENT EFFORTS TO IMPROVE PRODUCTIVITY IN

  32. Chat bot, RundeckΛ࢖ͬͨσϓϩΠ ▸ SlackͰ ruboty deploy cookpad ͱൃݴͯ͠σϓϩΠ ▸

    ruboty: Ruby੡ͷChat bot ▸ σϓϩΠ͸Rundeck্ͰߦΘΕɺଞͷਓ΋ϩάΛ ݟΔ͜ͱ͕Ͱ͖Δ ▸ ݖݶ؅ཧ͞Ε͓ͯΓɺ։ൃऀ͔͠σϓϩΠͰ͖ͣɺ audit log΋࢒Δ 4. σϓϩΠʹ͓͚Δ޻෉
  33. Amazon ECSΛ࢖ͬͨαʔϏεͷσϓϩΠ ▸ Amazon ECS΁ͷσϓϩΠʹ͸಺੡ͷσϓϩΠπʔϧʮHakoʯΛར༻ ▸ https://github.com/eagletmt/hako ▸ AWSͷαʔϏε΍؀ڥม਺͕YAMLͰ؅ཧ͞Ε͓ͯΓɺ αʔϏε։ൃऀ͕

    pull request ϕʔεͰมߋͰ͖Δ ▸ RundeckͷίϯιʔϧͰ hako deploy ͕࣮ߦ͞ΕɺAmazon ECS্ʹ Dockerίϯςφ͕σϓϩΠ͞ΕΔ ▸ DockerͷͨΊɺϝΠϯͰ࢖͍ͬͯΔRubyҎ֎ͷݴޠͰ΋σϓϩΠ͕ ༰қ 4. σϓϩΠʹ͓͚Δ޻෉
  34. σϓϩΠՄೳ࣌ؒ ▸ ݄ʙ໦༵೔ͷ 9:30-17:00 or ༵ۚ೔ͷ 9:30-15:00 ͔͠ σϓϩΠͰ͖ͳ͍ ▸

    Ϣʔβʔʹ໎࿭͕͔͔Βͳ͍Α͏ɺΠϯϑϥ͕؂ࢹ Ͱ͖ͳ͍໷΍ٳ೔ͷલ͸σϓϩΠ͠ͳ͍ ▸ ruboty͔ΒσϓϩΠ͠Α͏ͱ͢ΔͱνΣοΫ͞ΕΔ 4. σϓϩΠʹ͓͚Δ޻෉
  35. σϓϩΠՄೳ࣌ؒ 4. σϓϩΠʹ͓͚Δ޻෉

  36. σϓϩΠϩοΫ ▸ ͙͢ʹσϓϩΠ͞ΕΔͱࠔΔΑ͏ͳมߋΛͨ࣌͠ͷͨΊͷ ҆શ૷ஔ ▸ RundeckͷδϣϒΛdisable͢ΔAPIΛୟ͍ͯϩοΫ ▸ ΫοΫύουͷΑ͏ʹ Docker Λ࢖Θͣී௨ͷ

    EC2 ΠϯελϯεʹσϓϩΠ͞Ε͍ͯΔҰ෦ͷαʔϏεͰ͸ɺ Φʔτεέʔϧ͍ͯ͠Δ࣌΋ࣗಈͰϩοΫ͞ΕΔ 4. σϓϩΠʹ͓͚Δ޻෉
  37. σϓϩΠϩοΫ 4. σϓϩΠʹ͓͚Δ޻෉

  38. σϓϩΠϩοΫ 4. σϓϩΠʹ͓͚Δ޻෉

  39. σϓϩΠϩοΫ 4. σϓϩΠʹ͓͚Δ޻෉

  40. HakoΛ࢖ͬͨδϣϒͷ࣮ߦ ▸ Hako͸αʔϏεͷσϓϩΠ͚ͩͰͳ͘ɺAmazon ECS্Ͱ ίϚϯυΛ࣮ߦ͢Δͷʹ΋࢖͑Δ (hako oneshotίϚϯυ) ▸ ΦϑϥΠϯδϣϒ͸ hako

    oneshot Λ࢖ͬͯECS্Ͱ࣮ߦ͞ΕΔ ▸ δϣϒεέδϡʔϥ(Kuroko2)΍δϣϒΩϡʔ(Barbeque)͕ HakoΛαϙʔτ͍ͯ͠ΔͨΊ ▸ ςετΛ௨͍ͬͯΔ࠷৽ͷϦϏδϣϯΛ࢖͏Α͏ʹͳ͓ͬͯΓɺ σϓϩΠ͕ෆཁ (ඞཁͳ৔߹͸Slack͔ΒϩοΫՄೳ) 4. σϓϩΠʹ͓͚Δ޻෉
  41. σϓϩΠʹ͓͚Δ޻෉ ·ͱΊ ▸ Ruboty, Rundeck, Hako, ECSΛར༻ͨ͠σϓϩΠ؀ڥ ▸ σϓϩΠʹΑͬͯϢʔβʔʹ໎࿭͕͔͔Γʹ͍͘࢓૊Έʹ͠ ͍ͯΔ

    4. σϓϩΠʹ͓͚Δ޻෉
  42. 5. MONITORING EFFORTS TO IMPROVE PRODUCTIVITY IN

  43. Sentry, SlackΛ࢖ͬͯΤϥʔΛ؂ࢹ ▸ Τϥʔϩά͸fluentdΛ௨ͯ͡Sentryʹૹ৴͞ΕΔ ▸ σϓϩΠޙ͸SentryΛ؂ࢹ͠ɺԿ͔Τϥʔ͕ى͖ͨΒରԠ ͢Δ ▸ Sentry͔ΒSlackʹ΋௨஌͞ΕΔ 5.

    ؂ࢹʹ͓͚Δ޻෉
  44. δϣϒ͕ࣦഊͨ͠ΒSlack΍ϝʔϧͰ௨஌ ▸ ΦϑϥΠϯδϣϒ͕ࣦഊͨ͠৔߹΋Slack౳Ͱ௨஌Ͱ͖Δ ▸ Kuroko2΍Barbeque͕Slackͷ௨஌Λαϙʔτ ▸ BarbequeͰ࣮ߦ͍ͯ͠Δδϣϒ͸ɺҰ෦ͷΤϥʔ͸ࣗಈͰ ϦτϥΠΛઃఆ͍ͯ͠Δ 5. ؂ࢹʹ͓͚Δ޻෉

  45. ECSͷϩάʹෆ৹ͳϩά͕ͳ͍͔֬ೝ ▸ HakoͰσϓϩΠͨ͠αʔϏεͷϩά͸ࣾ಺γεςϜͰ ϩάΛҰཡͰ͖Δ ▸ αʔόʔʹsshͯ͠less΍tail -fΛ͢ΔΑΓख͕ؒগͳ͍ 5. ؂ࢹʹ͓͚Δ޻෉

  46. αʔϏεͷো֐͸ZabbixͰ؂ࢹ ▸ αʔϏεͷো֐͸ZabbixͰ؂ࢹ ▸ ࣗಈͰSlackʹ௨஌ ▸ waker (https://github.com/ryotarai/waker) ͱ࿈ܞͯ͠ TwilioͰి࿩͕͔͔Δ

    ▸ ओʹΠϯϑϥ͕౰൪੍Ͱ24࣌ؒରԠ 5. ؂ࢹʹ͓͚Δ޻෉
  47. ؂ࢹʹ͓͚Δ޻෉ ·ͱΊ ▸ Կ͔ى͖ͨΒ͙͢ʹؾ෇͚ΔΑ͏ͳ࢓૊Έʹ͍ͯ͠Δ ▸ Τϥʔͳ͘Ձ஋Λಧ͚Δͱ͜Ζ·Ͱ͕αʔϏε։ൃ 5. ؂ࢹʹ͓͚Δ޻෉

  48. ։ൃ؀ڥΛ੔͑Δ্Ͱେ੾ʹ͍ͯ͠Δ͜ͱ ;Γ͔͑Γ ▸ αʔϏε։ൃऀͷੜ࢈ੑΛୈҰʹߟ͑ͯ։ൃ؀ڥΛ ੔͍͑ͯΔ ▸ ͨͩ͠ɺ໨త͸Ϣʔβʔʹ͢͹΍͘Ձ஋Λಧ͚Δ͜ͱͰ͋Δ ͜ͱΛ๨Εͳ͍

  49. ิ଍εϥΠυ ▸ ӈ্ͷΞΠίϯ͸ͦͷࢪࡦʹؔΘͬͨਓͷGitHubΞΠίϯ Λද͓ͯ͠ΓɺؔΘΓ͕େ͖͍ਓॱʹࠨ͔ΒฒΜͰ͍·͢ adorechic amutake draftcode eagletmt eisuke EugeneKato

    k0kubun makimoto miyagawa ryotarai sorah taiki45 takai