/
main.go
53 lines (41 loc) · 1023 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"net/http"
"flag"
"path/filepath"
mcn "github.com/dgageot/docker-machine-proxy/machine"
"github.com/dgageot/docker-machine-proxy/proxy"
"github.com/docker/machine/commands/mcndirs"
"github.com/docker/machine/libmachine"
)
func main() {
if err := run(); err != nil {
panic(err)
}
}
func run() error {
machineName := flag.String("machine", "default", "Docker machine name")
addr := flag.String("addr", "localhost:2375", "Address of the proxy")
help := flag.Bool("help", false, "Show help")
flag.Parse()
if *help {
flag.Usage()
return nil
}
api := libmachine.NewClient(mcndirs.GetBaseDir(), mcndirs.GetMachineCertDir())
defer api.Close()
machine, err := api.Load(*machineName)
if err != nil {
return err
}
url, err := machine.URL()
if err != nil {
return err
}
return http.ListenAndServe(*addr, &proxy.DockerMachineProxy{
Machine: &mcn.DockerMachine{
Url: url,
CertPath: filepath.Join(mcndirs.GetBaseDir(), "machines", *machineName),
},
})
}