forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_runner.go
41 lines (33 loc) · 1.05 KB
/
build_runner.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
package queue
import (
"io"
"time"
"github.com/drone/drone/pkg/build"
"github.com/drone/drone/pkg/build/docker"
"github.com/drone/drone/pkg/build/repo"
"github.com/drone/drone/pkg/build/script"
)
type BuildRunner interface {
Run(buildScript *script.Build, repo *repo.Repo, key []byte, privileged bool, buildOutput io.Writer) (success bool, err error)
}
type buildRunner struct {
dockerClient *docker.Client
timeout time.Duration
}
func NewBuildRunner(dockerClient *docker.Client, timeout time.Duration) BuildRunner {
return &buildRunner{
dockerClient: dockerClient,
timeout: timeout,
}
}
func (runner *buildRunner) Run(buildScript *script.Build, repo *repo.Repo, key []byte, privileged bool, buildOutput io.Writer) (bool, error) {
builder := build.New(runner.dockerClient)
builder.Build = buildScript
builder.Repo = repo
builder.Key = key
builder.Privileged = privileged
builder.Stdout = buildOutput
builder.Timeout = runner.timeout
err := builder.Run()
return builder.BuildState == nil || builder.BuildState.ExitCode != 0, err
}