woodpecker/pkg/queue/build_runner.go
Alex Suraci a198657a7e Runner -> BuildRunner to be more descriptive
also kill some stale comments
2014-02-25 17:14:14 -08:00

40 lines
1,005 B
Go

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, 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, buildOutput io.Writer) (bool, error) {
builder := build.New(runner.dockerClient)
builder.Build = buildScript
builder.Repo = repo
builder.Key = key
builder.Stdout = buildOutput
builder.Timeout = runner.timeout
err := builder.Run()
return builder.BuildState == nil || builder.BuildState.ExitCode != 0, err
}