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

カンファレンス映えするデモアプリをPythonとCloud Runでいい感じに作った話 / Data Visualization for Dash and Cloud Run

カンファレンス映えするデモアプリをPythonとCloud Runでいい感じに作った話 / Data Visualization for Dash and Cloud Run

PyLadies Tokyo 8 周年記念パーティーLT

Shinichi Nakagawa

November 19, 2022
Tweet

More Decks by Shinichi Nakagawa

Other Decks in Programming

Transcript

  1. ΧϯϑΝϨϯεө͑͢Δ σϞΞϓϦΛ΄΅Python͚ͩͰ ࡞ͬͨ࿩ with Cloud Run⚾ ㅟ ㅟ ㅟ ㅟ

    ㅟ ㅟ ㅟ ㅟ ㅟ ㅟ PyConJP 2022 Ͱ΍Εͳ͔ͬͨ࿩Λ͜͜Ͱڙཆ͠·͢ͷר Shinichi [email protected] 2022/11/19 PyLadies Tokyo 8प೥ه೦LT
  2. Who am ɹ? ʢ͓લ୭Α?ʣ • Shinichi [email protected] • େख֎ࢿܥITίϯαϧاۀϚωʔδϟʔ •

    ೔ຊͷPythonք۾Ͱʮ⽁ͷਓʯͱݺ͹Ε͍ͯΔ • PyConJPొஃ8ճʢ2014-2018, 2020-2022ʣ 
 ʢ2019೥͸ຐ͕ࠩͨ͠ҰൠࢀՃऀʣ • PyLadies Tokyo ̋प೥΋LTࢀՃ8ճ໨ 
 ʢॳճ͔Βϑϧग़৔ܧଓதʣ #Python #Serverless #GoogleCloud #Baseball 
 #DataScience #SABRmetrics
  3. ຊ೔ͷ͓࿩ • DashΛ࢖ͬͯʮ΄΅Python͚ͩʯͰWebΞϓϦέʔγϣϯΛ࡞Δ • DashΞϓϦέʔγϣϯΛGoogle CloudͰ͍͍ײ͡ʹϗετ͢Δ

  4. Ͳ͏͍͏Ϟϊ͔ͻͱ·͓ͣݟͤ͠·͢.

  5. ΦΦλχαϯʂʂΩϡϯͰ͢ὑ ౤खͰೋܻউͪͳ͕Β΋ଧͬͯ34ຊྥଧ…Τά͍.

  6. ΦΦλχαϯʂʂΩϡϯͰ͢ὑ ౤खͰೋܻউͪͳ͕Β΋ଧͬͯ34ຊྥଧ…Τά͍.

  7. σϞΞϓϦέʔγϣϯߏ੒ • ΞϓϦຊମ͸DashͰ࣮૷ͨ͠ϑϩϯτΤϯυ, Cloud RunͰϗετ • API GatewayΛ௨ͯ͠όοΫΤϯυʹΞΫηε • όοΫΤϯυ͸Cloud

    Functionsʹ͋Δʢ͜Ε΋Pythonʣ, Databaseͷத਎ΛJSONͰฦ͢RESTful API
  8. Dash • άϥϑඳըɾՄࢹԽϥΠϒϥϦʮPlotlyʯΛ 
 ͍͍ײ͡ͳWebΞϓϦͱͯ͠࡞ΔͨΊͷFW • αʔόʔαΠυΞϓϦͷϕʔε͸Flask, ϑϩϯτ͸Reactͱ͍͏ 
 ʢྲྀߦΓͬΆͯ͘ʣ͍͍ײ͡ͳߏ੒

    • ૉͷJavaScriptɾHTMLΛॻ͔ͳͯ͘΋, Python͚ͩͰΠέΔॴ͕ 
 ؾʹೖΓ, σϞΞϓϦͷϕʔεͱͯ͠࠾༻
  9. ίʔυʢงғؾʣ • ࠷ॳظͷίʔυͷεΫγϣͰ͢ • HTMLʹ໛ͨ͠ίϯϙʔωϯτΛ 
 ΰϦͬͱॻ͘ • ΠϕϯτۦಈͰͷॻ͖׵͑͸ 


    CallbackͳσίϨʔλʔͰ࣮૷ • ͳΜͱͳ͘Ͱ͕͢ReactͬΆ͍ 
 งғؾʹʢͳ͓callback஍ࠈʣ
  10. Cloud Run΁ͷϗεςΟϯά • GitHub Repositoryʹpushͨ͠ΒGitHub Actions͕ൃՐ, ςετ -> Docker Build

    -> Cloud RunσϓϩΠ • ςετ͸pytest, flake8, mypyΛGitHub Actions্Ͱ࣮ࢪʢunit, integration·Ͱ୲อ͢ΔΠϝʔδʣ • Docker build͸Cloud Runͷඪ४తͳ΍Γํʹै͏. • Cloud Build্ͰϏϧυ • Artifact Registryʹpush • Cloud Run΁ͷσϓϩΠ͸Github ActionsͷެࣜΛ࢖࣮ͬͯࢪ. • ͪͳΈʹଞͷΫϥ΢υαʔϏεͰ΋༨༟Ͱ΍ΕΔͱࢥ͍·͢ʢAWS, Azure, etc…ʣ
  11. Github Actionsͷఆٛ test->build->deploy • ݱࡏӡ༻͍ͯ͠ΔΞϓϦͷ 
 GitHub Actionsఆٛ • ࣮ݱ͢Δͷʹ100ߦ͍ۙ

    
 yamlఆ͕ٛඞཁʹ…orz • ͜͜·Ͱ΍ΔΜͩͬͨΒ 
 build/deploy͸terraformͷํ͕ 
 Ή͠Ζָ͔΋͠Εͳ͍આ
  12. ·ͱΊ • DashΛ࢖͑͹΄΅Python͚ͩͰ 
 σʔλΛݟͤΔΞϓϦΛ࡞Ε·͢. • ίϯςφԽͯ͠Cloud RunͰ 
 ϗετ͢Δͷָ͕Ͱྑ͍Ͱ͠ΐ͏.

    
 ʢଞͷΫϥ΢υͰ΋΋ͪΖΜOKʣ • ΦΦλχαϯ, ΩϡϯͰ͢ὑ
  13. ࣌ؒͷ౎߹্୺ંͬͨ࿩ • API GatewayͱόοΫΤϯυͷ࿩͸୺ંΓ·ͨ͠🙏 • ϦΫΤετ͋Ε͹࣭ٙԠ౴ɾϒϩάɾผ৔Ͱ࿩͢ͳͲ͠·͢ • ͜͏͍͏ઃܭʹԿނ͔ͨ͠ʁ΋ؚΊͯ·ͨ΍Γ·͢👍

  14. PyLadies Tokyo 8प೥͓ΊͰͱ͏͍͟͝·͢🎉 ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