Skip to content

Commit

Permalink
store libamchine hosts in a map (#3)
Browse files Browse the repository at this point in the history
Loading a new one each time creates a new rpc server,
each time listening on a new port.
  • Loading branch information
bamarni committed Jul 4, 2016
1 parent 55d720e commit 8ee88f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= v2.0.1
VERSION ?= v2.0.2

clean:
rm -rf build
Expand All @@ -11,7 +11,7 @@ build: clean
tar -cvzf build/releases/dockness-$$os-x64.tar.gz -C build/$$os dockness; \
done

release:
release: build
git tag $(VERSION)
git push origin $(VERSION)
github-release release --user bamarni --repo dockness --tag $(VERSION) --name "$(VERSION)"
Expand Down
15 changes: 10 additions & 5 deletions dockness.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"github.com/docker/machine/commands/mcndirs"
"github.com/docker/machine/libmachine"
mcnhost "github.com/docker/machine/libmachine/host"
mcnlog "github.com/docker/machine/libmachine/log"
"github.com/miekg/dns"
"log"
Expand All @@ -15,6 +16,7 @@ import (

var api *libmachine.Client
var ttl uint
var machines = make(map[string]*mcnhost.Host)

func lookup(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
Expand All @@ -35,13 +37,16 @@ func lookup(w dns.ResponseWriter, r *dns.Msg) {
}
machineName := domLevels[len(domLevels)-3]

machine, err := api.Load(machineName)
if err != nil {
mcnlog.Debugf("Couldn't load machine '%s' : %s", machineName, err)
continue
if machines[machineName] == nil {
machine, err := api.Load(machineName)
if err != nil {
mcnlog.Debugf("Couldn't load machine '%s' : %s", machineName, err)
continue
}
machines[machineName] = machine
}

ip, err := machine.Driver.GetIP()
ip, err := machines[machineName].Driver.GetIP()
if err != nil {
mcnlog.Debugf("Couldn't find IP for machine '%s' : %s", machineName, err)
continue
Expand Down

0 comments on commit 8ee88f6

Please sign in to comment.