Skip to content

Commit

Permalink
Merge branch 'WIP-0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
j1n6 committed Sep 18, 2014
2 parents c5f3fe2 + 5bffa5c commit 2e18d50
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 36 deletions.
10 changes: 3 additions & 7 deletions README.md
Expand Up @@ -109,10 +109,8 @@ Configuration in the `production.json` file can be overridden with environment v

Environment Variable | Corresponds To
---------------------|---------------
`MARATHON_ZK_HOST` | Marathon.Zookeeper.Host
`MARATHON_ZK_PATH` | Marathon.Zookeeper.Path
`MARATHON_ENDPOINT` | Marathon.Endpoint
`BAMBOO_HOST` | Bamboo.Host
`BAMBOO_ENDPOINT` | Bamboo.Endpoint
`BAMBOO_ZK_HOST` | Bamboo.Zookeeper.Host
`BAMBOO_ZK_PATH` | Bamboo.Zookeeper.Path
`HAPROXY_TEMPLATE_PATH` | HAProxy.TemplatePath
Expand Down Expand Up @@ -205,11 +203,9 @@ docker build -t bamboo .
Once the image has been built, running as a container is straightforward - you do however still need to provide the configuration to the image as environment variables. Docker allows two options for this - using the `-e` option or by putting them in a file and using the `--env-file` option. For this example we will use the former and we will map through ports 8000 and 80 to the docker host (obviously the hosts configured here will need to be reachable from this container):

