-
Notifications
You must be signed in to change notification settings - Fork 1
/
executor_docker_command.go
117 lines (96 loc) · 2.58 KB
/
executor_docker_command.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
110
111
112
113
114
115
116
117
package docker
import (
"bytes"
"github.com/fsouza/go-dockerclient"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors"
)
type commandExecutor struct {
executor
}
func (s *commandExecutor) watchContainers(preContainer, buildContainer, postContainer *docker.Container) {
s.Println()
err := s.watchContainer(preContainer, bytes.NewBufferString(s.BuildScript.PreScript))
if err != nil {
s.BuildFinish <- err
return
}
s.Println()
err = s.watchContainer(buildContainer, bytes.NewBufferString(s.BuildScript.BuildScript))
if err != nil {
s.BuildFinish <- err
return
}
s.Println()
err = s.watchContainer(postContainer, bytes.NewBufferString(s.BuildScript.PostScript))
if err != nil {
s.BuildFinish <- err
return
}
s.BuildFinish <- nil
}
func (s *commandExecutor) Start() error {
s.Debugln("Starting Docker command...")
imageName, err := s.getImageName()
if err != nil {
return err
}
options, err := s.prepareBuildContainer()
if err != nil {
return err
}
buildImage, err := s.getPrebuiltImage("build")
if err != nil {
return err
}
// Start pre-build container which will git clone changes
preContainer, err := s.createContainer("pre", buildImage.ID, nil, *options)
if err != nil {
return err
}
// Start post-build container which will upload artifacts
postContainer, err := s.createContainer("post", buildImage.ID, nil, *options)
if err != nil {
return err
}
// Start build container which will run actual build
buildContainer, err := s.createContainer("build", imageName, s.BuildScript.GetCommandWithArguments(), *options)
if err != nil {
return err
}
// Wait for process to exit
go s.watchContainers(preContainer, buildContainer, postContainer)
return nil
}
func init() {
options := executors.ExecutorOptions{
DefaultBuildsDir: "/builds",
DefaultCacheDir: "/cache",
SharedBuildsDir: false,
Shell: common.ShellScriptInfo{
Shell: "bash",
Type: common.NormalShell,
RunnerCommand: "/usr/bin/gitlab-runner-helper",
},
ShowHostname: true,
SupportedOptions: []string{"image", "services"},
}
creator := func() common.Executor {
return &commandExecutor{
executor: executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
},
}
}
featuresUpdater := func(features *common.FeaturesInfo) {
features.Variables = true
features.Image = true
features.Services = true
}
common.RegisterExecutor("docker", executors.DefaultExecutorProvider{
Creator: creator,
FeaturesUpdater: featuresUpdater,
})
}