-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker.go
More file actions
42 lines (35 loc) · 878 Bytes
/
docker.go
File metadata and controls
42 lines (35 loc) · 878 Bytes
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
package dockercommand
import (
"log"
"os"
docker "github.com/fsouza/go-dockerclient"
)
type Docker struct {
client Client
}
func NewDocker(endpoint string) (*Docker, error) {
endpoint = resolveDockerEndpoint(endpoint)
if len(os.Getenv("DOCKER_CERT_PATH")) != 0 {
client, err := docker.NewTLSClient(endpoint, os.Getenv("DOCKER_CERT_PATH")+"/cert.pem",
os.Getenv("DOCKER_CERT_PATH")+"/key.pem",
os.Getenv("DOCKER_CERT_PATH")+"/ca.pem")
if err != nil {
log.Fatal(err)
}
return &Docker{&FsouzaClient{client}}, nil
}
client, err := docker.NewClient(endpoint)
if err != nil {
return nil, err
}
return &Docker{&FsouzaClient{client}}, nil
}
func resolveDockerEndpoint(input string) string {
if len(input) != 0 {
return input
}
if len(os.Getenv("DOCKER_HOST")) != 0 {
return os.Getenv("DOCKER_HOST")
}
return "unix:///var/run/docker.sock"
}