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 Nakagawa@shinyorke 2022/11/19 PyLadies Tokyo 8प೥ه೦LT

    View full-size slide

  2. Who am ɹ?


    ʢ͓લ୭Α?ʣ
    • Shinichi Nakagawa@shinyorke


    • େख֎ࢿܥITίϯαϧاۀϚωʔδϟʔ


    • ೔ຊͷPythonք۾Ͱʮ⽁ͷਓʯͱݺ͹Ε͍ͯΔ


    • PyConJPొஃ8ճʢ2014-2018, 2020-2022ʣ

    ʢ2019೥͸ຐ͕ࠩͨ͠ҰൠࢀՃऀʣ


    • PyLadies Tokyo ̋प೥΋LTࢀՃ8ճ໨

    ʢॳճ͔Βϑϧग़৔ܧଓதʣ


    #Python #Serverless #GoogleCloud #Baseball

    #DataScience #SABRmetrics

    View full-size slide

  3. ຊ೔ͷ͓࿩
    • DashΛ࢖ͬͯʮ΄΅Python͚ͩʯͰWebΞϓϦέʔγϣϯΛ࡞Δ


    • DashΞϓϦέʔγϣϯΛGoogle CloudͰ͍͍ײ͡ʹϗετ͢Δ

    View full-size slide

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

    View full-size slide

  5. ΦΦλχαϯʂʂΩϡϯͰ͢ὑ


    ౤खͰೋܻউͪͳ͕Β΋ଧͬͯ34ຊྥଧ…Τά͍.

    View full-size slide

  6. ΦΦλχαϯʂʂΩϡϯͰ͢ὑ


    ౤खͰೋܻউͪͳ͕Β΋ଧͬͯ34ຊྥଧ…Τά͍.

    View full-size slide

  7. σϞΞϓϦέʔγϣϯߏ੒
    • ΞϓϦຊମ͸DashͰ࣮૷ͨ͠ϑϩϯτΤϯυ, Cloud RunͰϗετ
    • API GatewayΛ௨ͯ͠όοΫΤϯυʹΞΫηε
    • όοΫΤϯυ͸Cloud Functionsʹ͋Δʢ͜Ε΋Pythonʣ, Databaseͷத਎ΛJSONͰฦ͢RESTful API

    View full-size slide

  8. Dash
    • άϥϑඳըɾՄࢹԽϥΠϒϥϦʮPlotlyʯΛ

    ͍͍ײ͡ͳWebΞϓϦͱͯ͠࡞ΔͨΊͷFW


    • αʔόʔαΠυΞϓϦͷϕʔε͸Flask, ϑϩϯτ͸Reactͱ͍͏

    ʢྲྀߦΓͬΆͯ͘ʣ͍͍ײ͡ͳߏ੒


    • ૉͷJavaScriptɾHTMLΛॻ͔ͳͯ͘΋, Python͚ͩͰΠέΔॴ͕

    ؾʹೖΓ, σϞΞϓϦͷϕʔεͱͯ͠࠾༻

    View full-size slide

  9. ίʔυʢงғؾʣ
    • ࠷ॳظͷίʔυͷεΫγϣͰ͢


    • HTMLʹ໛ͨ͠ίϯϙʔωϯτΛ

    ΰϦͬͱॻ͘


    • ΠϕϯτۦಈͰͷॻ͖׵͑͸

    CallbackͳσίϨʔλʔͰ࣮૷


    • ͳΜͱͳ͘Ͱ͕͢ReactͬΆ͍

    งғؾʹʢͳ͓callback஍ࠈʣ

    View full-size slide

  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…ʣ

    View full-size slide

  11. Github Actionsͷఆٛ


    test->build->deploy
    • ݱࡏӡ༻͍ͯ͠ΔΞϓϦͷ

    GitHub Actionsఆٛ


    • ࣮ݱ͢Δͷʹ100ߦ͍ۙ

    yamlఆ͕ٛඞཁʹ…orz


    • ͜͜·Ͱ΍ΔΜͩͬͨΒ

    build/deploy͸terraformͷํ͕

    Ή͠Ζָ͔΋͠Εͳ͍આ

    View full-size slide

  12. ·ͱΊ
    • DashΛ࢖͑͹΄΅Python͚ͩͰ

    σʔλΛݟͤΔΞϓϦΛ࡞Ε·͢.


    • ίϯςφԽͯ͠Cloud RunͰ

    ϗετ͢Δͷָ͕Ͱྑ͍Ͱ͠ΐ͏.

    ʢଞͷΫϥ΢υͰ΋΋ͪΖΜOKʣ


    • ΦΦλχαϯ, ΩϡϯͰ͢ὑ

    View full-size slide

  13. ࣌ؒͷ౎߹্୺ંͬͨ࿩
    • API GatewayͱόοΫΤϯυͷ࿩͸୺ંΓ·ͨ͠🙏


    • ϦΫΤετ͋Ε͹࣭ٙԠ౴ɾϒϩάɾผ৔Ͱ࿩͢ͳͲ͠·͢


    • ͜͏͍͏ઃܭʹԿނ͔ͨ͠ʁ΋ؚΊͯ·ͨ΍Γ·͢👍

    View full-size slide

  14. PyLadies Tokyo 8प೥͓ΊͰͱ͏͍͟͝·͢🎉


    ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide