Skip to content
Permalink
Browse files

Healthcheck

  • Loading branch information...
s32x committed Mar 20, 2019
1 parent c0a2ec6 commit b8f0519343767126bb4ea0c88fe99d879fc69af4
Showing with 13 additions and 38 deletions.
  1. +1 −8 .circleci/config.yml
  2. +1 −6 Makefile
  3. +1 −1 classifier/classify.go
  4. +1 −1 go.mod
  5. +2 −2 go.sum
  6. +0 −1 main.go
  7. +7 −19 service/service.go
@@ -4,7 +4,6 @@ jobs:
working_directory: /go/src/s32x.com/gamedetect
environment:
- DOCKER_TAG: s32x/gamedetect
- HEROKU_APP: gamedetect
docker:
- image: circleci/golang:1.12
steps:
@@ -18,10 +17,4 @@ jobs:
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Push image to DockerHub
command: docker push $DOCKER_TAG
- run:
name: Install the Heroku CLI
command: curl https://cli-assets.heroku.com/install.sh | sh
- run:
name: Deploy the app
command: make deploy
command: docker push $DOCKER_TAG
@@ -12,9 +12,4 @@ install:
make deps
go install
run:
DEMO=true go run main.go
deploy:
make deps
heroku container:login
heroku container:push web -a gamedetect
heroku container:release web -a gamedetect
DEMO=true go run main.go
@@ -92,7 +92,7 @@ func (c *Classifier) NormalizeOutputs(s *op.Scope, ext string) (tf.Output, tf.Ou
decode = op.DecodeGif(s, input)
case "bmp":
decode = op.DecodeBmp(s, input, op.DecodeBmpChannels(3))
default:
default: // Will default to Jpeg decode
decode = op.DecodeJpeg(s, input, op.DecodeJpegChannels(3))
}

2 go.mod
@@ -10,5 +10,5 @@ require (
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/tensorflow/tensorflow v1.13.1
github.com/valyala/fasttemplate v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a // indirect
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576 // indirect
)
4 go.sum
@@ -11,8 +11,8 @@ github.com/tensorflow/tensorflow v1.13.1/go.mod h1:itOSERT4trABok4UOoG+X4BoKds9F
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a h1:YX8ljsm6wXlHZO+aRz9Exqr0evNhKRNe5K/gi+zKh4U=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576 h1:aUX/1G2gFSs4AsJJg2cL3HuoRhCSCz733FE5GUSuaT4=
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -18,7 +18,6 @@ func main() {
}
defer s.Close()
s.Start(
getenv("ENV", "dev"), // The environment to run the server in
getenv("DOMAIN", "gamedetect.io"), // The host the server is running on
getenv("DEMO", "false"), // Perform sanity tests and serve the web frontend
getenv("PORT", "8080"), // The port the server will run on
@@ -29,36 +29,21 @@ func NewService(graphPath, labelsPath string) (*Service, error) {
func (s *Service) Close() error { return s.classifier.Close() }

// Start begins serving the generated Service on the passed port
func (s *Service) Start(env, domain, demo, port string) {
func (s *Service) Start(domain, demo, port string) {
// Create a new echo Echo and bind all middleware
e := echo.New()
e.HideBanner = true

// Configure SSL, WWW, and Host based redirects if being hosted in a
// production environment
if strings.Contains(strings.ToLower(env), "prod") {
e.Pre(middleware.HTTPSNonWWWRedirect())
e.Pre(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if c.Request().Host == domain {
return next(c)
}
return c.Redirect(http.StatusPermanentRedirect,
c.Scheme()+"://"+domain)
}
})
e.Pre(middleware.CORS())
}

// Bind all middleware
// Bind middleware
e.Pre(middleware.RemoveTrailingSlashWithConfig(
middleware.TrailingSlashConfig{
RedirectCode: http.StatusPermanentRedirect,
}))
e.Pre(middleware.Secure())
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Pre(middleware.Secure())
e.Use(middleware.Gzip())
e.Use(middleware.CORS())

// If hosting as a demonstration, configure a renderer, process all demo
// test data and serve all testdata and static assets on the index
@@ -81,6 +66,9 @@ func (s *Service) Start(env, domain, demo, port string) {

// Bind all API endpoints
e.POST("/", s.Classify)
e.GET("/healthcheck", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})

// Listen and Serve
log.Printf("Starting service on port %v\n", port)

0 comments on commit b8f0519

Please sign in to comment.
You can’t perform that action at this time.