Skip to content

Commit

Permalink
Start command and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed Dec 1, 2016
1 parent 95ed6c4 commit b9f8e27
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 6 deletions.
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:1.6.2-alpine

MAINTAINER TFG Co <backend@tfgco.com>

EXPOSE 8888

RUN apk update
RUN apk add --update git make g++ apache2-utils bash

RUN go get -u github.com/Masterminds/glide/...

ADD . /go/src/github.com/topfreegames/donations

WORKDIR /go/src/github.com/topfreegames/donations
RUN glide install
RUN go install github.com/topfreegames/donations

ENV DONATIONS_MONGODB_HOST 0.0.0.0
ENV DONATIONS_MONGODB_PORT 27017
ENV DONATIONS_MONGODB_DB donations
ENV DONATIONS_REDIS_URL redis://0.0.0.0:3456/0
ENV DONATIONS_REDIS_MAXIDLE 3
ENV DONATIONS_REDIS_IDLETIMEOUTSECONDS 240

ENV DONATIONS_SENTRY_URL ""
ENV DONATIONS_NEWRELIC_KEY ""
ENV DONATIONS_NEWRELIC_APPNAME ""

ENV DONATIONS_BASICAUTH_USERNAME ""
ENV DONATIONS_BASICAUTH_PASSWORD ""

CMD /go/bin/donations start --bind 0.0.0.0 --port 8888 --fast --config /go/src/github.com/topfreegames/donations/config/default.yaml
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: docs db

MY_IP=`ifconfig | grep --color=none -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep --color=none -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1`
PACKAGES = $(shell glide novendor)
OS = "$(shell uname | awk '{ print tolower($$0) }')"

Expand Down Expand Up @@ -34,9 +35,16 @@ cross:
@chmod +x bin/*

docker-build:
@mkdir -p ./_build/docker
@docker build -t donations -f Dockerfile .

docker-run:
@echo "Running docker with MongoDB: ${MY_IP}:9999..."
@docker run -i -t --rm \
-e "DONATIONS_MONGO_HOST=${MY_IP}" \
-e "DONATIONS_MONGO_PORT=9999" \
-p 8888:8888 \
donations

docker-services-dev: docker-services-shutdown
@docker-compose -p donations-dev -f ./docker-compose-dev.yml up -d

Expand Down
87 changes: 87 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// donations
// https://github.com/topfreegames/donations
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license
// Copyright © 2016 Top Free Games <backend@tfgco.com>

package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/topfreegames/donations/api"
"github.com/topfreegames/donations/log"
"github.com/uber-go/zap"
)

var host string
var port int
var debug bool
var quiet bool
var fast bool
var configFile string

// startCmd represents the start command
var startCmd = &cobra.Command{
Use: "start",
Short: "starts the donations API server",
Long: `Starts donations server with the specified arguments. You can use
environment variables to override configuration keys.`,
Run: func(cmd *cobra.Command, args []string) {
ll := zap.InfoLevel
if debug {
ll = zap.DebugLevel
}
if quiet {
ll = zap.ErrorLevel
}
l := zap.New(
zap.NewJSONEncoder(), // drop timestamps in tests
ll,
)

cmdL := l.With(
zap.String("source", "startCmd"),
zap.String("operation", "Run"),
zap.String("host", host),
zap.Int("port", port),
zap.Bool("debug", debug),
)

log.D(cmdL, "Creating application...")
app, err := api.GetApp(
host,
port,
configFile,
debug,
l,
false,
fast,
)

if err != nil {
log.E(cmdL, "Application failed to start.", func(cm log.CM) {
cm.Write(zap.Error(err))
})
os.Exit(1)
}
log.D(cmdL, "Application created successfully.")

log.I(cmdL, fmt.Sprintf("Application started successfully at %s:%d", host, port))
app.Start()
},
}

func init() {
RootCmd.AddCommand(startCmd)

startCmd.Flags().StringVarP(&host, "bind", "b", "0.0.0.0", "Host to bind donations to")
startCmd.Flags().IntVarP(&port, "port", "p", 8888, "Port to bind donations to")
startCmd.Flags().StringVarP(&configFile, "config", "c", "./config/default.yaml", "Configuration path")
startCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Debug mode")
startCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "Quiet mode (log level error)")
startCmd.Flags().BoolVarP(&fast, "fast", "f", false, "Use FastHTTP as the Engine. If false, the net/http engine will be used")
}
4 changes: 1 addition & 3 deletions docs/hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Donations uses MongoDB to store clans information. The container takes environme

* `DONATIONS_MONGO_HOST` - MongoDB host to connect to;
* `DONATIONS_MONGO_PORT` - MongoDB port to connect to;
* `DONATIONS_MONGO_USER` - Password of the MongoDB Server to connect to;
* `DONATIONS_MONGO_DBNAME` - Database name of the MongoDB Server to connect to;
* `DONATIONS_MONGO_SSLMODE` - SSL Mode to connect to mongoDB with.
* `DONATIONS_MONGO_DB` - Database name of the MongoDB Server to connect to.

Donations uses Redis for global locks. The container takes environment variables to specify this connection:

Expand Down
2 changes: 0 additions & 2 deletions push_to_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

VERSION=$(cat version.txt | sed "s@donations v@@g")

cp ./config/default.yaml ./dev

docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"

docker build -t donations .
Expand Down

0 comments on commit b9f8e27

Please sign in to comment.