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
More Decks by qushot
See All by qushot
よく使っているライブラリ&ツール紹介
qushot
0
100
Other Decks in Programming
See All in Programming
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
530
はじめてのPLATEAU
nokonoko1203
1
570
GraphQL の onError と Nullability のこれから
quramy
0
210
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
110
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
150
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
160
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
220
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
280
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
1.6k
Next.js: The final boss of Web Performance
guaca
0
380
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.7k
Modernizing iOS Apps
seyfoyun
0
150
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Un-Boring Meetings
codingconduct
0
490
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.8k
It's Worth the Effort
3n
188
29k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
680
Build your cross-platform service in a week with App Engine
jlugia
234
19k
How to Talk to Developers About Accessibility
jct
2
610
Transcript
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 まで!
ご清聴ありがとうございました!