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
GAEアプリをCI/CDして結果をSlackに通知した話 / GAE App CICD Sla...
Search
qushot
January 31, 2019
Programming
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GAEアプリをCI/CDして結果をSlackに通知した話 / GAE App CICD Slack notification
qushot
January 31, 2019
Transcript
35 slides
GAEアプリをCI/CDして 結果をSlackに通知した話 2019/1/31 Go(Un)Conference LT大会 5kg
Google Cloud Platform プレミアパートナー 自己紹介 名前: 本 雄太朗 (@qushot) 所属:
クラウドエース株式会社 業務: サーバサイド(GAE, GKE)をGoで開発 Go歴: 2年弱
None
前置き
Google App Engine GoogleのインフラでWebアプリを実行できるPaaS。 開発者はアプリのコードだけ書いてればいいので楽。 Go 1.11対応(beta)。
Cloud Build 基本的にはコンテナイメージをビルドするためのサービス。 GitHubなどのリポジトリにPushすると 設定ファイルに従ってビルド・テスト・デプロイなどの処理ができる。
Cloud Pub/Sub ストリーム分析とイベント駆動型コンピューティング向けの基盤 メッセージキューみたいなサービス
Google Cloud Functions イベント駆動型のサーバーレスコンピューティングプラットフォーム。 HTTPリクエストやGCP/Firebaseでのイベントをトリガーに関数を実行する。 Go 1.11対応(beta)
話すこと 1. GAE/GoアプリをCloud BuildでCI/CDする! 2. CI/CDの結果をGCF/GoでSlack通知!
GAE/GoアプリをCloud BuildでCI/CD
やること Cloud Buildのトリガーを設定 ビルド設定ファイルを作成 Developer Cloud Build GitHub App Engine
Build Trigger Build & Deploy Push
やること Cloud Buildのトリガーを設定 ビルド設定ファイルを作成 Developer Cloud Build GitHub App Engine
Build Trigger Build & Deploy Push
Cloud Buildのトリガーを設定 ソースを選択(GitHubやBitbucket) リポジトリを選択 トリガーとするブランチや ビルド設定ファイルの選択 Cloud Buildでの環境変数を設定する
やること Cloud Buildのトリガーを設定 ビルド設定ファイルを作成 Developer Cloud Build GitHub App Engine
Build Trigger Build & Deploy Push
ビルド設定ファイルを作成 cloudbuild.yaml - フロントのコードをビルドするステップ - go get するステップ - テストを走らせるステップ
- デプロイするステップ steps: # デプロイするステップの例 - name: "gcr.io/cloud-builders/gcloud" args: [ "app", "deploy", "--project=$PROJECT_ID", "--no-promote", "./app/app.yaml", ]
CI/CDの結果をGCF/GoでSlack通知
やること Slackbot準備 (詳細は省略) 結果を受け取って投げる関数を実装 Cloud Build Cloud Functions Cloud Pub/Sub
Slack Push Subscription Notification Event
やること Slackbot準備 (詳細は省略) 結果を受け取って投げる関数を実装 この辺は特になにもしなくてよい→ Cloud Build Cloud Functions Cloud
Pub/Sub Slack Push Subscription Notification Event
やること Slackbot準備 (詳細は省略) 結果を受け取って投げる関数を実装 Cloud Build Cloud Functions Cloud Pub/Sub
Slack Push Subscription Notification Event
ファイル構成 .bot ├── cmd │ └── main.go ←ローカル開発時に使う ├── shared
│ └── shared.go ←共通ロジックなどを置いておく ├── build_report.go ←デプロイする関数を置いておく ├── .env.yaml ←環境変数を書いておく ├── build_report_deploy.sh ←デプロイ用スクリプト ├── go.mod └── go.sum
ファイル構成 .bot ├── cmd │ └── main.go ←ローカル開発時に使う ├── shared
│ └── shared.go ←共通ロジックなどを置いておく ├── build_report.go ←デプロイする関数を置いておく ├── .env.yaml ←環境変数を書いておく ├── build_report_deploy.sh ←デプロイ用スクリプト ├── go.mod └── go.sum
関数を実装する build_report.go // PubSubからのメッセージ受ける構造体 type PubSubMessage struct { Data []byte
`json:"data"` } // ↑のbyte配列をUnmarshalするための構造体 // 関数はPublicに func BuildReport(ctx context.Context, m PubSubMessage) error { // 処理 return nil } type build struct { Status string `json:"status"` LogURL string `json:"logUrl"` }
関数を実装する build_report.go // PubSubからのメッセージ受ける構造体 type PubSubMessage struct { Data []byte
`json:"data"` } // ↑のbyte配列をUnmarshalするための構造体 // 関数はPublicに func BuildReport(ctx context.Context, m PubSubMessage) error { // 処理 return nil } type build struct { Status string `json:"status"` LogURL string `json:"logUrl"` } json.Unmarshalして、 buildのStatusが “SUCCESS” の場合は成功 Statusが “FAILURE”, “INTERNAL_ERROR”, “TIMEOUT” の場合は失敗 の通知を飛ばす処理を書く ※Statusには上記以外のものもあるので、気をつけないと通知まみれになる
別のトリガーを利用したい場合 公式ドキュメントに各トリガー向けのサンプルがあります https://cloud.google.com/functions/docs/calling/
環境変数を定義する .env.yaml OAUTH_ACCESS_TOKEN: xoxp-0123456789-foo-bar VERIFICATION_TOKEN: FooBarHogeFufu CHANNEL_ID: ABCDEFG Goからos.Getenvで読み込める
デプロイする build_report_deploy.sh #!/bin/bash gcloud functions deploy build_report \ --region asia-northeast1
\ --entry-point BuildReport \ --stage-bucket project-id_cloudbuild \ --runtime go111 \ --env-vars-file .env.yaml \ --trigger-topic cloud-builds Functionsでの関数名 デプロイ対象のGoの関数 環境変数のファイル
GitHubにPushすると... はい嬉しい
全体的なアーキテクチャ Developer Cloud Build GitHub App Engine Trigger Build &
Deploy Push Pub/Sub Functions Slack Event Push Subscription Notification
微妙なところ GAEではデプロイ時に内部でCloud Buildを利用しているため、 Functionsのトリガーが反応してしまう つまり、自分で定義したCloud Build TriggerとGAEのCloud Buildを 区別する方法が無さそうなので、Slackに通知が2つ飛んできてしまう とはいえ成功通知が2つ来てればいいだけ
(スッタタタッ! スッタタタッ!ってなってちょっとうざい)
せっかくなら 通知だけじゃ便利とは言えないよね! Slack Interactive Message [1] とか使って botからバージョンの切り替えとかやりたいよね! というわけでApp Engine
Admin APIを叩こう! [1] Slack Interactive Message の例
と思いきや Go向けのクライアントライブラリが無い・・・[1] 自動生成されたライブラリ(やたら項目が多くてダルい)とか REST APIは提供されているので叩け無いことはないケド・・・ [1] https://cloud.google.com/appengine/docs/admin-api/client-libraries
Googleさん、お願いします^^
まとめ ほとんど手間をかけずにCI/CDを実現できた! デプロイの結果を通知してくれて便利になった! GAEのバージョン切り替えも(だるそうだけど)GCFでいけそう いずれ実装してどこかで話ができればと思います Slackbotの設定は情報が錯綜しており一番つらかったかも Goのお話ほとんどなくてごめんなさい Goのお話ほとんどなくて本当にごめんなさい...m(_ _)m
現在クラウドエースでは 絶賛社員募集中です! GCPやGoでの開発・運用に 興味があれば @qushot まで!
ご清聴ありがとうございました!
More Decks by qushot
See All by qushot
よく使っているライブラリ&ツール紹介
qushot
0
100
Other Decks in Programming
See All in Programming
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
270
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
Skills Are the New npm [AAIF Bengaluru, Nov 2026]
shivamsaraswat
0
130
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
6.3k
Lean で手続き的プログラム の証明が書けるようになった
inoueasei
8
3.3k
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
690
小さなアプリを作って公開するまで
onozaty
0
250
JavaScriptはシングルバイナリの夢を見るか / Does JavaScript Dream of a Single Binary?
ssssota
0
390
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
170
将来の標準フォーマッター?ktfmtを深堀る
t45k
1
250
AppFunctionsの内部実装を紐解く
hiroaki404
1
120
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
540
A Modern Web Designer's Workflow
chriscoyier
699
190k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
The SEO Collaboration Effect
kristinabergwall1
1
630
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
860
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
470
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
How to Think Like a Performance Engineer
csswizardry
28
3k