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

Lerna + TypeScript + Serverless FrameworkではじめるC...

Lerna + TypeScript + Serverless FrameworkではじめるCircleCIでのAPIデプロイ/ circlecijp-201907

【大阪】CircleCI ユーザーコミュニティミートアップ #1

Hidetaka Okamoto

July 16, 2019
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

  1. L e r n a + Ty p e S

    c r i p t + S e r v e r l e s s F r a m e w o r k Ͱ ͸ ͡ Ί Δ C i rc l e C I Ͱ ͷ A P I σ ϓ ϩ Π ʲ େ ࡕ ʳ C i rc l e C I Ϣʔ βʔί ϛ ϡχςΟϛ ʔ τΞ οϓ # 1 #circlecijp
  2. H i d e t a k a O k

    a m o t o • Digitalcube Co. Ltd. • Alexa Campions • AWS Samurai 2017 in Japan
  3. D i g i t a l c u b

    e Ͱ ͷ C i rc l e C I ར ༻ ঢ় گ #circlecijp
  4. D i g i t a l c u b

    e Ͱ ͷ C i rc l e C I ར ༻ ঢ় گ • SaaSܥͰ͸΄΅શPJར༻ • Dockerίϯςφ / Serverless Framework / React / AWS AMI etc … • ෳ਺ਓ͕֤PJͰͦΕͧΕCIΛ·Θ͢ͷͰɺFreeͩͱͨ·ʹ٧·Δ • ༗ྉϓϥϯʹͯ͠Linuxίϯςφ2ͭΛར༻த #circlecijp
  5. ͦ ͷ ଞ ͷ C I α ʔ Ϗ ε

    ʹ ͭ ͍ͯ • Circle CI͸δϣϒ਺ʢίϯςφ਺ʣͰͷ՝ۚ • OSS͸Travis CIΛར༻ͯ͠δϣϒΛ෼ࢄ • ECS / SAM (CloudFormation)ܥ͸CodeBuild (with CodePipeline) • ϓϥΠϕʔτrepo΍3rd PartyπʔϧͰσϓϩΠ͢Δ࣌͸CircleCI #circlecijp
  6. L e r n a + Ty p e S

    c r i p t + S e r v e r l e s s F r a m e w o r k Ͱ ͸ ͡ Ί Δ C i rc l e C I Ͱ ͷ A P I σ ϓ ϩ Π #circlecijp
  7. ϥ Π ϒ ϥ Ϧ ͱ ϓ ϩ δΣ Ϋ

    τ Λ ̍ re p o Ͱ ؅ ཧ
  8. ͳ ͥ Ϟ ϊ Ϩϙ ʹ ͠ ͨ ͔ ʁ

    • API / Batch͸AWS / Stripe΁ͷAPIίʔϧ͕΄΅ϝΠϯ • DynamoDBΫΤϦ΍StripeͷAPIϨεϙϯεͷߜΓࠐΈॲཧ͕૿Ճ • PJ͝ͱʹϥούʔతϝιουɾؔ਺͕ൃੜɺDRYͰͳ͘ͳΔ • ϥούʔ܈͸OSSʹ͍ͨ͠Θ͚Ͱ͸ͳ͍ • ϞϊϨϙʹͯ͠ɺશPJಉ͡ιʔεΛࢀর͢ΔΑ͏ʹมߋ #circlecijp
  9. L e r n a - Ϟ ϊ Ϩϙ ؅

    ཧ ͷ ͨ Ί ͷ ϥ Π ϒ ϥ Ϧ • npm i -D lerna • `packages/`഑ԼʹnpmϓϩδΣΫτΛ഑ஔ͢ΔʢDefaultʣ • lernaίϚϯυͰશϓϩδΣΫτʹରͯ͠npm-script͕࣮ߦՄೳ • —scopeΛ͚ͭΔͱϓϩδΣΫτࢦఆ΋Մೳʢෳ਺Մʣ • lerna addΛ࢖͏ͱϓϩδΣΫτಉ࢜ΛϦϯΫͰ͖Δʢsymlinkʣ #circlecijp
  10. L e r n a Λ ࢖ ͬͯ ͍ Δ

    P J ͷ ྫ • Gutenberg - WordPressͷ৽͍͠ϒϩοΫΤσΟλ • ASK SDK - Amazon Alexa޲͚SDK (Node.js൛ͷΈ) • AWS Amplify - AWSͰΞϓϦΛ࡞Δͱ͖ͷϑϨʔϜϫʔΫ • ASK Utils - ASK SDKΛศརʹ࢖͏ͨΊͷSDK (made by Զ) • AmazonܥͷNode.jsϥΠϒϥϦ͸͍͍ͩͨLerna؅ཧ #circlecijp
  11. ෼ ׂ ͷ ํ ๏ • ਖ਼௚ख୳Γ • Stripe /

    AWS / TerraformͳͲɺΞΫηε͢ΔαʔϏεͰ෼ׂ • ʮಛఆϓϥϯͷϢʔβʔͷΈௐ΂ΔʯͳͲͷΑ͘࢖͏λεΫ͕ൃੜ • workerͱ͍͏໊લͰ΋͏̍ͭ૚Λ௥Ճͨ͠ #circlecijp
  12. ΍ ͬͯ Α ͔ ͬ ͨ ͜ ͱ • ࠶ར༻Ͱ͖Δίʔυ͕૿͑ͨ

    • webpackͰϏϧυ͔ͯ͠Β࢖͏ͷͰɺLambdaͷαΠζ΋গ͠ݮͬͨ • 1repoʹ·ͱ·͍ͬͯΔͷͰɺPJ͕୳͠΍͍͢ • ࢖༻͢Δύοέʔδͷόʔδϣϯ΍tsconfigͳͲΛἧ͑ΕΔ #circlecijp
  13. ͭ Β ͍ ͱ ͜ Ζ • ͍ΖΜͳPJͰ࢖͏ͷͰɺԼखʹߋ৽Ͱ͖ͳ͘ͳͬͨ • ϥΠϒϥϦଆ͸ܕఆٛ΍ςετ͔ͬ͠Γ΍Βͳ͍ͱ΍͹͍

    • ෼ׂ͗͢͠Δͱ௥͍͔͚Δͷ͕େม • ϥΠϒϥϦͷϏϧυΛ๨ΕΔͱPJ͕Ξϓσ͞Εͳ͍ • CI / CDͲ͏͢Δͷ໰୊ #circlecijp
  14. ͭ Β ͍ ͱ ͜ Ζ • ͍ΖΜͳPJͰ࢖͏ͷͰɺԼखʹߋ৽Ͱ͖ͳ͘ͳͬͨ • ϥΠϒϥϦଆ͸ܕఆٛ΍ςετ͔ͬ͠Γ΍Βͳ͍ͱ΍͹͍

    • ෼ׂ͗͢͠Δͱ௥͍͔͚Δͷ͕େม • ϥΠϒϥϦͷϏϧυΛ๨ΕΔͱPJ͕Ξϓσ͞Εͳ͍ • CI / CDͲ͏͢Δͷ໰୊ #circlecijp
  15. L e r n a Ψ ο π Ϧ ࢖

    ͬ ͨ ͱ ͖ ͷ C i rc l e C I ར ༻ ʹ ͭ ͍ͯ #circlecijp
  16. L e r n a ࢖ ͏ ͱ Կ ͕

    ͭ Β ͘ ͳ Δ ͔ ʁ • PJͷϧʔτσΟϨΫτϦ͕มΘΔɻ • Before: <root> • After: <root>/packages/<PJ>/ • PJ਺͕૿͑Δͱɺδϣϒͷ࣮ߦ͕࣌ؒ௕͘ͳΔ • .circleci/config.yml͕ΧΦεʹͳΔ #circlecijp
  17. ͳ ʹ ͕ ͓ ͖ ͨ ʁ • Workflowؤுͬͨ •

    PJ͝ͱʹϏϧυΛఆٛ • filterͰϏϧυ͢ΔϒϥϯνΛࢦఆ • PJಉ࢜Ͱґଘ͍ͯ͠Δ৔߹͸ɺࣄલʹϏϧυ͕ඞཁ • requiresͰґଘ͢ΔϏϧυΛ࣮ߦ͢ΔΑ͏ʹࢦఆ #circlecijp
  18. C i rc l e C I ্ Ͱ l

    e r n a ί Ϛ ϯ υ Λ ಈ ͔ ͢ ৔ ߹ ͷ ஫ ҙ ఺ • —scopeΛ͚ͭͳ͍ͱશPJʹରͯ͠npm-script͕࣮ߦ͞ΕΔ • PJ਺ͱδϣϒ࣮ߦ͕࣌ؒൺྫ͢Δ • ௕࣌ؒίϯςφΛઐ༗͞ΕΔՄೳੑ͕͕͋Δ • ϒϥϯν΍filterΛར༻ͯ͠ɺඞཁͳPJͷςετɾϏϧυ͚ͩʹ • Lerna + sls webpack͸͕͔͔࣌ؒ͘͢͝ΔͷͰಛʹ஫ҙ #circlecijp
  19. C i rc l e C I ʹ ݶ Β

    ͳ ͍ T i p s • Lerna + sls webpack͸͕͔͔࣌ؒ͘͢͝ΔʢݪҼෆ໌ʣ • ϝϞϦΛ࢖͍੾Δͱ͖͕͋ΔͷͰɺ--max-old-space-sizeΛదٓ࢖͏ • node --max-old-space-size=2048 $(which sls) deploy • package.jsonʹ”private”: trueΛ͚ͭͯͳ͍PJ͸npm publishՄೳ #circlecijp
  20. C o n c l u s i o n

    • CircleCI͸ϓϥΠϕʔτܥPJͷCI / CDʹศར • δϣϒ਺Ͱ՝ۚ͞ΕΔͷͰɺOSS͸TravisͳͲΛ࢖͏ͱΑ͍͔΋ • LernaΛ࢖͏͜ͱͰɺෳ਺ͷPJͱڞ༗ϥΠϒϥϦΛ·ͱΊͯ؅ཧ • CircleCIͷWorkflowΛ࢖͑͹ϞϊϨϙͰ΋CI / CDͰ͖Δ • ୭͔΋ͬͱ͍͍ํ๏͋ΔͳΒڭ͑ͯʢ Blog / Meetup / etc…ʣ #circlecijp