woodpecker/server/queue/build_runner.go

42 lines
1.1 KiB
Go
Raw Normal View History

package queue
import (
"io"
"time"
2014-06-04 21:44:05 +00:00
"github.com/drone/drone/shared/build"
"github.com/drone/drone/shared/build/docker"
"github.com/drone/drone/shared/build/repo"
"github.com/drone/drone/shared/build/script"
)
type BuildRunner interface {
2014-03-27 05:40:17 +00:00
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,
}
}
2014-03-27 05:40:17 +00:00
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
2014-03-27 05:40:17 +00:00
builder.Privileged = privileged
builder.Stdout = buildOutput
builder.Timeout = runner.timeout
err := builder.Run()
return builder.BuildState == nil || builder.BuildState.ExitCode != 0, err
}