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

KompalWeather: Serverless Sauna Service with Cloud Run

KompalWeather: Serverless Sauna Service with Cloud Run

Serverless Meetup Japan Virtual #7の登壇資料です。 #serverlessjp
https://serverless.connpass.com/event/188880/

Toshinori Sugita

September 23, 2020
Tweet

More Decks by Toshinori Sugita

Other Decks in Technology

Transcript

  1. KompalWeather: Serverless Sauna Service with Cloud Run

    @toshi0607


    View Slide

  2. 自己紹介

    ● 杉田 寿憲

    ○ Toshinori Sugita / toshi0607

    ○ Software [email protected]メルカリ

    ○ マイクロサービスを開発するプラットフォームの開発・運用

    ○ サウナ・スパ健康アドバイザー

    ● 本

    ○ 『Google Cloud Platformで学ぶTerraform』←NEW!

    ○ Knative本 × 3

    ○ 『GoとSAMで学ぶAWS Lambda』

    ○ 『Extensive Xamarin(共著)』

    ● 趣味

    ○ 猫、サウナ、サーバーレス


    View Slide

  3. View Slide

  4. ※https://kom-pal.com/

    View Slide

  5. ※https://project.gotanda-valley.com/engineer-sento1/

    View Slide

  6. ※https://project.gotanda-valley.com/engineer-sento1/

    View Slide

  7. ※https://twitter.com/kompal_osaki/status/1266980363718410241

    View Slide

  8. ※https://www.google.co.jp/maps/place/%E9%87%91%E6%98%A5%E6%B9%AF/@35.6172952,139.7193735,17z/data=!
    3m1!4b1!4m5!3m4!1s0x60188aedf92e7e07:0xc9b827cec1b7ca9e!8m2!3d35.6172952!4d139.7215622

    View Slide

  9. ※https://kom-pal.com/

    View Slide

  10. ※https://kom-pal.com/

    View Slide

  11. 高次元のととのいを得るために必要な機能

    ● 混雑具合変更の通知

    ● 1日のうちで空きがちな時間帯

    ● 1週間のうちで空きがちな曜日


    View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. 常連「営業時間終了時に空いてるステータスでないと営
    業終了ツイートできひんな…」


    銭湯店主「営業中か営業時間外かも返しますね!」


    View Slide

  17. 設計時の気持ち

    ● 実装はしたいけど一刻も早く動かしたい

    ● 運用に手間はかけられないはず

    ● UIやグラフ化をシュッと実装できる気はしない


    View Slide

  18. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー


    View Slide

  19. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー

    1 watch
    2 fetch status
    3 save status
    4 post status change

    View Slide

  20. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー

    1 visualize
    2 download graph
    3 save graph

    View Slide

  21. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー

    1 trend
    2 download graph
    3 post graph

    View Slide

  22. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー


    View Slide

  23. Cloud Run + Cloud Scheduler

    ● サーバーをCloud Runで HTTPサーバーをホスト

    ○ watch: 混雑状況取得・変化通知

    ○ visualize: 混雑トレンドグラフ取得

    ○ trend: 混雑トレンドグラフ投稿

    ● Cloud Schedulerで用途別のエンドポイントにリクエスト

    ○ 営業時間15分毎にwatch

    ○ 営業日23:30にvisualize

    ○ 営業日15:00にtrend


    View Slide

  24. Cloud Schedulerありがとう

    ● Unix cron形式でのスケジューリング、バックオフ付リトライ、リトライ
    回数、タイムアウトなどを設定可能

    ● Schedulerのサービスアカウントにroles/run.invokerを付与し、リクエ
    ストにOIDCトークンとして付与

    ○ Cloud Runの認証必須状態を維持

    ● 0.1$ job/月

    ○ 無料枠 3 jobs/月

    ※https://cloud.google.com/scheduler

    View Slide

  25. Cloud Run + Cloud Scheduler

    ※https://github.com/toshi0607/KompalWeather/blob/master/terraform/development/google_cloud_scheduler_job.tf

    View Slide

  26. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー

    1 watch
    2 fetch status
    3 save status
    4 post status change

    View Slide

  27. Google Sheets

    ● メールアドレスだけでデータ共有

    ○ CSVエクスポート機能実装不要

    ● 簡易な分析・グラフ化が楽

    ● GCPのサービスアカウントに対しても編集権限付与可能

    ○ Cloud RunからRead/Write


    View Slide

  28. Cloud Run
    Cloud Run
    App
    Engine
    Monitoring
    Cloud
    Storage
    Logging
    Cloud Scheduler Slack
    Twitter
    Secret Manager
    Google
    Sheets
    Kom-pal
    API
    Firebase
    Invoker Compute Storage UI
    KompalWeatherのアーキテクチャー


    View Slide

  29. Cloud Monitoring

    ● 監視ではなく、カスタムメトリクスを混雑状況の可視化に利用

    ● 画像データもダウンロード可能

    ○ APIはない


    View Slide

  30. Cloud Monitoring


    View Slide

  31. Managed UI?

    ● UI作るの得意なら何か自分で実装したかもしれない

    ● データを準備すれば、「日常」「手元」に届けてくれるサービスもたくさ
    んある


    View Slide

  32. CI/CD

    ● masterブランチへのマージをトリガーにコンテナイメージビルド、
    Google Container Registryへのプッシュ、Cloud Runへのデプロイを
    実行

    ● Cloud Runサービス設定時にリポジトリ、Dockerfileへのパス、トリ
    ガーを指定するだけで設定可能

    ○ buildpacksを使ったDockerfileなしのデプロイも対応

    ● CI/CD用の強めの権限を持たせたサービスアカウントファイルのダ
    ウンロード不要

    ※https://cloud.google.com/run/docs/continuous-deployment-with-cloud-build buildpacks日本語ページ未反映

    View Slide

  33. Cloud Runとエコシステム

    ● プロダクトとして

    ○ ブルーグリーンデプロイ、トラフィックスプリット、カスタムドメイ
    ン、gPRC(unary)

    ● アーキテクチャの一部として

    ○ Scheduler、Events、Workflows、Cloud SQL, etc

    ○ Serverless NEG、VPC接続(Shared含む)

    ● 開発のライフサイクル

    ○ ローカル開発(Cloud Code for VS Code、IntelliJ)

    ○ CI/CD

    ※https://cloud.google.com/run/docs/release-notes

    View Slide

  34. 案内

    Cloud Runをもっと知りたい!

    ● 入門ハンズオン

    ○ https://cloud.google.com/run/docs/quickstarts

    ● ドキュメント

    ○ https://cloud.google.com/run

    ● もっと!

    ○ https://github.com/steren/awesome-cloudrun

    ○ https://github.com/ahmetb/cloud-run-faq


    View Slide

  35. 案内

    金春湯でととのいたい!

    ● サイト

    ○ https://kom-pal.com/

    ● Twitter

    ○ https://twitter.com/kompal_osaki

    ● 評判は?

    ○ https://sauna-ikitai.com/saunas/2027


    View Slide

  36. 案内

    KompalWeatherの実装を知りたい!

    ● GitHub

    ○ https://github.com/toshi0607/KompalWeather

    ● Twitter

    ○ https://twitter.com/KompalWeather

    ● 質問・要望があればどうぞ!

    ○ https://twitter.com/toshi0607


    View Slide

  37. ご清聴ありがとうございました!

    KompalWeather: Serverless Sauna Service with Cloud Run


    View Slide