Skip to content

Commit

Permalink
Added Docker host in Docker Backend Config
Browse files Browse the repository at this point in the history
  • Loading branch information
fntlnz committed Aug 2, 2016
1 parent c065501 commit bec5381
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Metric string

type BackendConfig struct {
DockerHost string `yaml:"DockerHost"`
TLSCACert string `yaml:"TLSCACert"`
TLSCert string `yaml:"TLSCert"`
TLSKey string `yaml:"TLSKey"`
Expand Down Expand Up @@ -49,6 +50,7 @@ func NewConfigFromFile(file string) (Config, error) {
func (c Config) Print() {
fmt.Println("Backend: ", c.Backend)
fmt.Println("BackendConfig")
fmt.Println("\tDocker Host ", c.BackendConfig.DockerHost)
fmt.Println("\tTLSCACert ", c.BackendConfig.TLSCACert)
fmt.Println("\tTLSCert ", c.BackendConfig.TLSCert)
fmt.Println("\tTLSKey ", c.BackendConfig.TLSKey)
Expand Down
13 changes: 10 additions & 3 deletions container/backend/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
)

const (
DockerAPI = "unix:///var/run/docker.sock"
DockerAPIVersion = "v1.23"
)

Expand All @@ -35,21 +34,29 @@ func NewDockerBackend(c config.BackendConfig) (*Docker, error) {
httpHeaders := map[string]string{
"User-Agent": fmt.Sprintf("kappa/%s", version.Version),
}

dockerHost := "unix:///var/run/docker.sock"

if c.DockerHost != "" {
dockerHost = c.DockerHost
}

if c.TLSCert != "" && c.TLSKey != "" {
tlsOptions := tlsconfig.Options{
CAFile: c.TLSCACert,
CertFile: c.TLSCert,
KeyFile: c.TLSKey,
InsecureSkipVerify: c.AllowInsecure,
}

config, err := tlsconfig.Client(tlsOptions)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: config,
}
proto, addr, _, err := client.ParseHost(DockerAPI)
proto, addr, _, err := client.ParseHost(dockerHost)
if err != nil {
return nil, err
}
Expand All @@ -59,7 +66,7 @@ func NewDockerBackend(c config.BackendConfig) (*Docker, error) {
}
}

client, err := client.NewClient(DockerAPI, DockerAPIVersion, httpClient, httpHeaders)
client, err := client.NewClient(dockerHost, DockerAPIVersion, httpClient, httpHeaders)
if err != nil {
return nil, err
}
Expand Down
5 changes: 1 addition & 4 deletions docs/examples/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---
backend: docker
backend_config:
TLSCACert: "/etc/docker/ca.crt"
TLSCert: "/etc/docker/server.pem"
TLSKey: "/etc/docker/server.key"
AllowInsecure: false
DockerHost: "unix:///var/run/docker.sock"
metrics:
queue_length: "/usr/local/bin/queue_length.sh"
reqsec: "/usr/local/bin/reqsec.sh"

0 comments on commit bec5381

Please sign in to comment.