Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Okayama-2018winter-gae-public.pdf
Search
hayashiki
December 22, 2018
780
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Okayama-2018winter-gae-public.pdf
hayashiki
December 22, 2018
More Decks by hayashiki
See All by hayashiki
FirestoreのN:N関連の設計の話
hayashiki
0
610
Deploying a Containerized Application On GKE
hayashiki
0
110
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
50
15k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
360
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
It's Worth the Effort
3n
188
29k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
First, design no harm
axbom
PRO
2
1.3k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
240
Statistics for Hackers
jakevdp
799
230k
Skip the Path - Find Your Career Trail
mkilby
1
230
Designing Powerful Visuals for Engaging Learning
tmiket
1
570
Transcript
Cookbook 'App Engine' 合同勉強会in大都会岡山 2018/12/22 Masayuki Hayashida ( @hayashiki )
自己紹介 key value 名前 林田 賢行 Name Hayashida Masayuki Github
@hayashiki 所属 BULB株式会社 VR/機械学習/IoT コミュニティ GCPUGオーガナイザー その他 フルリモートワーカー
話すこと AppEngine(GAE) Overview 構成パターン API Endpoint Webhook SPA With Firebase
AppEngineとは GoogleCloud(GCP)の提供するPaaSサービス ・Web アプリケーションに設定ファイルを書くだけですぐにデプロイ可能 ・サーバメンテナンス不要 ・オートスケール、圧倒的スピンアップの速さ ・独自ドメインが割り振られる
で、大事なポイントが
無料で運用できる枠がわりとある 個人でのサービス開発 スタートアップでの新規開発 検証用プロタイプ 社内の業務ハックツールなどなど
AppEngine ランタイム環境 対応言語 [Java, Python, PHP, Go, Nodejs] 例としてGoであれば、GAE/Goといった表記がされることが多い 正確にいうと、FlexibleEnvironment
は自由度の高いGAE 環境がある 例えばRuby といった言語サポートも増えるのだが、無料枠がないこともあり、 今回の話の対象外としている
Hello World app.yaml runtime: go111 app.go func main() { http.HandleFunc("/",
indexHandler) port := os.Getenv("PORT") log.Printf("Listening on port %s", port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), } func indexHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) return } fmt.Fprint(w, "Hello, World!") }
デプロイ $ gcloud app deploy
その他機能 Name Description Datastore NoSQLデータベース TaskQueue(Cloud Tasks) 非同期処理ができるタスクキュー Cron(Cloud Sheduler)
スケジューラ GCPのAPI GCP全般 Logging,Debug機能も実はすごいんだが割愛・・・
Demo
Demo解説
構成パターン
APIエンドポイント パターン API開発効率が非常にいい バージョン, サービス単位でエンドポイントを付与してデプロイが可能 カジュアルにエンドポイントがたてられる
エンドポイント命名 https://[VERSION]‑dot‑[SERVICE]‑dot‑[PROJECT].appspot.com
エンドポイント例 $ gcloud app deploy --version feature $ gcloud app
deploy --version master target service: [base] target version: [feature] target url: [https://base-dot-goa-api01.appspot.com] target service: [base] target version: [master] target url: [https://base-dot-goa-api01.appspot.com]
なにがいいの? 個人,開発機,モバイル向け,Mock用 ロールバック トラフィック分割(A/B Test)
API開発はgoa使おう goa はGo で実装されたDSL API 雛形( コード) やSwagger( ドキュメント) を生成してくれる
すぐにAppEngine にのせてデプロイすることができる。
まとめ サーバ構築、運用しなくていいとかもう色々とびこえている感あり コアなビジネスロジック書くところに集中できる環境
Webhook / Bot パターン Webhookを介してWebサービス同士をつなぐ イベント駆動でなく、定期処理も行うBot
Lineだとこんな設定画面
Slackだとこんな画面
Githubだとこんな画面
GithubでのBot・Webhook例 ‑ PRの緊急重要ラベルを定期監視してSlackにPostするBotマン ‑ GithubとSlackのコメントのメンションをSyncさせる
まとめ スケジューラ機能をつかった定期Bot としても実装しやすい FaaS でよく使われる使い方である アプリケーション単位でサービス管理したい場合に有効
SPA パターン HTML,CSS,JavaScriptといったStaticファイルも一緒にデプロイ 可能だがリッチなUI/UXがほしい
Vuejsが手っ取り早い index.htmlにVuejsのCDNを組み込めば簡単にSPAが実現可能
index.htmlにCDNをくみこむ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-s
<title>Okayama!</title> <script src="http://unpkg.com/vue/dist/vue.js"></script <script src="https://unpkg.com/axios/dist/axios.min.js" </head>
データバインディング var app = new Vue({ el: '#app', data: {
tasks: [], newTask: "", }, created: function() { axios.get('/tasks') .then((response) => { this.tasks = response.data.items || [] })}, methods: { addTask: function(task) { let params = new URLSearchParams() params.append('body', this.newTask) axios.post('/tasks', params) .then((response) => { ...
React, AngularでもSPA使いたい Webpack build ビルド先をAppEngineのビルド先に出力
まとめ BackendとFrontend、両方をデプロイすることが可能
With Firebase パターン
FirebaseAuthだけお借りするパターン AppEngine のアプリをFirebase で認証する Firebase が使用するユーザーID を借りて それ以外の永続化データはDatastore で管理する
FirebaseのFirestore FirebaseのDataBase Firestoreを利用する
AppEngine + Firebase お互いに得意な領域で役割をわける Frontend側はUIを作り込むトコロ バッチ処理、複雑なビジネスロジックを含む処理 例:1日1回バッチで数万件のアイテムを一括で情報更新、 XXば場合なレポートを作成し、全文検索Index更新し、 さらにビジネスロジックが云々・・・
・フロントエンドで、こみいった非同期処理、並行処理など辛み ならばAppEnging/GOでGoroutinesをつかう
まとめ FirebaseとAppEngineをハイブリッドに使おう
DDD!!!(どんどんデプロイ) 岡山AppEngineハンズオン https://gcpug‑okayama.connpass.com 岡山Go勉強会 https://okayamago.connpass.com/ https://okayamago.connpass.com/event/112138/
ref Next Currency‑GAEGo https://speakerdeck.com/sonatard/next‑currency‑gaego GolangのgoaでAPIをデザインしよう https://tikasan.hatenablog.com/entry/2017/05/08/190000 App Engine アプリのユーザーを Firebase
で認証する https://cloudplatform‑jp.googleblog.com/2016/10/app‑engine‑ firebase.html