-
Notifications
You must be signed in to change notification settings - Fork 1
/
executor.go
109 lines (90 loc) · 2.57 KB
/
executor.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package machine
import (
"errors"
"time"
"github.com/Sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
// Force to load docker executor
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/docker"
)
type machineExecutor struct {
provider *machineProvider
executor common.Executor
build *common.Build
data common.ExecutorData
config common.RunnerConfig
}
func (e *machineExecutor) log() (log *logrus.Entry) {
log = e.build.Log()
details, _ := e.build.ExecutorData.(*machineDetails)
if details == nil {
details, _ = e.data.(*machineDetails)
}
if details != nil {
log = log.WithFields(logrus.Fields{
"name": details.Name,
"usedcount": details.UsedCount,
"created": details.Created,
"now": time.Now(),
})
}
if e.config.Docker != nil {
log = log.WithField("docker", e.config.Docker.Host)
}
return
}
func (e *machineExecutor) Shell() *common.ShellScriptInfo {
if e.executor == nil {
return nil
}
return e.executor.Shell()
}
func (e *machineExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) (err error) {
e.build = build
// Use the machine
e.config, e.data, err = e.provider.Use(config, build.ExecutorData)
if err != nil {
return err
}
// TODO: Currently the docker-machine doesn't support multiple builds
build.ProjectRunnerID = 0
if details, _ := build.ExecutorData.(*machineDetails); details != nil {
build.Hostname = details.Name
} else if details, _ := e.data.(*machineDetails); details != nil {
build.Hostname = details.Name
}
e.log().Infoln("Starting docker-machine build...")
// Create original executor
e.executor = e.provider.provider.Create()
if e.executor == nil {
return errors.New("failed to create an executor")
}
return e.executor.Prepare(globalConfig, &e.config, build)
}
func (e *machineExecutor) Run(cmd common.ExecutorCommand) error {
if e.executor == nil {
return errors.New("missing executor")
}
return e.executor.Run(cmd)
}
func (e *machineExecutor) Finish(err error) {
if e.executor != nil {
e.executor.Finish(err)
}
e.log().Infoln("Finished docker-machine build:", err)
}
func (e *machineExecutor) Cleanup() {
// Cleanup executor if were created
if e.executor != nil {
e.executor.Cleanup()
}
// Release allocated machine
if e.data != "" {
e.provider.Release(&e.config, e.data)
e.data = nil
}
}
func init() {
common.RegisterExecutor("docker+machine", newMachineProvider("docker_machines", "docker"))
common.RegisterExecutor("docker-ssh+machine", newMachineProvider("ssh_docker_machines", "docker-ssh"))
}