-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.go
54 lines (40 loc) · 991 Bytes
/
docker.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
54
package main
import (
"io"
"os"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"golang.org/x/net/context"
)
type DockerAuth struct {
Username string
Password string
ServerAddress string
}
func NewDockerClient() *client.Client {
dockerApiVersion := os.Getenv("DockerApiVersion")
if dockerApiVersion == "" {
dockerApiVersion = "1.38"
}
c, err := client.NewClientWithOpts(client.WithVersion(dockerApiVersion))
CheckIfError(err)
return c // enforce the default value here
}
func PullPublicImage(img string) bool {
dockerClient := NewDockerClient()
ctx := context.Background()
pull, err := dockerClient.ImagePull(ctx, img, types.ImagePullOptions{})
if err != nil {
fmt.Println(err)
return false
} else {
io.Copy(os.Stdout, pull)
return true
}
}
func Tag(sourcetag, destinationtag string) {
dockerClient := NewDockerClient()
ctx := context.Background()
dockerClient.ImageTag(ctx, sourcetag, destinationtag)
}