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

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

kkznch
August 07, 2018

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

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

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

kkznch

August 07, 2018
Tweet

More Decks by kkznch

Other Decks in Programming

Transcript

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  6. Copyright Re:Build.inc All Rights Reserved.
    ձࣾ঺հ
    ◆ձ໊ࣾ
    גࣜձࣾRe:Build
    ◆ॅॴ
    ԭೄݝԭೄࢢதԝ̍ஸ໨̍̒−̕
    ◆ࣄۀ಺༰
    ɾ೶ۀʹ͓͍ͯͷϑʔυϩεΛແ͘͢
    ࣗࣾWEBαʔϏεͷاըɾ։ൃɻ
    ɾडୗ։ൃ
    ◆ࣾһ
    4໊
    ◆ΤϯδχΞͷಇ͖ํ
    ϦϞʔτϫʔΫՄೳͳࣗ༝ͳಇ͖ํΛਪ঑ͯ͠·͢ʂ

    View full-size slide

  7. ɾαʔϏε໊
    temite
    ɾγεςϜ֓ཁ
    ECϓϥοτϑΥʔϜ
    ΫϨδοτܾࡁ
    ΞϑΟϦΤΠτ
    ͳͲ
    ɾ࢖͍ͬͯΔٕज़
    ݴޠ : PHP,JavaScript
    ϑϨʔϜϫʔΫ: laravel5,Vue.js,JQueryͳͲ
    ։ൃதͷαʔϏε

    View full-size slide

  8. ϑϩϯταΠυ
    αʔόαΠυ
    Ϗϧυπʔϧ
    DB

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  11. GitLabͱ͸ʁ

    View full-size slide

  12. GitLabͱ͸ʁ
    GitHubͬΆౕ͍

    View full-size slide

  13. GitLabͷΞΠίϯ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  16. GitLabͷػೳ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. ‣ PHPStan(PHP Static Analysis Tool)Ͱ੩తղੳ
    ‣ PHPUnitͰ୯ମςετɾ݁߹ςετ
    ‣ εςʔδϯά؀ڥ΁ͷσϓϩΠ
    GitLab CIͰฐ͕ࣾ΍ͬͯΔ͜ͱ

    View full-size slide

  20. PHPStanͰ੩తղੳ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  25. (1)PUSH
    (2)GitLab CI࣮ߦ (3)ίϯςφىಈ
    Gitlab
    (6)Envoy࣮ߦ
    ςετ࣮ߦ
    ίϯςφ
    σϓϩΠ࣮ߦ
    ίϯςφ
    (5)ίϯςφىಈ
    (4)UnitTest࣮ߦ
    (7)Pull
    ຊ൪؀ڥ
    or
    εςʔδϯά؀ڥ
    ϦϙδτϦ
    GiaLab CI
    ࣮ߦϑϩʔ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  31. (1)PUSH
    (2)GitLab CI࣮ߦ (3)ίϯςφىಈ
    Gitlab
    (6)Envoy࣮ߦ
    ςετ࣮ߦ
    ίϯςφ
    σϓϩΠ࣮ߦ
    ίϯςφ
    (5)ίϯςφىಈ
    (4)UnitTest࣮ߦ
    (7)Pull
    ຊ൪؀ڥ
    or
    εςʔδϯά؀ڥ
    ϦϙδτϦ
    ςετɾσϓϩΠͷ࣮ߦΛߦ͏
    ίϯςφͷݩͱͳΔ
    DockerΠϝʔδ͕ඞཁ
    ϩʔΧϧͰ࡞੒ͨ͠DockerΠϝʔδΛ
    GitLab Container Registryʹొ࿥

    View full-size slide

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

    View full-size slide

  33. (1)PUSH
    (2)GitLab CI࣮ߦ (3)ίϯςφىಈ
    Gitlab
    (6)Envoy࣮ߦ
    ςετ࣮ߦ
    ίϯςφ
    σϓϩΠ࣮ߦ
    ίϯςφ
    (5)ίϯςφىಈ
    (4)UnitTest࣮ߦ
    (7)Pull
    ຊ൪؀ڥ
    or
    εςʔδϯά؀ڥ
    ϦϙδτϦ
    Push͞ΕͨλΠϛϯάͰϦϙδτϦʹ
    .gitlab-ci.ymlͱ͍͏ϑΝΠϧ͕͋Ε͹
    ͦͷதʹهࡌ͞Εͨδϣϒ͕࣮ߦ͞ΕΔ
    .gitlab-ci.ymlΛ࡞੒

    View full-size slide

  34. .gitlab-ci.yml
    σϓϩΠ࣮ߦίϯςφ
    ͷॲཧ಺༰Λهड़
    ςετ࣮ߦίϯςφͰ
    ࢖༻͢ΔαʔϏε΍
    ॲཧ಺༰Λهड़
    ࢖༻͢ΔDockerΠϝʔδ
    envoyίϚϯυʂ

    View full-size slide

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

    View full-size slide

  36. (1)PUSH
    (2)GitlabCI࣮ߦ (3)ίϯςφىಈ
    Gitlab
    (6)Envoy࣮ߦ
    ςετ࣮ߦ
    ίϯςφ
    σϓϩΠ࣮ߦ
    ίϯςφ
    (5)ίϯςφىಈ
    (4)UnitTest࣮ߦ
    (7)Pull
    ຊ൪؀ڥ
    or
    εςʔδϯά؀ڥ
    ϦϙδτϦ
    σϓϩΠ࣮ߦίϯςφͰenvoyίϚϯυ
    ͕࣮ߦ͞ΕɺEnvoy.blade.phpʹهड़ͨ͠
    ॲཧ͕࣮ߦ͞ΕΔ
    Envoy.blade.phpΛ࡞੒

    View full-size slide

  37. Envoy.blade.php ෳ਺ͷσϓϩΠઌΛهड़Մೳ
    EnvoyͷதͰ࢖༻͢Δ
    άϩʔόϧม਺తͳͷΛఆٛ
    ۩ମతͳॲཧΛ৭ʑͱهड़
    @serversσΟϨΫςΟϒͰࢦఆͨ͠ϗετʹSSH઀ଓ͠ɺ
    ͦͷ಺෦Ͱ@storyσΟϨΫςΟϒ಺ͷॲཧ͕࣮ߦ͞ΕΔ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  42. getϝιουͷྫ

    View full-size slide

  43. postϝιουͷྫ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  46. ɾۄͶ͗ͷΑ͏ͳߏ଄ͰϦΫΤετͱ
    Ϩεϙϯεͷؒʹ༷ʑͳॲཧΛڬΈࠐ
    Έ΍͍͢
    ɾόϦσʔγϣϯͳͲ΋୯ҰͷΤϯςΟ
    ςΟʹґଘ͢ΔͷͰ͸ͳ͘ɺForm୯
    ҐͰ࣮૷Ͱ͖Δ
    MiddleWareͷྫ
    ೝ ূ ν Σ ο Ϋɺ ό Ϧ σ ʔ γ ϣ ϯɺ
    CSRFτʔΫϯͷνΣοΫ
    [ิ଍] Middlewareͱ͸ʁ

    View full-size slide

  47. ϞοΫԽͷ࢓૊Έ͕ศར

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide