Laravel5.5的 継続的インテグレーション / Laravel 5.5 Continuous Integration

0451a8e214a5c0ddffd489528adbf787?s=47 kkznch
August 07, 2018

Laravel5.5的 継続的インテグレーション / Laravel 5.5 Continuous Integration

レガシーコード改革!UT/CIでWebサービスの技術的負債を解消する取り組み
登壇枠で使用

参考URL
https://base.connpass.com/event/94476/

0451a8e214a5c0ddffd489528adbf787?s=128

kkznch

August 07, 2018
Tweet

Transcript

  1. Copyright Re:Build.inc All Rights Reserved. Laravel5.5的 ܧଓ的インテグレʔション 嘉਺侑起 2018/08/07 3F#VJME

  2. Copyright Re:Build.inc All Rights Reserved. "HFOEB ձࣾɾࣗݾ঺հ (JU-BC$*Λಋೖ͢ΔϝϦοτ (JU-BC$*ͷಋೖํ๏ -BSBWFM1)16OJUͷϝϦοτ

  3. Copyright Re:Build.inc All Rights Reserved. ձࣾɾࣗݾ঺հ

  4. Copyright Re:Build.inc All Rights Reserved. ࣗݾ঺հ ◆໊લ ླ໦ ޹೭(Suzuki Takayuki)

    ◆ࣗݾ঺հ ɾ1990೥ɺਆಸ઒ݝੜ·Εɻ ɾࣾձਓʹͳ͔ͬͯΒɺϓϩάϥϛϯάΛ࢝ΊΔɻ ɾ2015೥ʹϑϧεϐʔυʹೖࣾ͠ɺ2017೥ʹ ϑϦʔϥϯεΛ΍ͬͨޙʹ2017೥11݄ʹԭೄͰىۀɻ ◆झຯ ίεϓϨɺԻָϥΠϒɺϚϥιϯେձʹग़Δɺ໺ٿ؍ઓ ◆εΩϧ ɾPHP, Symfony2,CakePHP3,Laravel5, ɾJavaScript, backbone.js,Angular4
  5. Copyright Re:Build.inc All Rights Reserved. ࣗݾ঺հ ◆໊લ Յ਺ ါى(Kakazu Yuki)

    @kkznch ◆ࣗݾ঺հ ɾ1990೥ɺԭೄݝੜ·Ε ɾ2016೥ʹԭిάϩʔόϧγεςϜζגࣜձࣾʹೖࣾɺ2018 ೥ʹגࣜձࣾRe:Build΁స৬ͯ͠ݱࡏʹࢸΔ ɾࠃ಺ॎஅ͍ͨ͠ ◆झຯ όϨʔϘʔϧɺϐΞϊɺήʔϜɺΧϑΣ८Γ ◆εΩϧ ɾPHPɺJavaScriptɺC/C++ɺPythonɺRuby ɾΠϯϑϥશൠɺηΩϡϦςΟগʑ
  6. Copyright Re:Build.inc All Rights Reserved. ձࣾ঺հ ◆ձ໊ࣾ גࣜձࣾRe:Build ◆ॅॴ ԭೄݝԭೄࢢதԝ̍ஸ໨̍̒−̕

    ◆ࣄۀ಺༰ ɾ೶ۀʹ͓͍ͯͷϑʔυϩεΛແ͘͢ ࣗࣾWEBαʔϏεͷاըɾ։ൃɻ ɾडୗ։ൃ ◆ࣾһ 4໊ ◆ΤϯδχΞͷಇ͖ํ ϦϞʔτϫʔΫՄೳͳࣗ༝ͳಇ͖ํΛਪ঑ͯ͠·͢ʂ
  7. ɾαʔϏε໊ temite ɾγεςϜ֓ཁ ECϓϥοτϑΥʔϜ ΫϨδοτܾࡁ ΞϑΟϦΤΠτ ͳͲ ɾ࢖͍ͬͯΔٕज़ ݴޠ :

    PHP,JavaScript ϑϨʔϜϫʔΫ: laravel5,Vue.js,JQueryͳͲ ։ൃதͷαʔϏε
  8. ϑϩϯταΠυ αʔόαΠυ Ϗϧυπʔϧ DB

  9. ૊৫ମ੍ ϓϩμΫτΦʔφʔ ։ൃϦʔμʔ νʔϜϝϯόʔ ▪ϓϩδΣΫτߏ੒ ɾϓϩμΫτΦʔφʔɿ1໊ ɾ։ൃϦʔμʔɿ1໊ ɾνʔϜϝϯόʔɿ3໊ ※σβΠφʔ΄΅ແ͠

  10. Copyright Re:Build.inc All Rights Reserved. (JU-BC$*Λಋೖ͢ΔϝϦοτ

  11. GitLabͱ͸ʁ

  12. GitLabͱ͸ʁ GitHubͬΆౕ͍

  13. GitLabͷΞΠίϯ

  14. GitLabͷΞΠίϯʢچʣ ͳΜ͔ා͍

  15. GitLabͷΞΠίϯ ॏͶͯΈͨ

  16. GitLabͷػೳ

  17. GitLabͷػೳ ͜͜Β΁ΜΑ͘࢖͏

  18. ‣ GitLabఏڙͷܧଓతΠϯςάϨʔγϣϯπʔϧ ‣ ϦϙδτϦ͕Push͞ΕͨλΠϛϯάͰಈ࡞͢Δ ‣ ಈ͔ͨ͢Ίʹ৭ʑͱ͝ʹΐ͝ʹΐ͢Δඞཁ͋Γ GitLab CIͱ͸ʁ

  19. ‣ PHPStan(PHP Static Analysis Tool)Ͱ੩తղੳ ‣ PHPUnitͰ୯ମςετɾ݁߹ςετ ‣ εςʔδϯά؀ڥ΁ͷσϓϩΠ GitLab

    CIͰฐ͕ࣾ΍ͬͯΔ͜ͱ
  20. PHPStanͰ੩తղੳ

  21. PHPUnitͰ୯ମςετɾ݁߹ςετ

  22. εςʔδϯά؀ڥ΁ͷσϓϩΠ ※اۀൿີͷͨΊ͓ݟͤͰ͖·ͤΜ

  23. 2 3 GitLab CIΛಋೖ͢ΔϝϦοτ ѹ౗త҆৺ײ ͷ֫ಘ ॲཧͷࣗಈԽʹΑ Γޮ཰Ξοϓ ඼࣭Λ୲อ 1

    2 3
  24. Copyright Re:Build.inc All Rights Reserved. (JU-BC$*ͷಋೖํ๏

  25. (1)PUSH (2)GitLab CI࣮ߦ (3)ίϯςφىಈ Gitlab (6)Envoy࣮ߦ ςετ࣮ߦ ίϯςφ σϓϩΠ࣮ߦ ίϯςφ

    (5)ίϯςφىಈ (4)UnitTest࣮ߦ (7)Pull ຊ൪؀ڥ or εςʔδϯά؀ڥ ϦϙδτϦ GiaLab CI ࣮ߦϑϩʔ
  26. ‣ SSH઀ଓ༻ͷ伴૊Λ࡞੒ɾొ࿥͢Δ ‣ DockerΠϝʔδΛ࡞੒ɾొ࿥͢Δ ‣ GitLabϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ ‣ σϓϩΠλεΫϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ GitLab CIಋೖखॱ

  27. ‣SSH઀ଓ༻ͷ伴૊Λ࡞੒ɾొ࿥͢Δ ‣ DockerΠϝʔδΛ࡞੒ɾొ࿥͢Δ ‣ GitLabϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ ‣ σϓϩΠλεΫϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ GitLab CIಋೖखॱ

  28. (1)PUSH (2)GitLab CI࣮ߦ (3)ίϯςφىಈ Gitlab (6)Envoy࣮ߦ ςετ࣮ߦ ίϯςφ σϓϩΠ࣮ߦ ίϯςφ

    (5)ίϯςφىಈ (4)UnitTest࣮ߦ (7)Pull ຊ൪؀ڥ or εςʔδϯά؀ڥ ϦϙδτϦ GitLab CI͔ΒσϓϩΠઌ΁ σϓϩΠΛ࣮ߦ͢ΔͨΊʹ SSH઀ଓ༻ͷ伴૊͕ඞཁ ެ։伴Λઃஔ ൿີ伴Λઃஔ
  29. (1)PUSH (2)GitLab CI࣮ߦ (3)ίϯςφىಈ Gitlab (6)Envoy࣮ߦ ςετ࣮ߦ ίϯςφ σϓϩΠ࣮ߦ ίϯςφ

    (5)ίϯςφىಈ (4)UnitTest࣮ߦ (7)Pull ຊ൪؀ڥ or εςʔδϯά؀ڥ ϦϙδτϦ σϓϩΠઌͷαʔό͔Β GitLabͷϦϙδτϦΛPull͢ΔͨΊʹ SSH઀ଓ༻ͷ伴૊͕ඞཁ ൿີ伴Λઃஔ ެ։伴Λઃஔ
  30. ‣ SSH઀ଓ༻ͷ伴૊Λ࡞੒ɾొ࿥͢Δ ‣DockerΠϝʔδΛ࡞੒ɾొ࿥͢Δ ‣ GitLabϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ ‣ σϓϩΠλεΫϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ GitLab CIಋೖखॱ

  31. (1)PUSH (2)GitLab CI࣮ߦ (3)ίϯςφىಈ Gitlab (6)Envoy࣮ߦ ςετ࣮ߦ ίϯςφ σϓϩΠ࣮ߦ ίϯςφ

    (5)ίϯςφىಈ (4)UnitTest࣮ߦ (7)Pull ຊ൪؀ڥ or εςʔδϯά؀ڥ ϦϙδτϦ ςετɾσϓϩΠͷ࣮ߦΛߦ͏ ίϯςφͷݩͱͳΔ DockerΠϝʔδ͕ඞཁ ϩʔΧϧͰ࡞੒ͨ͠DockerΠϝʔδΛ GitLab Container Registryʹొ࿥
  32. ‣ SSH઀ଓ༻ͷ伴૊Λ࡞੒ɾొ࿥͢Δ ‣ DockerΠϝʔδΛ࡞੒ɾొ࿥͢Δ ‣GitLabϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ ‣ σϓϩΠλεΫϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ GitLab CIಋೖखॱ

  33. (1)PUSH (2)GitLab CI࣮ߦ (3)ίϯςφىಈ Gitlab (6)Envoy࣮ߦ ςετ࣮ߦ ίϯςφ σϓϩΠ࣮ߦ ίϯςφ

    (5)ίϯςφىಈ (4)UnitTest࣮ߦ (7)Pull ຊ൪؀ڥ or εςʔδϯά؀ڥ ϦϙδτϦ Push͞ΕͨλΠϛϯάͰϦϙδτϦʹ .gitlab-ci.ymlͱ͍͏ϑΝΠϧ͕͋Ε͹ ͦͷதʹهࡌ͞Εͨδϣϒ͕࣮ߦ͞ΕΔ .gitlab-ci.ymlΛ࡞੒
  34. .gitlab-ci.yml σϓϩΠ࣮ߦίϯςφ ͷॲཧ಺༰Λهड़ ςετ࣮ߦίϯςφͰ ࢖༻͢ΔαʔϏε΍ ॲཧ಺༰Λهड़ ࢖༻͢ΔDockerΠϝʔδ envoyίϚϯυʂ

  35. ‣ SSH઀ଓ༻ͷ伴૊Λ࡞੒ɾొ࿥͢Δ ‣ DockerΠϝʔδΛ࡞੒ɾొ࿥͢Δ ‣ GitLabϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ ‣σϓϩΠλεΫϥϯφʔ؅ཧ༻ϑΝΠϧΛ࡞੒͢Δ GiLlab CIಋೖखॱ

  36. (1)PUSH (2)GitlabCI࣮ߦ (3)ίϯςφىಈ Gitlab (6)Envoy࣮ߦ ςετ࣮ߦ ίϯςφ σϓϩΠ࣮ߦ ίϯςφ (5)ίϯςφىಈ

    (4)UnitTest࣮ߦ (7)Pull ຊ൪؀ڥ or εςʔδϯά؀ڥ ϦϙδτϦ σϓϩΠ࣮ߦίϯςφͰenvoyίϚϯυ ͕࣮ߦ͞ΕɺEnvoy.blade.phpʹهड़ͨ͠ ॲཧ͕࣮ߦ͞ΕΔ Envoy.blade.phpΛ࡞੒
  37. Envoy.blade.php ෳ਺ͷσϓϩΠઌΛهड़Մೳ EnvoyͷதͰ࢖༻͢Δ άϩʔόϧม਺తͳͷΛఆٛ ۩ମతͳॲཧΛ৭ʑͱهड़ @serversσΟϨΫςΟϒͰࢦఆͨ͠ϗετʹSSH઀ଓ͠ɺ ͦͷ಺෦Ͱ@storyσΟϨΫςΟϒ಺ͷॲཧ͕࣮ߦ͞ΕΔ

  38. ͜͜·Ͱ΍ͬͯ GitLab CI͕ಈ͖·͢ʢଟ෼ʣ

  39. ৄࡉʹ͍ͭͯ͸ฐࣾͷϒϩά͔ Յ਺ݸਓͷϒϩάΛࢀর͍ͩ͘͞ ※ࢀߟ ʮגࣜձࣾRe:Buildͷϒϩάʯ ʮ͚͚ͣΜηϧϑϋοΩϯάʯ

  40. Copyright Re:Build.inc All Rights Reserved. -BSBWFM1)16OJUͷϝϦοτ

  41. 4 1 LaravelͰςετ͢ΔϝϦοτ Merit ᶃςετ༻ͷget,postϝιου͕͋Δ ᶄϨεϙϯεͷΞαʔτ͕๛෋ ᶅςετ༻ͷτϨΠτ͕ศར ᶆϞοΫԽͷ࢓૊Έ͕ศར

  42. getϝιουͷྫ

  43. postϝιουͷྫ

  44. ϨεϙϯεͷΞαʔτ͕๛෋

  45. ςετ༻τϨΠτ͕ศར ‣ RefreshDatabaseɿ - ̍ͭͷςετ͕ऴΘΔͨͼʹDBΛϦϑϨογϡ͢Δ ‣ DatabaseTransactionsɿ - ̍ͭͷςετ͕ऴΘΔͨͼʹDBΛςετ։࢝௚લͷঢ়ଶ ·ͰϩʔϧόοΫ͢Δ

    ‣ WithoutMiddlewareɿ - ࢓ֻ͚ΒΕ͍ͯΔMiddlewareΛແࢹ
  46. ɾۄͶ͗ͷΑ͏ͳߏ଄ͰϦΫΤετͱ Ϩεϙϯεͷؒʹ༷ʑͳॲཧΛڬΈࠐ Έ΍͍͢ ɾόϦσʔγϣϯͳͲ΋୯ҰͷΤϯςΟ ςΟʹґଘ͢ΔͷͰ͸ͳ͘ɺForm୯ ҐͰ࣮૷Ͱ͖Δ MiddleWareͷྫ ೝ ূ ν

    Σ ο Ϋɺ ό Ϧ σ ʔ γ ϣ ϯɺ CSRFτʔΫϯͷνΣοΫ [ิ଍] Middlewareͱ͸ʁ
  47. ϞοΫԽͷ࢓૊Έ͕ศར

  48. ϞοΫԽ͢Δલ Mail Class Router Controller SMTPαʔόʔ

  49. ϞοΫԽͨ͋͠ͱ Router Controller SMTPαʔόʔ Mail Class SMTPαʔόʔʹϝʔϧΛૹ৴ͨ͜͠ͱ ʹͯ͘͠ΕΔʢ࣮ࡍʹ͸ૹ৴͠ͳ͍ʣ

  50. Copyright Re:Build.inc All Rights Reserved. ·ͱΊ

  51. 5 1 ·ͱΊ ᶃ GitLab CIͰςετٴͼσϓϩΠॲཧΛࣗಈԽ͢Δ͜ ͱʹΑΓɺ࡞ۀΛޮ཰Խͭͭ͠඼࣭ͷ୲อ͕Ͱ͖Δ ᶄ LaravelͷPHPUnitʹ͸ศརͳΞαʔτ΍τϨΠτ͕ ༻ҙ͞Ε͍ͯΔͨΊɺՄಡੑɾอकੑͷߴ͍ςετ͕

    ॻ͚Δ