2014-02-25 04:51:25 +03:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2014-02-26 04:14:14 +03:00
|
|
|
type BuildRunner interface {
|
2014-03-27 08:40:17 +03:00
|
|
|
Run(buildScript *script.Build, repo *repo.Repo, key []byte, privileged bool, buildOutput io.Writer) (success bool, err error)
|
2014-02-25 04:51:25 +03:00
|
|
|
}
|
|
|
|
|
2014-02-26 04:14:14 +03:00
|
|
|
type buildRunner struct {
|
2014-02-25 04:51:25 +03:00
|
|
|
dockerClient *docker.Client
|
|
|
|
timeout time.Duration
|
|
|
|
}
|
|
|
|
|
2014-02-26 04:14:14 +03:00
|
|
|
func NewBuildRunner(dockerClient *docker.Client, timeout time.Duration) BuildRunner {
|
|
|
|
return &buildRunner{
|
2014-02-25 04:51:25 +03:00
|
|
|
dockerClient: dockerClient,
|
|
|
|
timeout: timeout,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-27 08:40:17 +03:00
|
|
|
func (runner *buildRunner) Run(buildScript *script.Build, repo *repo.Repo, key []byte, privileged bool, buildOutput io.Writer) (bool, error) {
|
2014-02-26 04:14:14 +03:00
|
|
|
builder := build.New(runner.dockerClient)
|
2014-02-25 04:51:25 +03:00
|
|
|
builder.Build = buildScript
|
|
|
|
builder.Repo = repo
|
|
|
|
builder.Key = key
|
2014-03-27 08:40:17 +03:00
|
|
|
builder.Privileged = privileged
|
2014-02-25 04:51:25 +03:00
|
|
|
builder.Stdout = buildOutput
|
2014-02-26 04:14:14 +03:00
|
|
|
builder.Timeout = runner.timeout
|
2014-02-25 04:51:25 +03:00
|
|
|
|
|
|
|
err := builder.Run()
|
|
|
|
|
|
|
|
return builder.BuildState == nil || builder.BuildState.ExitCode != 0, err
|
|
|
|
}
|