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

GoConference_人生いろいろモノレポもいろいろ

 GoConference_人生いろいろモノレポもいろいろ

More Decks by 株式会社ビットキー / Bitkey Inc.

Other Decks in Technology

Transcript

  1. 1. ࣗݾ঺հ 3 • ∁ڮయੜ(Noriki Takahashi) ◦ Twitter: @norinoriki0 ◦

    GitHub: nrnrk • גࣜձࣾBitkey ◦ bitkey platform ͱ͍͏”ΧΪ”ͷϓϥοτϑΥʔϜͷ։ൃ • 2೥൒ Go Ͱ։ൃ͍ͯ͠·͢ • झຯ: ਺ֶɾ෺ཧֶ ◦ zk-SNARKs ͷ਺ֶతͳଆ໘ΛטΈࡅ͘هࣄΛॻ͍ͨΓͯ͠·͢
  2. 2. എܠͱͯ͠ͷ͘͠͡Γ 21 ᶃ ڞ௨ϥΠϒϥϦͷѻ͍͕͏·͍͔͘ͳ͍ ◦ ֤ϦϙδτϦͰಉ͡Α͏ͳϩδοΫ͕ग़ͯ͘Δ ▪ → ϘΠϥʔϓϨʔτԽ

    ◦ ղܾ͠Α͏ͱɺڞ௨ϥΠϒϥϦԽ͢Δ ▪ → ڞ௨ϥΠϒϥϦΛઌʹमਖ਼ͯ͠Ϛʔδ͠ͳ͍ͱ࢖͑ͳ͍... ▪ → ʮ͜Εमਖ਼ͨ͠Βଞʹ΋Өڹ͋ΔΜ͡Ό...ʯ ◦ → ڞ௨ϥΠϒϥϦ͕ൃల͠ͳ͍ & ϘΠϥʔϓϨʔτ΋ੜ·Ε΍͍͢
  3. ᶄ Go ͷόʔδϣϯ΍ϥΠϒϥϦͷߋ৽͕େม ◦ ʮ͋ɺ͜ͷϥΠϒϥϦ service A Ͱ͸ v2 ͚ͩͲɺ

    service B ͸ v1 ͳΜͩʯ ▪ service A Λ্͛ͨλΠϛϯάͰ্͓͚͛ͯΕ͹... ◦ ʮ͊͞ɺGo 1.17 ͕ϦϦʔε͞Εͨͧʯ ▪ → ֤ϦϙδτϦͰͪΐͪ͜ΐ͜PRΛग़͢͜ͱʹ... ◦ Dependabot PR ϙνϙν... 2. എܠͱͯ͠ͷ͘͠͡Γ 23
  4. ᶅ ϚʔδͷλΠϛϯάΛ͋Θͤͳ͍ͱ͍͚ͳ͍ ◦ ͜ͷ։ൃ service A ͱ service B ͷमਖ਼͕ඞཁͩ

    ▪ → ͋ɺͰ΋ service A ͸ service B ʹґଘ͍ͯ͠Δ͔Βɺservice B Λઌ ʹϚʔδ͠ͳ͍ͱ service A ͷ CI ͕ࣦഊ͢Δͧ... ◦ ͞ΒʹɺgRPC ͷͨΊͷ proto ϑΝΠϧΛαʔόʔଆ ஔ͍ͨ͜ͱͰෳࡶԽ ▪ ΫϥΠΞϯτଆͰίʔυੜ੒͢Δࡍʹ proto ϑΝΠϧΛμ΢ϯϩʔυ͢ Δߏ੒ʹͳͬͯ͠·ͬͨ... 2. എܠͱͯ͠ͷ͘͠͡Γ 25
  5. • ϞϊϨϙ(Mono Repository) ◦ ෳ਺ͷύοέʔδ(Ϟδϡʔϧ)ΛҰͭͷϦϙδτϦͰ؅ཧ͢Δ͜ͱ ◦ ϝϦοτ ▪ Ұׅ؅ཧ͕͠΍͍͢ ◦

    σϝϦοτ ▪ ಛఆͷύοέʔδ͔Β͢Δͱແؔ܎ͳ΋ͷ͕ଟ͍(ιʔεɺίϛοτ) ◦ ࠓճͷࣄྫ ▪ 1νʔϜ͕؅ཧ͍ͯͨ͠10ఔ౓ͷϦϙδτϦͷ౷߹(খن໛) 3. Go ϞϊϨϙͷ෼ྨ 32
  6. 3. Go ϞϊϨϙͷ෼ྨ 35 • ϞϊϨϙͰͷղফΠϝʔδ ◦ ෳ਺ͷύοέʔδͷίϛοτɾϚʔδΛΞτϛοΫʹͰ͖Δ ▪ Ϛʔδॱ൪ͳͲؾʹ͠ͳͯ͘ྑ͍

    ▪ ؾܰʹڞ௨ϥΠϒϥϦΛ੾Γग़ͤͯɺϝϯςφϯε΋͠΍͍͢ ▪ CI Ͱύοέʔδؒͷςετ͕Ͱ͖Δ
  7. 3. Go ϞϊϨϙͷ෼ྨ 37 • ϞϊϨϙͰͷղফΠϝʔδ ◦ ෳ਺ͷύοέʔδͷίϛοτɾϚʔδΛΞτϛοΫʹͰ͖Δ ▪ Ϛʔδॱ൪ͳͲؾʹ͠ͳͯ͘ྑ͍

    ▪ ؾܰʹڞ௨ϥΠϒϥϦΛ੾Γग़ͤͯɺϝϯςφϯε΋͠΍͍͢ ▪ CI Ͱύοέʔδؒͷςετ͕Ͱ͖Δ ◦ ґଘͷڞ௨Խͤ͞Δ͜ͱ͕Ͱ͖Δ ▪ Ұׅͯ͠ɺGo΍ϥΠϒϥϦͷߋ৽ɾ؅ཧ͕Ͱ͖Δ
  8. 3. Go ϞϊϨϙͷ෼ྨ 41 • Go module ʹ஫໨ͨ͠෼ྨ ◦ go.mod

    Ұ͚ͭͩ: Mono Module ▪ root ʹ go.mod Λ͓͍ͯɺશମΛҰͭͷ Go Module ͱͯ͠ѻ͏ํ๏ ▪ → ಠཱੑ͕௿͍(go.mod ʹॻ͔ͣʹґଘͰ͖Δ) ◦ go.mod ͨ͘͞Μ: Multi Module ▪ ֤σΟϨΫτϦʹ go.mod Λஔ͖ɺͦΕͧΕΛ Go Module ͱͯ͠ѻ͏ ▪ → ಠཱੑ͕ߴ͍(go.mod ʹॻ͔ͳ͍ͱґଘͰ͖ͳ͍)
  9. • Mono Module બΜͩཧ༝: ֤՝୊ͷղফ ◦ ᶃ ڞ௨ϥΠϒϥϦͷѻ͍͕͏·͍͔͘ͳ͍ ▪ ͜Ε͔Β͸

    Go package ͱͯ͠ڞ௨ϥΠϒϥϦΛ࡞Ε͹OK ▪ ୯ମςετΛॻ͘͜ͱͰڞ௨ϥΠϒϥϦͷमਖ਼΋͠΍͘͢ 3. Go ϞϊϨϙͷ෼ྨ 52
  10. • Mono Module બΜͩཧ༝: ֤՝୊ͷղফ ◦ ᶃ ڞ௨ϥΠϒϥϦͷѻ͍͕͏·͍͔͘ͳ͍ ▪ ͜Ε͔Β͸

    Go package ͱͯ͠ڞ௨ϥΠϒϥϦΛ࡞Ε͹OK ▪ ୯ମςετΛॻ͘͜ͱͰڞ௨ϥΠϒϥϦͷमਖ਼΋͠΍͘͢ ◦ ᶄ Go ͷόʔδϣϯ΍ϥΠϒϥϦͷߋ৽͕େม ▪ ϧʔτͷ go.mod ͱ .go-version ͷॻ͖׵͑ͰOK 3. Go ϞϊϨϙͷ෼ྨ 53
  11. • Mono Module બΜͩཧ༝: ֤՝୊ͷղফ ◦ ᶃ ڞ௨ϥΠϒϥϦͷѻ͍͕͏·͍͔͘ͳ͍ ▪ ͜Ε͔Β͸

    Go package ͱͯ͠ڞ௨ϥΠϒϥϦΛ࡞Ε͹OK ▪ ୯ମςετΛॻ͘͜ͱͰڞ௨ϥΠϒϥϦͷमਖ਼΋͠΍͘͢ ◦ ᶄ Go ͷόʔδϣϯ΍ϥΠϒϥϦͷߋ৽͕େม ▪ ϧʔτͷ go.mod ͱ .go-version ͷॻ͖׵͑ͰOK ◦ ᶅ ϚʔδͷλΠϛϯάΛ͋Θͤͳ͍ͱ͍͚ͳ͍ ▪ શ෦ҰॹʹͳΔͷͰOK 3. Go ϞϊϨϙͷ෼ྨ 54
  12. • Ҡߦͷํ਑ ◦ Mono Module Monorepo ͰҠߦ͢Δ ◦ εϞʔϧελʔτͱͯ͠ɺGoͷϦϙδτϦͷΈͰ࣮ࢪ ◦

    Mono Module + গ͠ Bazel ▪ ڞ௨ͯ͠࢖͏ϥΠϒϥϦ͕ଟ͘ɺύοέʔδͷಠཱੑ͕ඞཁͳ͍ ▪ ϏϧυͷύϑΥʔϚϯεͷ޲্΍ࠓޙϞϊϨϙͷൣғΛ޿͛Δͱ͖ʹ ར༻Ͱ͖ΔΑ͏ʹɺඞཁʹԠͯ͡গͣͭ͠ Bazel ΛೖΕ͍ͯ͘ 3. Go ϞϊϨϙͷ෼ྨ 55
  13. • ίʔυͷमਖ਼ ◦ git clone ͰϦϙδτϦͷऩू ◦ import จͷमਖ਼ ▪

    `github.com/organization/serviceA` → `github.com/organization/ XXXservice/serviceA` 4. ϞϊϨϙҠߦͱࠓޙ 59
  14. • ίʔυͷमਖ਼ ◦ git clone ͰϦϙδτϦͷऩू ◦ import จͷमਖ਼ ▪

    `github.com/organization/serviceA` → `github.com/organization/ XXXservice/serviceA` ◦ go.mod ͷ౷߹ ▪ ؆୯ʹίϐϖͰҰͭʹ·ͱΊΕ͹OK ▪ ϥΠϒϥϦͷόʔδϣϯͱ͔ἧ͍͑ͨͳΒదٓमਖ਼ 4. ϞϊϨϙҠߦͱࠓޙ 60
  15. • CI ରԠ ◦ ҎԼΛຬͨ͢Α͏ʹमਖ਼ ▪ ෆཁͳϏϧυΛճ͞ͳ͍Α͏ʹ͍ͨ͠ ▪ मਖ਼ͨ͠ൣғʹґଘ͍ͯ͠Δͱ͜ΖͷϏϧυ͸ճ͍ͨ͠ ◦

    CI ʹΑͬͯ͸ɺpath filtering ͱ͍͏ػೳΛ࢖࣮ͬͯݱͰ͖Δ͜ͱ͕ଟ͍ 4. ϞϊϨϙҠߦͱࠓޙ 65
  16. 4. ϞϊϨϙҠߦͱࠓޙ • Ҡߦʹؔͯ͠ؾ͍ͮͨ͜ͱ ◦ νʔϜ಺͔ͭಉҰݴޠͰ·ͱΊΔͷ͸ͦ͜·Ͱେม͡Όͳ͔ͬͨ ▪ νʔϜϝϯόʔͰগͣͭ͠ΩϟονΞοϓ͍ͯ͘͜͠ͱ͕Ͱ͖Δ ◦ ίʔυੜ੒ܥΛ

    Bazel Ͱ΍͍ͬͯ͘ͷ͸େม ▪ mockgen ͸ࣗલͷ rule Λ࡞੒͕ͨ͠ɺͳΕΔ·Ͱ͔ͳΓݫ͍͠ ◦ ࣄલʹϥΠϒϥϦͷߋ৽Λ࣮ࢪ͓͔ͯ͠ͳ͍ͱେม ▪ 3ͭҎ্ͷόʔδϣϯ͕͔ͪ߹͏͜ͱ΋... 69
  17. • ·ͱΊ ◦ Mono Module Monorepo ͱ Multi Module Monorepo

    ▪ ಠཱੑ͕ͲΕ͚ͩඞཁ͔Ͱબ୒͢Δ ◦ Go ϞϊϨϙ͸ϏϧυπʔϧΛؤுΓ͗ͣ࢝͢ΊΔͷ͕͓͢͢Ί ▪ Bazel Ͱ׬શʹ΍Ζ͏ͱ͢Δͱ௒େม ▪ → ඞཁʹԠͯ͡গͣͭ͠ೖΕ͍ͯ͘ ◦ ϞϊϨϙԽʹΑͬͯDX(։ൃମݧ)͕վળͰ͖ͨ ▪ 1νʔϜ಺ͷϚΠΫϩαʔϏεͳΒσϝϦοτগͳ͓͘͢͢Ί 5. ·ͱΊ 72