Skip to content

Commit

Permalink
Update health endpoint to be on the main server port. Streamline Dock…
Browse files Browse the repository at this point in the history
…er releases. Merged #63
  • Loading branch information
mofirouz committed Apr 22, 2017
1 parent 52cf182 commit 721cd2e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
- Updated Zap logging library to latest stable version.
- Command line `--verbose` flag no longer alters the logging output to print to both terminal and file.
- Log output format is set to JSON.
- Updated health endpoint to be on the '/' of the main server port.
- Streamline Docker image releases.

### Fixed
- Fix issue where ping tickers could not have stopped correctly under some circumstances.
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ BINNAME := nakama
VERSION := 0.13.0-dev
BUILDDIR := build
COMMITID := $(shell git rev-parse --short HEAD 2>/dev/null || echo nosha)
DOCKERDIR := install/docker/nakama

PROTOC ?= protoc
PROTOCFLAGS := -I . -I vendor --gogoslick_out=plugins=grpc:.
Expand Down Expand Up @@ -140,3 +141,18 @@ dbsetup:
.PHONY: dbreset
dbreset:
./${BUILDDIR}/dev/${BINNAME} migrate down --limit 0

.PHONY: dockerbuild
dockerbuild:
docker build --build-arg version=${VERSION} ${DOCKERDIR}

.PHONY: docker
docker: dockerbuild
$(eval IMAGEID := $(shell docker images --filter "label=version=${VERSION}" --format "{{.ID}}"))
docker tag ${IMAGEID} heroiclabs/nakama:${VERSION}
docker tag ${IMAGEID} heroiclabs/nakama:latest

.PHONY: dockerpush
dockerpush:
docker push heroiclabs/nakama:${VERSION}
docker push heroiclabs/nakama:latest
11 changes: 9 additions & 2 deletions RELEASEINST.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ The development team use these steps to build and upload a release.

5. Login and access the [new draft release](https://github.com/heroiclabs/nakama/releases) on GitHub. Repeat the changelog in the release description. Then publish the release.

6. Add new `## [Unreleased]` section to start of `CHANGELOG.md`. Increment and add suffix `"-dev"` to version in `Makefile` and commit. i.e. `VERSION := 0.10.0` should now become `VERSION := 0.11.0-dev`.
6. Create Docker image and push to Docker Hub.

```
docker login
make docker dockerpush
```

7. Add new `## [Unreleased]` section to start of `CHANGELOG.md`. Increment and add suffix `"-dev"` to version in `Makefile` and commit. i.e. `VERSION := 0.10.0` should now become `VERSION := 0.11.0-dev`.

```
git add Makefile CHANGELOG.md
git commit -m "Set new development version."
git push origin master
```
```

### Package Managers

Expand Down
2 changes: 2 additions & 0 deletions install/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ To stop and purge all stored data, containers, and images from your machine. Run
## Build and deploy the Docker image
#### You can use the makefile to build, tag and release Docker images. The following is the manual way of doing achieving the same result.
1. To build the image locally. Setup a local copy of the codebase. Run the following command (in the same directory as this README):
If you have updated the version number in the `Dockerfile` also update it in the command below:
Expand Down
8 changes: 7 additions & 1 deletion install/docker/nakama/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ FROM ubuntu:xenial

MAINTAINER Heroic Labs <[email protected]>

ARG version

LABEL version=$version
LABEL description="Distributed server for social and realtime games and apps."

RUN mkdir -p /nakama
RUN mkdir -p /nakama/data/log/
RUN touch /nakama/data/log/nakama.log
Expand All @@ -13,7 +18,8 @@ RUN ln -sf /dev/stdout data/log/nakama.log

RUN apt-get update; apt-get install -y curl

RUN curl -sL https://github.com/heroiclabs/nakama/releases/download/v0.12.1/nakama-0.12.1-linux-amd64.tar.gz | tar xz
RUN echo "Fetching https://github.com/heroiclabs/nakama/releases/download/v$version/nakama-$version-linux-amd64.tar.gz ..."
RUN curl -sL https://github.com/heroiclabs/nakama/releases/download/v$version/nakama-$version-linux-amd64.tar.gz | tar xz

EXPOSE 7350 7351

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func main() {
messageRouter := server.NewMessageRouterService(sessionRegistry)
presenceNotifier := server.NewPresenceNotifier(jsonLogger, config.GetName(), trackerService, messageRouter)
trackerService.AddDiffListener(presenceNotifier.HandleDiff)
authService := server.NewAuthenticationService(jsonLogger, config, db, sessionRegistry, trackerService, messageRouter)
authService := server.NewAuthenticationService(jsonLogger, config, db, statsService, sessionRegistry, trackerService, messageRouter)
opsService := server.NewOpsService(jsonLogger, multiLogger, semver, config, statsService)

gaenabled := len(os.Getenv("NAKAMA_TELEMETRY")) < 1
Expand Down
16 changes: 0 additions & 16 deletions server/ops_accepter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func NewOpsService(logger *zap.Logger, multiLogger *zap.Logger, version string,
},
}

service.mux.HandleFunc("/v0/health", service.healthHandler).Methods("GET")
service.mux.HandleFunc("/v0/cluster/stats", service.statusHandler).Methods("GET")
service.mux.HandleFunc("/v0/config", service.configHandler).Methods("GET")
service.mux.HandleFunc("/v0/info", service.infoHandler).Methods("GET")
Expand All @@ -80,21 +79,6 @@ func NewOpsService(logger *zap.Logger, multiLogger *zap.Logger, version string,

func (s *opsService) Stop() {}

func (s *opsService) healthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")

healthScore := s.statsService.GetHealthStatus()
health := make(map[string]int)
health["status"] = healthScore
healthJSON, _ := json.Marshal(health)

if healthScore > 0 {
w.WriteHeader(500)
}

w.Write(healthJSON)
}

func (s *opsService) statusHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")

Expand Down
14 changes: 13 additions & 1 deletion server/session_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type authenticationService struct {
logger *zap.Logger
config Config
db *sql.DB
statsService StatsService
registry *SessionRegistry
pipeline *pipeline
mux *mux.Router
Expand All @@ -72,13 +73,14 @@ type authenticationService struct {
}

// NewAuthenticationService creates a new AuthenticationService
func NewAuthenticationService(logger *zap.Logger, config Config, db *sql.DB, registry *SessionRegistry, tracker Tracker, messageRouter MessageRouter) *authenticationService {
func NewAuthenticationService(logger *zap.Logger, config Config, db *sql.DB, statService StatsService, registry *SessionRegistry, tracker Tracker, messageRouter MessageRouter) *authenticationService {
s := social.NewClient(5 * time.Second)
p := NewPipeline(config, db, s, tracker, messageRouter, registry)
a := &authenticationService{
logger: logger,
config: config,
db: db,
statsService: statService,
registry: registry,
pipeline: p,
hmacSecretByte: []byte(config.GetSession().EncryptionKey),
Expand Down Expand Up @@ -107,6 +109,16 @@ func NewAuthenticationService(logger *zap.Logger, config Config, db *sql.DB, reg
func (a *authenticationService) configure() {
a.mux = mux.NewRouter()

a.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
healthScore := a.statsService.GetHealthStatus()
status := 200
if healthScore > 0 {
status = 500
}
w.WriteHeader(status)

}).Methods("GET")

a.mux.HandleFunc("/user/login", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
return
Expand Down

0 comments on commit 721cd2e

Please sign in to comment.