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

GoとNature ~ Nature Remoの裏側 / Nature Bath vol6

07ecb4f6c2111bff7ab4f0412edc773d?s=47 Songmu
December 02, 2020

GoとNature ~ Nature Remoの裏側 / Nature Bath vol6

07ecb4f6c2111bff7ab4f0412edc773d?s=128

Songmu

December 02, 2020
Tweet

Transcript

  1. ݫൿɿຊࢿྉͷҰ෦·ͨ͸શ෦ΛɺNatureגࣜձࣾͷڐՄͳ͠ʹɺෳ੡ɺసࡌ͢Δ͜ͱΛې͡·͢ɻ Introduce about September 3, 2019 Natureגࣜձࣾ Go ͱ Nature

    Bath vol.6 ʮGo։ൃɾӡ༻ͷݱ৔ʯ 19th November, 2020 ~ Nature Remoͷཪଆ
  2. 2 Me • দ໦ խ޾ (id:Songmu) • Nature גࣜձࣾ औక໾CTO

    • https://songmu.jp/riji • https://github.com/Songmu • ޷͖ͳݴޠ͸GoͱPerlͱதࠃޠ • 3 Times ISUCON Winner • ஶॻʹʮΈΜͳͷGoݴޠʯ౳ • झຯ͸OSS׆ಈͰ͢
  3. 3 Created Miscellaneous Go Tools • maltmill • πʔϧΛ؆୯ʹhomebrewͰ഑෍͢ΔͨΊͷπʔϧ •

    horenso • όονδϣϒͷͨΊͷϥούʔ • peep • ϓϩηεͷऴྃ௨஌Λͯ͘͠ΕΔ܅ • gocredits • Goͷπʔϧ഑෍࣌ʹґଘϥΠϒϥϦͷLICENSEΛಉࠝ • etc. • ref. ʮGoͰπʔϧΛྔ࢈͢Δ๻ͷํ๏ʯ • https://junkyard.song.mu/slides/gocon2019-fukuoka/#0
  4. 4 Maintaining major Go tools • ghq (github.com/x-motemen/ghq) • ιʔείʔυϦϙδτϦ؅ཧπʔϧ

    • ghq handbook • https://leanpub.com/ghq-handbook • ghr (github.com/tcnksm/ghr) • GitHub΁ͷόΠφϦϦϦʔε༻πʔϧ
  5. 5 Recent Works • Let's Encryptͷϧʔτূ໌ॻมߋ໰୊ • Android7.1ҎલͰLet's Encryptূ໌ॻͷαΠτ͕ݟΒ Εͳ͘ͳΔ

    • https://songmu.jp/riji/entry/2020-09-22-letsencrypt.html • Let's Encryptͷূ໌ॻ੾ସपΓͦͷޙ • https://songmu.jp/riji/entry/2020-09-22-letsencrypt.html
  6. 6 Recent Works • GoͷΫϥΠΞϯτ΁ͷରԠ • ͝ར༻͍ͩ͘͞

  7. 7 ৽࡞ • github.com/Songmu/gotesplit • github.com/Songmu/ecschedule • ޙͰղઆ͠·͢

  8. 8 We are Hiring • GoΤϯδχΞઈࢍืूதͰ͢ʂ • ݱࡏ3໊ • ιϑτ΢ΣΞΤϯδχΞ͸7໊

  9. ࠓ೔࿩͢͜ͱ Agenda 9

  10. 10 Agenda • ܰ͘Nature Remoͷ঺հ • Nature RemoͱGo • ೔ʑͷGo׆༻΍OSS׆ಈͳͲ

  11. ձࣾͱ੡඼ Company and Product 11

  12. Mission 12 Mission ⾃然との共⽣を テクノロジーでドライブする

  13. Product

  14. ֎ग़ઌ͔ΒεϚϗͰΤΞίϯΛON εϚʔτεϐʔΧʔͱ࿈ܞͯ͠੠ͰՈిΛૢ࡞ 14 Features

  15. How It Works

  16. Traction 20ສ୆ಥഁ ೝ஌ˍγΣΞۀքNo.1 ʢ2020೥2݄࣮ࢪɺࣗࣾௐ΂ʣ

  17. Nature RemoͱGo Nature Remo and Go 17

  18. API Stream Worker Amazon ECS Subscribe Publish WS WS Pub/Sub

    System Diagram
  19. Nature Remoͷཪଆ • αʔόʔαΠυ͸΄΅શͯGo • ࣮͸ׂͱී௨ͷWebٕज़Λ࢖࣮ͬͯݱ͍ͯ͠Δ • WebSocketͷ઀ଓ؅ཧपΓ͕νϟϨϯδϯά • αʔϏε΋ٸ੒௕த

  20. Components • API • εϚϗΞϓϦ΍εϚʔτεϐʔΧʔͱͷ௨৴ • Stream • Nature RemoͱͷWebSocket௨৴

    • Worker • ϧʔϧͷ࣮ߦ ͢΂ͯGo੡ͰAmazon ECS্Ͱಈ͔͍ͯ͠Δ
  21. Remarkable Points • ૉ๿ͳGo੡ͷWebΞϓϦέʔγϣϯ • Redis Pub/SubΛ༻͍ͨɺAPI - Streamؒͷ΍ΓͱΓ •

    Nature Remo͸ALBΛܦ༝ͯ͠streamαʔόʔʹ WebSocket઀ଓ͍ͯ͠Δ • AlexaͷΧελϜεΩϧ͸AWS Lambdaܦ༝Λ࢖࣮ͬͯߦ ͞ΕΔ
  22. Simple Web Applications with Go • ී௨ͷWebΞϓϦέʔγϣϯ • ΋ͱ΋ͱherokuͰϗετ໊͍ͯͨ͠࢒΋ •

    ϑϨʔϜϫʔΫ • github.com/nbio/hitch • Gorilla web toolkitΛ෦෼తʹར༻ • MySQL/Redis • gorp/redigo • guregu/dynamo
  23. Utilize Redis Pub/Sub • Redis Pub/SubΛ׆༻͍ͯ͠Δ • API͔Β͸RedisʹPublish • Stream͸RedisΛSubscribe

    • ૬ޓ௨৴͠ͳ͍ૄ݁߹Λ࣮ݱ͍ͯ͠Δ • Streamଆ͸͋͘·ͰWebSocketͱRedis͔ΒͷSubscribeͰ ड͚෇໋͚ͨྩͷ࣮ߦ͔͓͜͠ͳΘͣঢ়ଶΛ࣋ͨͳ͍
  24. WebSocket connection via ALB • Nature Remo͸ALBΛܦ༝ͯ͠streamαʔϏεʹ WebSocket઀ଓ͍ͯ͠Δ • ҰͭͷGoΞϓϦͷίϯςφͰ਺ສ઀ଓ͞͹͚Δʂ

    • Goͷ͓खܰͳྑ͞Λ࣮ײ • Go͸खܰʹͦΕͳΓͷύϑΥʔϚϯε͕ग़ͤΔͷ͕͔ͳΓ ྑ͍
  25. ೔ʑͷ։ൃɾӡ༻ Go Topics 25

  26. ೔ʑͷۀ຿ • GitHub্Ͱ։ൃ • CircleCI্ͰCI/CD • developϒϥϯν͔ΒfeatureϒϥϯνΛ੾Δ • ϨϏϡʔͯ͠Ϛʔδ •

    renovateʹΑΔϥΠϒϥϦࣗಈΞοϓσʔτ • developϒϥϯν͔Βmasterϒϥϯν΁ͷpull request • git-pr-releaseʹΑͬͯࣗಈ࡞੒ • Ϛʔδ͞ΕͨΒࣗಈͰຊ൪deploy
  27. CI/CD Pipelines git-pr-release git push go test go build docker

    build docker push ecspresso deploy 1 2 3 4
  28. ECSͷdeployʹecspressoಋೖ • github.com/kayac/ecspresso • ecs-deploy͔Β৐Γ׵͑ • ৐Γ׵͑ઌͱͯͪ͠ΐ͏ͲΑ͔ͬͨ • طଘͷTask DefinitionΛར༻ͯͦ͠ͷ··γʔϜϨεʹ

    ҠߦՄೳ • CircleCI͔Βdeploy͍ͯ͠Δ • ଞʹ΋ kayac/go-katsubushi ͳͲkayac OSSΛ׆༻
  29. ECS Task Definition͕reviewableʹ • Task΁ͷαΠυΧʔ௥Ճ΍ύϥϝʔλʔมߋ͕reviewable ʹͳͬͨͷ͸ྑ͔ͬͨ

  30. github.com/Songmu/flextime • ςετͰ࣌ࠁܥΛࠩ͠ସ͑ΔͨΊͷϥΠϒϥϦ • timeύοέʔδͱಉ༷ͷΠϯλʔϑΣʔεΛඋ͑Δ

  31. github.com/Songmu/smartcache • ϓϦϑΣον͢ΔΠϯϝϞϦΩϟογϡ • Ωϟογϡߋ৽ॲཧ͕ • ॏෳ͠ͳ͍Α͏ʹɾϒϩοΫ͠ͳ͍Α͏ʹ

  32. ECS Scheduled Task؅ཧͷͨΊͷπʔϧecschedule • github.com/Songmu/ecschedule • όονྨ͸ɺECSͷScheduled TaskΛར༻͍ͯ͠Δ͕ͦΕ Λόʔδϣϯ؅ཧ͍ͨ͠ͱ͍͏ಈػ

  33. খωλ: όονྨͷಈ͔͠ํ • APIͱworkerͱόον͸ಉ͡GoόΠφϦɺಉ͡ίϯςφ • Task Definition͸ҧ͏΋ͷ΋ • αϒίϚϯυͰॲཧΛ෼͚Δ •

    nature server: APIαʔόʔͷىಈ • nature squadrons: ϫʔΧʔͷىಈ • nature batch hoge ... : όονྨͷىಈ
  34. 34 ςετߴ଎ԽͷͨΊͷgotesplit • github.com/Songmu/gotesplit • CI؀ڥͰͷςετฒྻ࣮ߦΛ؆୯ʹ࣮ݱ • CircleCI / GitHub

    Actions • ࣾ಺ͷςετ͕࣌ؒ15෼->5෼ʹ • ͔ͳΓศརͳͷͰͥͻ͝ར༻͍ͩ͘͞
  35. 35 @soh335࡞ͷOSS • github.com/soh335/go-test-redisserver • github.com/soh335/shukujitsu (new!) • github.com/schemalex/schemalex •

    ← ͜Ε͸·ͩಋೖग़དྷ͍ͯͳ͍
  36. 36 github.com/soh335/shukujitsu • ࡢ൩஀ੜ • ҎԼͷσʔλΛ΋ͱʹ೔ຊͷॕ೔൑ఆ • https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv • ͜Ε͸typoͰ͸͋Γ·ͤΜ

    • σʔλϑΥʔϚοτ͸ឯ༨ۂં͋ͬͨΑ͏͕ͩࠓ͸ׂͱ·ͱ΋
  37. 37 ࣗ࡞OSSΛຊ൪ʹಋೖ͢Δ • ͱΓ͋͑ͣOSSͰ࡞ͬͯΈΔ • ࢼ͠ʹຊ൪౤ೖͯ͠͠·͏

  38. OSS΁ͷpull request 38

  39. 39 nbio/hitch#11

  40. 40 nbio/hitch#12

  41. 41 kayac/go-katsubushi#40

  42. 42 blang/semver#56

  43. 43 pressly/goose#180

  44. 44 pressly/goose#181

  45. 45 kayac/ecspresso#37

  46. 46 kayac/ecspresso#38

  47. 47 kayac/ecspresso#161

  48. 48 guregu/dynamo#106

  49. 49 goccy/go-yaml#23

  50. 50 goccy/go-yaml#36

  51. 51 go-gorp/gorp#411

  52. 52 manifoldco/promptui#132

  53. 53 shogo82148/go-sql-proxy#42

  54. 54 OSS΁ͷpull request • ʮڠௐʯͰ͖Δ͔Λॏࢹ • pull requestΛૹͬͯΈͯ୳ΓΛೖΕΔ • ࢥ૝͕Ϛον͍ͯͦ͠͏͔

    • ϝϯςφϯε͕ΞΫςΟϒ͔ • ϝϯςφϯε͕ࢭ·ͬͯΔͱࢥ͍͖΍͙͢ʹ ରԠͯ͘͠ΕΔ͜ͱ΋ • 1೥ܦ͔ͬͯΒϚʔδ͞ΕΔ͜ͱ΋
  55. ·ͱΊ 55

  56. Natureͷ։ൃ • αʔόʔαΠυ͸΄΅શ෦Go • 10ສ୆௒͑ͷIoTσόΠεΛϋϯυϦϯά͢ΔWebSocketίϯςφ܈ • αʔόʔଆͷ੍ޚ͕݁ߏϔϏʔͰ໘ന͍ • ૊ΈࠐΈ΍Appͱͷ࿈ܞͷ໘ന͞ •

    OSSΛͪΌΜͱ׆༻͍ͨ͠ • ڠௐͰ͖ΔOSSΛબΜͰߩݙ΋͍ͯ͘͠ • OSSʹͰ͖Δ΋ͷ͸ͯ͠͠·͏
  57. We are Hiring! ੵۃ࠾༻தͰ͢ʂ • όοΫΤϯυΤϯδχΞ • εϚʔτϑΥϯΤϯδχΞ • ϑϩϯτΤϯυΤϯδχΞ

    • ػցֶशΤϯδχΞ • ૊ΈࠐΈΤϯδχΞ