````
docker run -t -i --rm -p 8000:8000 -p 80:80 \
-e MARATHON_ZK_HOST=zk:2181 \
-e MARATHON_ZK_PATH=/marathon \
docker run -t -i --rm -p 8000:8000 -p 80:80 \
-e MARATHON_ENDPOINT=http://marathon:8080 \
-e BAMBOO_HOST=http://bamboo:8000 \
-e BAMBOO_ENDPOINT=http://bamboo:8000 \
-e BAMBOO_ZK_HOST=zk:2181 \
-e BAMBOO_ZK_PATH=/bamboo \
bamboo -bind=":8000"
Expand Down
9 changes: 2 additions & 7 deletions config/development.json
@@ -1,15 +1,10 @@
{
"Marathon": {
"Endpoint": "http://localhost:8080",
"Zookeeper": {
"Host": "localhost",
"Path": "/marathon/state",
"ReportingDelay": 5
}
"Endpoint": "http://localhost:8080"
},

"Bamboo": {
"Host": "http://10.0.2.2:8000",
"Endpoint": "http://10.0.2.2:8000",
"Zookeeper": {
"Host": "localhost",
"Path": "/foo",
Expand Down
9 changes: 2 additions & 7 deletions config/production.example.json
@@ -1,15 +1,10 @@
{
"Marathon": {
"Endpoint": "http://localhost:8080",
"Zookeeper": {
"Host": "localhost",
"Path": "/marathon/state",
"ReportingDelay": 5
}
"Endpoint": "http://localhost:8080"
},

"Bamboo": {
"Host": "http://haproxy-ip-address:8000",
"Endpoint": "http://haproxy-ip-address:8000",
"Zookeeper": {
"Host": "localhost",
"Path": "/marathon-haproxy/state",
Expand Down
2 changes: 1 addition & 1 deletion configuration/Bamboo.go
Expand Up @@ -2,7 +2,7 @@ package configuration

type Bamboo struct {
// Service host
Host string
Endpoint string

// Routing configuration storage
Zookeeper Zookeeper
Expand Down
4 changes: 1 addition & 3 deletions configuration/configuration.go
Expand Up @@ -43,11 +43,9 @@ func (config *Configuration) FromFile(filePath string) error {
func FromFile(filePath string) (Configuration, error) {
conf := &Configuration{}
err := conf.FromFile(filePath)
setValueFromEnv(&conf.Marathon.Zookeeper.Host, "MARATHON_ZK_HOST")
setValueFromEnv(&conf.Marathon.Zookeeper.Path, "MARATHON_ZK_PATH")
setValueFromEnv(&conf.Marathon.Endpoint, "MARATHON_ENDPOINT")

setValueFromEnv(&conf.Bamboo.Host, "BAMBOO_HOST")
setValueFromEnv(&conf.Bamboo.Endpoint, "BAMBOO_ENDPOINT")
setValueFromEnv(&conf.Bamboo.Zookeeper.Host, "BAMBOO_ZK_HOST")
setValueFromEnv(&conf.Bamboo.Zookeeper.Path, "BAMBOO_ZK_PATH")

Expand Down
2 changes: 0 additions & 2 deletions configuration/marathon.go
Expand Up @@ -6,6 +6,4 @@ package configuration
type Marathon struct {
// marathon http endpoint including port number
Endpoint string
// Zookeeper setting for marathon
Zookeeper Zookeeper
}
19 changes: 10 additions & 9 deletions main/bamboo/bamboo.go
Expand Up @@ -8,9 +8,9 @@ import (
"os"
"time"

lumberjack "github.com/natefinch/lumberjack"
"github.com/samuel/go-zookeeper/zk"
"github.com/zenazn/goji"
lumberjack "github.com/natefinch/lumberjack"

"github.com/QubitProducts/bamboo/api"
"github.com/QubitProducts/bamboo/configuration"
Expand Down Expand Up @@ -48,7 +48,7 @@ func main() {
zkConn := listenToZookeeper(conf, eventBus)

// Register handlers
handlers := event_bus.Handlers{ Conf: &conf, Zookeeper: zkConn }
handlers := event_bus.Handlers{Conf: &conf, Zookeeper: zkConn}
eventBus.Register(handlers.MarathonEventHandler)
eventBus.Register(handlers.ServiceEventHandler)

Expand All @@ -66,7 +66,7 @@ func initServer(conf *configuration.Configuration, conn *zk.Conn, eventBus *even
goji.Get("/status", api.HandleStatus)

// State API
goji.Get("/api/state", stateAPI.Get)
goji.Get("/api/state", stateAPI.Get)

// Service API
goji.Get("/api/services", serviceAPI.All)
Expand All @@ -85,7 +85,7 @@ func initServer(conf *configuration.Configuration, conn *zk.Conn, eventBus *even
}

func registerMarathonEvent(conf *configuration.Configuration) {
url := conf.Marathon.Endpoint + "/v2/eventSubscriptions?callbackUrl=" + conf.Bamboo.Host + "/api/marathon/event_callback"
url := conf.Marathon.Endpoint + "/v2/eventSubscriptions?callbackUrl=" + conf.Bamboo.Endpoint + "/api/marathon/event_callback"
client := &http.Client{}
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Content-Type", "application/json")
Expand All @@ -95,7 +95,9 @@ func registerMarathonEvent(conf *configuration.Configuration) {
func createAndListen(conf configuration.Zookeeper) (chan zk.Event, *zk.Conn) {
conn, _, err := zk.Connect(conf.ConnectionString(), time.Second*10)

if err != nil { log.Panic(err) }
if err != nil {
log.Panic(err)
}

ch, _ := qzk.ListenToConn(conn, conf.Path, true, conf.Delay())
return ch, conn
Expand All @@ -108,23 +110,22 @@ func listenToZookeeper(conf configuration.Configuration, eventBus *event_bus.Eve
for {
select {
case _ = <-serviceCh:
eventBus.Publish(event_bus.ServiceEvent{ EventType: "change" })
eventBus.Publish(event_bus.ServiceEvent{EventType: "change"})
}
}
}()
return serviceConn
}


func configureLog() {
if len(logPath) > 0 {
log.SetOutput(io.MultiWriter(&lumberjack.Logger{
Filename: logPath,
Filename: logPath,
// megabytes
MaxSize: 100,
MaxBackups: 3,
//days
MaxAge: 28,
MaxAge: 28,
}, os.Stdout))
}
}

0 comments on commit 2e18d50

Please sign in to comment.