-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.go
50 lines (38 loc) · 928 Bytes
/
helper.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
package vm
import (
"context"
"fmt"
"github.com/thoas/go-funk"
"github.com/docker/docker/client"
"github.com/franela/goreq"
)
const gitURL = "https://raw.githubusercontent.com/ellcrys/vm-dockerfile"
// dockerAlive checks whether docker server is alive
func dockerAlive() error {
cli, err := client.NewClientWithOpts()
if err != nil {
return err
}
_, err = cli.Info(context.Background())
if err != nil {
if funk.Contains(err.Error(), "Cannot connect to the Docker") {
return err
}
panic(err)
}
return cli.Close()
}
//getDockerFile fetches Dockerfile from github.
func getDockerFile(version string) (*goreq.Response, error) {
commitURI := fmt.Sprintf("%s/%s/Dockerfile", gitURL, version)
res, err := goreq.Request{
Uri: commitURI,
}.Do()
if err != nil {
return nil, err
}
if res.Status == "404 Not Found" {
return nil, fmt.Errorf("%s", "Docker file not found")
}
return res, nil
}