abstract polling and execution to runner-go library
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/drone/runner-go/environ"
|
||||
"github.com/drone/runner-go/environ/provider"
|
||||
"github.com/drone/runner-go/manifest"
|
||||
"github.com/drone/runner-go/pipeline/runtime"
|
||||
"github.com/drone/runner-go/registry"
|
||||
"github.com/drone/runner-go/secret"
|
||||
|
||||
@@ -90,8 +91,7 @@ func (c *compileCommand) run(*kingpin.ParseContext) error {
|
||||
// lint the pipeline and return an error if any
|
||||
// linting rules are broken
|
||||
lint := linter.New()
|
||||
opts := linter.Opts{Trusted: c.Repo.Trusted}
|
||||
err = lint.Lint(resource, opts)
|
||||
err = lint.Lint(resource, c.Repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (c *compileCommand) run(*kingpin.ParseContext) error {
|
||||
comp.Mount, _ = os.Getwd()
|
||||
}
|
||||
|
||||
args := compiler.Args{
|
||||
args := runtime.CompilerArgs{
|
||||
Pipeline: resource,
|
||||
Manifest: manifest,
|
||||
Build: c.Build,
|
||||
|
||||
@@ -13,15 +13,16 @@ import (
|
||||
"github.com/drone-runners/drone-runner-docker/engine/linter"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/resource"
|
||||
"github.com/drone-runners/drone-runner-docker/internal/match"
|
||||
"github.com/drone-runners/drone-runner-docker/runtime"
|
||||
|
||||
"github.com/drone/runner-go/client"
|
||||
"github.com/drone/runner-go/environ/provider"
|
||||
"github.com/drone/runner-go/handler/router"
|
||||
"github.com/drone/runner-go/logger"
|
||||
loghistory "github.com/drone/runner-go/logger/history"
|
||||
"github.com/drone/runner-go/pipeline/history"
|
||||
"github.com/drone/runner-go/pipeline/remote"
|
||||
"github.com/drone/runner-go/pipeline/reporter/history"
|
||||
"github.com/drone/runner-go/pipeline/reporter/remote"
|
||||
"github.com/drone/runner-go/pipeline/runtime"
|
||||
"github.com/drone/runner-go/poller"
|
||||
"github.com/drone/runner-go/registry"
|
||||
"github.com/drone/runner-go/secret"
|
||||
"github.com/drone/runner-go/server"
|
||||
@@ -107,67 +108,70 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error {
|
||||
hook := loghistory.New()
|
||||
logrus.AddHook(hook)
|
||||
|
||||
poller := &runtime.Poller{
|
||||
Client: cli,
|
||||
Runner: &runtime.Runner{
|
||||
Client: cli,
|
||||
Machine: config.Runner.Name,
|
||||
Reporter: tracer,
|
||||
Linter: linter.New(),
|
||||
Match: match.Func(
|
||||
config.Limit.Repos,
|
||||
config.Limit.Events,
|
||||
config.Limit.Trusted,
|
||||
),
|
||||
Compiler: &compiler.Compiler{
|
||||
Clone: config.Runner.Clone,
|
||||
Privileged: append(config.Runner.Privileged, compiler.Privileged...),
|
||||
Networks: config.Runner.Networks,
|
||||
Volumes: config.Runner.Volumes,
|
||||
Resources: compiler.Resources{
|
||||
Memory: config.Resources.Memory,
|
||||
MemorySwap: config.Resources.MemorySwap,
|
||||
CPUQuota: config.Resources.CPUQuota,
|
||||
CPUPeriod: config.Resources.CPUPeriod,
|
||||
CPUShares: config.Resources.CPUShares,
|
||||
CPUSet: config.Resources.CPUSet,
|
||||
},
|
||||
Environ: provider.Combine(
|
||||
provider.Static(config.Runner.Environ),
|
||||
provider.External(
|
||||
config.Environ.Endpoint,
|
||||
config.Environ.Token,
|
||||
config.Environ.SkipVerify,
|
||||
),
|
||||
),
|
||||
Registry: registry.Combine(
|
||||
registry.File(
|
||||
config.Docker.Config,
|
||||
),
|
||||
registry.External(
|
||||
config.Registry.Endpoint,
|
||||
config.Registry.Token,
|
||||
config.Registry.SkipVerify,
|
||||
),
|
||||
),
|
||||
Secret: secret.Combine(
|
||||
secret.StaticVars(
|
||||
config.Runner.Secrets,
|
||||
),
|
||||
secret.External(
|
||||
config.Secret.Endpoint,
|
||||
config.Secret.Token,
|
||||
config.Secret.SkipVerify,
|
||||
),
|
||||
),
|
||||
runner := &runtime.Runner{
|
||||
Client: cli,
|
||||
Machine: config.Runner.Name,
|
||||
Reporter: tracer,
|
||||
Lookup: resource.Lookup,
|
||||
Lint: linter.New().Lint,
|
||||
Match: match.Func(
|
||||
config.Limit.Repos,
|
||||
config.Limit.Events,
|
||||
config.Limit.Trusted,
|
||||
),
|
||||
Compiler: &compiler.Compiler{
|
||||
Clone: config.Runner.Clone,
|
||||
Privileged: append(config.Runner.Privileged, compiler.Privileged...),
|
||||
Networks: config.Runner.Networks,
|
||||
Volumes: config.Runner.Volumes,
|
||||
Resources: compiler.Resources{
|
||||
Memory: config.Resources.Memory,
|
||||
MemorySwap: config.Resources.MemorySwap,
|
||||
CPUQuota: config.Resources.CPUQuota,
|
||||
CPUPeriod: config.Resources.CPUPeriod,
|
||||
CPUShares: config.Resources.CPUShares,
|
||||
CPUSet: config.Resources.CPUSet,
|
||||
},
|
||||
Execer: runtime.NewExecer(
|
||||
tracer,
|
||||
remote,
|
||||
engine,
|
||||
config.Runner.Procs,
|
||||
Environ: provider.Combine(
|
||||
provider.Static(config.Runner.Environ),
|
||||
provider.External(
|
||||
config.Environ.Endpoint,
|
||||
config.Environ.Token,
|
||||
config.Environ.SkipVerify,
|
||||
),
|
||||
),
|
||||
Registry: registry.Combine(
|
||||
registry.File(
|
||||
config.Docker.Config,
|
||||
),
|
||||
registry.External(
|
||||
config.Registry.Endpoint,
|
||||
config.Registry.Token,
|
||||
config.Registry.SkipVerify,
|
||||
),
|
||||
),
|
||||
Secret: secret.Combine(
|
||||
secret.StaticVars(
|
||||
config.Runner.Secrets,
|
||||
),
|
||||
secret.External(
|
||||
config.Secret.Endpoint,
|
||||
config.Secret.Token,
|
||||
config.Secret.SkipVerify,
|
||||
),
|
||||
),
|
||||
},
|
||||
Exec: runtime.NewExecer(
|
||||
tracer,
|
||||
remote,
|
||||
engine,
|
||||
config.Runner.Procs,
|
||||
).Exec,
|
||||
}
|
||||
|
||||
poller := &poller.Poller{
|
||||
Client: cli,
|
||||
Dispatch: runner.Run,
|
||||
Filter: &client.Filter{
|
||||
Kind: resource.Kind,
|
||||
Type: resource.Type,
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/drone-runners/drone-runner-docker/engine/compiler"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/linter"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/resource"
|
||||
"github.com/drone-runners/drone-runner-docker/runtime"
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/envsubst"
|
||||
"github.com/drone/runner-go/environ"
|
||||
@@ -26,7 +25,8 @@ import (
|
||||
"github.com/drone/runner-go/logger"
|
||||
"github.com/drone/runner-go/manifest"
|
||||
"github.com/drone/runner-go/pipeline"
|
||||
"github.com/drone/runner-go/pipeline/console"
|
||||
"github.com/drone/runner-go/pipeline/runtime"
|
||||
"github.com/drone/runner-go/pipeline/streamer/console"
|
||||
"github.com/drone/runner-go/registry"
|
||||
"github.com/drone/runner-go/secret"
|
||||
"github.com/drone/signal"
|
||||
@@ -102,7 +102,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
|
||||
// a configuration can contain multiple pipelines.
|
||||
// get a specific pipeline resource for execution.
|
||||
resource, err := resource.Lookup(c.Stage.Name, manifest)
|
||||
res, err := resource.Lookup(c.Stage.Name, manifest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -110,8 +110,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
// lint the pipeline and return an error if any
|
||||
// linting rules are broken
|
||||
lint := linter.New()
|
||||
opts := linter.Opts{Trusted: c.Repo.Trusted}
|
||||
err = lint.Lint(resource, opts)
|
||||
err = lint.Lint(res, c.Repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -137,8 +136,8 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
comp.Mount, _ = os.Getwd()
|
||||
}
|
||||
|
||||
args := compiler.Args{
|
||||
Pipeline: resource,
|
||||
args := runtime.CompilerArgs{
|
||||
Pipeline: res,
|
||||
Manifest: manifest,
|
||||
Build: c.Build,
|
||||
Netrc: c.Netrc,
|
||||
@@ -146,7 +145,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
Stage: c.Stage,
|
||||
System: c.System,
|
||||
}
|
||||
spec := comp.Compile(nocontext, args)
|
||||
spec := comp.Compile(nocontext, args).(*engine.Spec)
|
||||
|
||||
// include only steps that are in the include list,
|
||||
// if the list in non-empty.
|
||||
@@ -161,7 +160,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
continue I
|
||||
}
|
||||
}
|
||||
step.RunPolicy = engine.RunNever
|
||||
step.RunPolicy = runtime.RunNever
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +174,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
}
|
||||
for _, name := range c.Exclude {
|
||||
if step.Name == name {
|
||||
step.RunPolicy = engine.RunNever
|
||||
step.RunPolicy = runtime.RunNever
|
||||
continue E
|
||||
}
|
||||
}
|
||||
@@ -184,7 +183,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
|
||||
// create a step object for each pipeline step.
|
||||
for _, step := range spec.Steps {
|
||||
if step.RunPolicy == engine.RunNever {
|
||||
if step.RunPolicy == runtime.RunNever {
|
||||
continue
|
||||
}
|
||||
c.Stage.Steps = append(c.Stage.Steps, &drone.Step{
|
||||
|
||||
Reference in New Issue
Block a user