Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
A push notification server written in Go Gorush 1 Bo-Yi Wu Mopcon @ 2017.10.28
Slide 2
Slide 2 text
●Why I create the Gorush Project? ●Detail implementation in Golang ●Testing and deploy Go project. ●Run Gorush in Kubernetes. 2 Outline
Slide 3
Slide 3 text
● Mediatek Engineer ● DevOps ● Golang, PHP, Node.js .. ● Some open source ● Gitea ● Gin ● Drone ● appleboy @GitHub ● appleboy @twitter ● appleboy @slideshare ● appleboy46 @facebook About Me 3
Slide 4
Slide 4 text
● drone/drone ● go-gitea/gitea ● gin-gonic/gin ● appleboy/gorush Go Open Source in GitHub 4
Slide 5
Slide 5 text
● drone/drone ● go-gitea/gitea ● gin-gonic/gin ● appleboy/gorush Go Open Source in GitHub 5
Slide 6
Slide 6 text
https://mcs.mediatek.com/ 6
Slide 7
Slide 7 text
Mediatek Cloud Sandbox Trigger Push Email hook MQTT TCP HTTP Mediatek Cloud Sandbox 7
Slide 8
Slide 8 text
Mediatek Cloud Sandbox Trigger Push Email hook MQTT TCP HTTP Mediatek Cloud Sandbox 8 Forcus on Push notification
Slide 9
Slide 9 text
https://github.com/appleboy/gorush Gorush 9
Slide 10
Slide 10 text
A general push notification server for smartphone application Gorush 10
Slide 11
Slide 11 text
●Written in Go ●Push requests to APNs and FCM ●Simple HTTP APIs (JSON) ●RPC Protocol (gRPC) Gorush 11
Slide 12
Slide 12 text
Overview Client FCM APN s Gorush POST /push JSON Body HTTPS APNs Protocol 12
Slide 13
Slide 13 text
●System Requirement ●Good Performance ●High Concurrency ●Simple net/http Package ●Easy to Learn Why I Choose Go 13
Slide 14
Slide 14 text
https://github.com/golang/go/wiki/FromXToGo Why we switch From XX to Go 14
Slide 15
Slide 15 text
https://github.com/golangtw/jobs Who use Go in Taiwan 15
Slide 16
Slide 16 text
16 Push System Architecture
Slide 17
Slide 17 text
Before Seven years ago FCM APNs API Server API Server API Server PUSH 17
Slide 18
Slide 18 text
Before Two Years ago FCM APNs Worker Worker Worker PUSH Queue API API API de-queue Asynchronous Notification AWS en-queue 18
Slide 19
Slide 19 text
Nginx Traefik Now… FCM APNs Gorush Gorush Gorush PUSH API API API Http Post /push Gorush = Queue + Worker 19
Slide 20
Slide 20 text
How to implement simple notification service Gorush Architecture 20
Slide 21
Slide 21 text
How to send notification Client FCM APN s Gorush POST /push JSON Body HTTPS APNs Protocol 21
Slide 22
Slide 22 text
●Http Server ●gRPC Server ●Push API ●Worker 22 Gorush Component
Slide 23
Slide 23 text
net/http + Gin Route+ Facebook Grace 23
Slide 24
Slide 24 text
Push API using Gin Framework 24
Slide 25
Slide 25 text
Initial Worker Queue 25
Slide 26
Slide 26 text
API Request and Response 26
Slide 27
Slide 27 text
Send notification to Queue 27
Slide 28
Slide 28 text
Start Worker 28
Slide 29
Slide 29 text
Gorush Major Feature 29
Slide 30
Slide 30 text
●GET /api/stat/go ●GET /api/stat/app ●GET /sys/stats ●GET /metrics ●POST /api/push ●GET /healthz API List 30
Slide 31
Slide 31 text
GET /api/stat/go 31
Slide 32
Slide 32 text
GET /api/stat/app 32
Slide 33
Slide 33 text
GET /sys/stats 33
Slide 34
Slide 34 text
GET /metrics (Prometheus) 34
Slide 35
Slide 35 text
GET /metrics (Prometheus + Grafana) $ for i in {1..99999}; do bat -b.N=1000 -b.C=100 POST local:8088/api/push 35
Slide 36
Slide 36 text
GET /metrics (Prometheus + Grafana) 36
Slide 37
Slide 37 text
https://github.com/appleboy/gorush/#post-apipush POST /api/push 37
Slide 38
Slide 38 text
Push API Support Sync Mode Async vs. Sync Push 38
Slide 39
Slide 39 text
Notification Notification Notification Notification worker worker worker Client Notification worker WaitGroup 39
Slide 40
Slide 40 text
Notification Log Wait response Send to Work Queue 40
Slide 41
Slide 41 text
41
Slide 42
Slide 42 text
$ gorush Start Gorush Server 42
Slide 43
Slide 43 text
$ gorush –c config.yml Custom config file 43
Slide 44
Slide 44 text
$ GORUSH_CORE_PORT=8089 gorush Global Variable 44
Slide 45
Slide 45 text
● /etc/gorush/config.yml ● $HOME/.gorush/config.yml ● . (Current Folder) 45 Auto Load Config file
Slide 46
Slide 46 text
Server Confg Route Config 46
Slide 47
Slide 47 text
Server Config Route Config 47
Slide 48
Slide 48 text
48 Go Support Auto TLS Integrate Let's Encrypt
Slide 49
Slide 49 text
Autocert package in Go 49
Slide 50
Slide 50 text
Write one line code to support renew Let’s Encrypt automatically https://goo.gl/pfeC5Q 50
Slide 51
Slide 51 text
Android Config iOS Config Log Config 51
Slide 52
Slide 52 text
Send Android Notification API Key From Request 52
Slide 53
Slide 53 text
iOS Support .p12, .pem or .p8 53 Supports new Apple Token Based Authentication (JWT)
Slide 54
Slide 54 text
Send iOS Notification 54
Slide 55
Slide 55 text
Success or fail records 55
Slide 56
Slide 56 text
memory, blotdb, buntdb, leveldb, redis Storage 56
Slide 57
Slide 57 text
Interface 57
Slide 58
Slide 58 text
Init Interface 58
Slide 59
Slide 59 text
package flg Send Notification From CLI 59
Slide 60
Slide 60 text
Flag in Go 60
Slide 61
Slide 61 text
Flag doesn’t support Global variable Docker Container 61
Slide 62
Slide 62 text
Configuration Management 62
Slide 63
Slide 63 text
$ gorush -android –m="message" -k="API Key" –t="token" Sned Android 63
Slide 64
Slide 64 text
$ gorush -ios -m="message" -i="certificate path" -t="token" -topic="topic" Send iOS 64
Slide 65
Slide 65 text
write once run anywhere Cross Platform 65
Slide 66
Slide 66 text
https://github.com/mitchellh/gox Simple Go Cross Compilation 66
Slide 67
Slide 67 text
67
Slide 68
Slide 68 text
https://github.com/facebookgo/grace Graceful restart & zero downtime 68
Slide 69
Slide 69 text
How to resolve this problem? Facebook Grace doesn’t Support Windows 69
Slide 70
Slide 70 text
// +build windows https://golang.org/pkg/go/build/ Go build Flag 70
Slide 71
Slide 71 text
Build Binary into Docker Container 71
Slide 72
Slide 72 text
Docker Multi-Stage Build 72
Slide 73
Slide 73 text
Build small image using docker multi-stage $ docker build -t appleboy/gorush . https://goo.gl/zQbhmu 73
Slide 74
Slide 74 text
Auto testing and deploy in GO 74
Slide 75
Slide 75 text
Drone 75
Slide 76
Slide 76 text
Continuous Delivery system built on container technology What is Drone? 76
Slide 77
Slide 77 text
How to setup deploy process? 77 Using .drone.yml file
Slide 78
Slide 78 text
Git Test Release Docker Notify How to build Go binary in Drone 78
Slide 79
Slide 79 text
● Testing Code ● Analytic Code ● Code Quality ● Build Binary ● Deploy Binary ● Build Docker Image ● Deploy Docker Container ● Send Notification Pipeline Process in Go 79
Slide 80
Slide 80 text
Git Test Release Docker Notify How to build Go binary in Drone 80
Slide 81
Slide 81 text
First Step: Git Clone 81
Slide 82
Slide 82 text
Git Test Release Docker Notify How to build Go binary in Drone 82
Slide 83
Slide 83 text
Choose Image Testing Process 83
Slide 84
Slide 84 text
Code Quality in Go (golint) 84
Slide 85
Slide 85 text
Check comment typos (Misspell) 85
Slide 86
Slide 86 text
Check code format in Go (gofmt) 86
Slide 87
Slide 87 text
Check vendor folder (govendor) 87
Slide 88
Slide 88 text
Testing in Go $ coverage all https://github.com/appleboy/golang-testing 88
Slide 89
Slide 89 text
Git Test Release Docker Notify How to build Go binary in Drone 89
Slide 90
Slide 90 text
Choose Image Step Name Run on for Git tag event 90
Slide 91
Slide 91 text
Build binary for Cross Platform (gox) 91
Slide 92
Slide 92 text
Deploy to GitHub Release Page 92
Slide 93
Slide 93 text
Git Test Release Docker Notify How to build Go binary in Drone 93
Slide 94
Slide 94 text
Drone Envars Drone Secrets Plugin Image 94
Slide 95
Slide 95 text
Git Test Release Docker Notify How to build Go binary in Drone 95
Slide 96
Slide 96 text
Plugin Image Push Notification From FB Bot 96
Slide 97
Slide 97 text
Happy Coding 97
Slide 98
Slide 98 text
Run Gorush in Kubernets 98
Slide 99
Slide 99 text
99 Container Health Check
Slide 100
Slide 100 text
100 Global Configuration Map
Slide 101
Slide 101 text
101
Slide 102
Slide 102 text
$ kubectl create -f k8s $ kubectl get services $ minikube service frontend Three Steps 102
Slide 103
Slide 103 text
Interesting In Drone http://bit.ly/devops-drone 103
Slide 104
Slide 104 text
Thanks All coming. Any Problem? 104