* Why I create the Gorush Project? * Detail implementation in Golang * Testing and deploy Go project. * Run Gorush in Kubernetes.
A push notification server written in GoGorush1Bo-Yi WuMopcon @ 2017.10.28
View Slide
●Why I create the Gorush Project?●Detail implementation in Golang●Testing and deploy Go project.●Run Gorush in Kubernetes.2Outline
● Mediatek Engineer● DevOps● Golang, PHP, Node.js ..● Some open source● Gitea● Gin● Drone● appleboy @GitHub● appleboy @twitter● appleboy @slideshare● appleboy46 @facebookAbout Me3
● drone/drone● go-gitea/gitea● gin-gonic/gin● appleboy/gorushGo Open Source in GitHub4
● drone/drone● go-gitea/gitea● gin-gonic/gin● appleboy/gorushGo Open Source in GitHub5
https://mcs.mediatek.com/6
MediatekCloudSandboxTriggerPushEmailhookMQTTTCPHTTPMediatek Cloud Sandbox7
MediatekCloudSandboxTriggerPushEmailhookMQTTTCPHTTPMediatek Cloud Sandbox8Forcus on Push notification
https://github.com/appleboy/gorushGorush9
A general push notification serverfor smartphone applicationGorush10
●Written in Go●Push requests to APNs and FCM●Simple HTTP APIs (JSON)●RPC Protocol (gRPC)Gorush11
OverviewClientFCMAPNsGorushPOST /pushJSON BodyHTTPSAPNsProtocol12
●System Requirement●Good Performance●High Concurrency●Simple net/http Package●Easy to LearnWhy I Choose Go13
https://github.com/golang/go/wiki/FromXToGoWhy we switch From XX to Go14
https://github.com/golangtw/jobsWho use Go in Taiwan15
16Push System Architecture
Before Seven years agoFCMAPNsAPI ServerAPI ServerAPI ServerPUSH17
Before Two Years agoFCMAPNsWorkerWorkerWorkerPUSHQueueAPIAPIAPIde-queueAsynchronous NotificationAWSen-queue18
NginxTraefikNow…FCMAPNsGorushGorushGorushPUSHAPIAPIAPIHttpPost /pushGorush = Queue + Worker19
How to implement simple notification serviceGorush Architecture20
How to send notificationClientFCMAPNsGorushPOST /pushJSON BodyHTTPSAPNsProtocol21
●Http Server●gRPC Server●Push API●Worker22Gorush Component
net/http + Gin Route+ Facebook Grace23
Push API using Gin Framework24
Initial Worker Queue25
API Request and Response26
Send notification to Queue27
Start Worker28
Gorush Major Feature29
●GET /api/stat/go●GET /api/stat/app●GET /sys/stats●GET /metrics●POST /api/push●GET /healthzAPI List30
GET /api/stat/go31
GET /api/stat/app32
GET /sys/stats33
GET /metrics (Prometheus)34
GET /metrics (Prometheus + Grafana)$ for i in {1..99999}; do bat -b.N=1000 -b.C=100 POST local:8088/api/push35
GET /metrics (Prometheus + Grafana)36
https://github.com/appleboy/gorush/#post-apipushPOST /api/push37
Push API Support Sync ModeAsync vs. Sync Push38
NotificationNotificationNotificationNotificationworkerworkerworkerClientNotificationworkerWaitGroup39
NotificationLogWait responseSend to WorkQueue40
41
$ gorushStart Gorush Server42
$ gorush –c config.ymlCustom config file43
$ GORUSH_CORE_PORT=8089 gorushGlobal Variable44
● /etc/gorush/config.yml● $HOME/.gorush/config.yml● . (Current Folder)45Auto Load Config file
Server ConfgRouteConfig46
Server ConfigRouteConfig47
48Go Support Auto TLSIntegrate Let's Encrypt
Autocert package in Go49
Write one line code to support renew Let’s Encrypt automaticallyhttps://goo.gl/pfeC5Q50
Android ConfigiOS ConfigLog Config51
Send Android NotificationAPI Key From Request52
iOS Support .p12, .pem or .p853Supports new Apple Token Based Authentication (JWT)
Send iOS Notification54
Success or fail records55
memory, blotdb, buntdb, leveldb, redisStorage56
Interface57
Init Interface58
package flgSend Notification From CLI59
Flag in Go60
Flag doesn’t support Global variableDocker Container61
Configuration Management62
$ gorush -android –m="message" -k="API Key" –t="token"Sned Android63
$ gorush -ios -m="message" -i="certificate path"-t="token" -topic="topic"Send iOS64
write once run anywhereCross Platform65
https://github.com/mitchellh/goxSimple Go Cross Compilation66
67
https://github.com/facebookgo/graceGraceful restart & zero downtime68
How to resolve this problem?Facebook Grace doesn’t Support Windows69
// +build windowshttps://golang.org/pkg/go/build/Go build Flag70
Build Binary into Docker Container71
Docker Multi-Stage Build72
Build small image using docker multi-stage$ docker build -t appleboy/gorush .https://goo.gl/zQbhmu73
Auto testing and deploy in GO74
Drone75
Continuous Delivery systembuilt on container technologyWhat is Drone?76
How to setup deploy process?77Using .drone.yml file
Git Test Release Docker NotifyHow to build Go binary in Drone78
● Testing Code● Analytic Code● Code Quality● Build Binary● Deploy Binary● Build Docker Image● Deploy Docker Container● Send NotificationPipeline Process in Go79
Git Test Release Docker NotifyHow to build Go binary in Drone80
First Step: Git Clone81
Git Test Release Docker NotifyHow to build Go binary in Drone82
Choose ImageTesting Process83
Code Quality in Go (golint)84
Check comment typos (Misspell)85
Check code format in Go (gofmt)86
Check vendor folder (govendor)87
Testing in Go$ coverage allhttps://github.com/appleboy/golang-testing88
Git Test Release Docker NotifyHow to build Go binary in Drone89
Choose ImageStep NameRun on for Git tag event90
Build binary for Cross Platform (gox)91
Deploy to GitHub Release Page92
Git Test Release Docker NotifyHow to build Go binary in Drone93
Drone EnvarsDrone SecretsPlugin Image94
Git Test Release Docker NotifyHow to build Go binary in Drone95
Plugin ImagePush Notification From FB Bot96
Happy Coding 97
Run Gorush in Kubernets98
99Container Health Check
100Global Configuration Map
101
$ kubectl create -f k8s$ kubectl get services$ minikube service frontendThree Steps102
Interesting In Dronehttp://bit.ly/devops-drone103
Thanks All coming.Any Problem?104