forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategies.go
55 lines (48 loc) · 1.63 KB
/
strategies.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
55
package strategies
import (
dockerclient "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/build"
"github.com/openshift/source-to-image/pkg/build/strategies/onbuild"
"github.com/openshift/source-to-image/pkg/build/strategies/sti"
"github.com/openshift/source-to-image/pkg/docker"
)
// GetStrategy decides what build strategy will be used for the STI build.
func GetStrategy(config *api.Config) (build.Builder, error) {
image, err := GetBuilderImage(config)
if err != nil {
return nil, err
}
if image.OnBuild {
return onbuild.New(config)
}
return sti.New(config)
}
// GetBuilderImage processes the config and performs operations necessary to make
// the Docker image specified as BuilderImage available locally.
// It returns information about the base image, containing metadata necessary
// for choosing the right STI build strategy.
func GetBuilderImage(config *api.Config) (*docker.PullResult, error) {
d, err := docker.New(config.DockerConfig, config.PullAuthentication)
result := docker.PullResult{}
if err != nil {
return nil, err
}
var image *dockerclient.Image
if config.ForcePull {
image, err = d.PullImage(config.BuilderImage)
if err != nil {
glog.Warningf("An error occurred when pulling %s: %v. Attempting to use local image.", config.BuilderImage, err)
image, err = d.CheckImage(config.BuilderImage)
}
} else {
image, err = d.CheckAndPullImage(config.BuilderImage)
}
if err != nil {
return nil, err
}
result.Image = image
result.OnBuild = d.IsImageOnBuild(config.BuilderImage)
return &result, nil
}