forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerutil.go
52 lines (46 loc) · 1.4 KB
/
dockerutil.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
package builder
import (
"os"
"github.com/fsouza/go-dockerclient"
"github.com/openshift/source-to-image/pkg/sti/tar"
)
// DockerClient is an interface to the Docker client that contains
// the methods used by the common builder
type DockerClient interface {
BuildImage(opts docker.BuildImageOptions) error
PushImage(opts docker.PushImageOptions, auth docker.AuthConfiguration) error
RemoveImage(name string) error
}
// pushImage pushes a docker image to the registry specified in its tag
func pushImage(client DockerClient, name string, authConfig docker.AuthConfiguration) error {
repository, tag := docker.ParseRepositoryTag(name)
opts := docker.PushImageOptions{
Name: repository,
Tag: tag,
OutputStream: os.Stdout,
}
return client.PushImage(opts, authConfig)
}
func removeImage(client DockerClient, name string) error {
return client.RemoveImage(name)
}
// buildImage invokes a docker build on a particular directory
func buildImage(client DockerClient, dir string, noCache bool, tag string, tar tar.Tar) error {
tarFile, err := tar.CreateTarFile("", dir)
if err != nil {
return err
}
tarStream, err := os.Open(tarFile)
if err != nil {
return err
}
defer tarStream.Close()
opts := docker.BuildImageOptions{
Name: tag,
RmTmpContainer: true,
OutputStream: os.Stdout,
InputStream: tarStream,
NoCache: noCache,
}
return client.BuildImage(opts)
}