mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
implement fix for #2124
This commit is contained in:
parent
c3732041d5
commit
73d04b0398
4 changed files with 94 additions and 81 deletions
12
vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/compiler.go
generated
vendored
12
vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/compiler.go
generated
vendored
|
@ -103,7 +103,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||||
container.Image = "plugins/git:linux-arm64"
|
container.Image = "plugins/git:linux-arm64"
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("%s_clone", c.prefix)
|
name := fmt.Sprintf("%s_clone", c.prefix)
|
||||||
step := c.createProcess(name, container)
|
step := c.createProcess(name, container, "clone")
|
||||||
|
|
||||||
stage := new(backend.Stage)
|
stage := new(backend.Stage)
|
||||||
stage.Name = name
|
stage.Name = name
|
||||||
|
@ -121,7 +121,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||||
stage.Alias = container.Name
|
stage.Alias = container.Name
|
||||||
|
|
||||||
name := fmt.Sprintf("%s_clone_%d", c.prefix, i)
|
name := fmt.Sprintf("%s_clone_%d", c.prefix, i)
|
||||||
step := c.createProcess(name, container)
|
step := c.createProcess(name, container, "clone")
|
||||||
stage.Steps = append(stage.Steps, step)
|
stage.Steps = append(stage.Steps, step)
|
||||||
|
|
||||||
config.Stages = append(config.Stages, stage)
|
config.Stages = append(config.Stages, stage)
|
||||||
|
@ -142,7 +142,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
name := fmt.Sprintf("%s_services_%d", c.prefix, i)
|
name := fmt.Sprintf("%s_services_%d", c.prefix, i)
|
||||||
step := c.createProcess(name, container)
|
step := c.createProcess(name, container, "services")
|
||||||
stage.Steps = append(stage.Steps, step)
|
stage.Steps = append(stage.Steps, step)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
name := fmt.Sprintf("%s_step_%d", c.prefix, i)
|
name := fmt.Sprintf("%s_step_%d", c.prefix, i)
|
||||||
step := c.createProcess(name, container)
|
step := c.createProcess(name, container, "pipeline")
|
||||||
stage.Steps = append(stage.Steps, step)
|
stage.Steps = append(stage.Steps, step)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ func (c *Compiler) setupCache(conf *yaml.Config, ir *backend.Config) {
|
||||||
|
|
||||||
container := c.cacher.Restore(c.metadata.Repo.Name, c.metadata.Curr.Commit.Branch, conf.Cache)
|
container := c.cacher.Restore(c.metadata.Repo.Name, c.metadata.Curr.Commit.Branch, conf.Cache)
|
||||||
name := fmt.Sprintf("%s_restore_cache", c.prefix)
|
name := fmt.Sprintf("%s_restore_cache", c.prefix)
|
||||||
step := c.createProcess(name, container)
|
step := c.createProcess(name, container, "cache")
|
||||||
|
|
||||||
stage := new(backend.Stage)
|
stage := new(backend.Stage)
|
||||||
stage.Name = name
|
stage.Name = name
|
||||||
|
@ -205,7 +205,7 @@ func (c *Compiler) setupCacheRebuild(conf *yaml.Config, ir *backend.Config) {
|
||||||
container := c.cacher.Rebuild(c.metadata.Repo.Name, c.metadata.Curr.Commit.Branch, conf.Cache)
|
container := c.cacher.Rebuild(c.metadata.Repo.Name, c.metadata.Curr.Commit.Branch, conf.Cache)
|
||||||
|
|
||||||
name := fmt.Sprintf("%s_rebuild_cache", c.prefix)
|
name := fmt.Sprintf("%s_rebuild_cache", c.prefix)
|
||||||
step := c.createProcess(name, container)
|
step := c.createProcess(name, container, "cache")
|
||||||
|
|
||||||
stage := new(backend.Stage)
|
stage := new(backend.Stage)
|
||||||
stage.Name = name
|
stage.Name = name
|
||||||
|
|
42
vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go
generated
vendored
42
vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go
generated
vendored
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/cncd/pipeline/pipeline/frontend/yaml"
|
"github.com/cncd/pipeline/pipeline/frontend/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Compiler) createProcess(name string, container *yaml.Container) *backend.Step {
|
func (c *Compiler) createProcess(name string, container *yaml.Container, section string) *backend.Step {
|
||||||
var (
|
var (
|
||||||
detached bool
|
detached bool
|
||||||
workingdir string
|
workingdir string
|
||||||
|
@ -62,25 +62,19 @@ func (c *Compiler) createProcess(name string, container *yaml.Container) *backen
|
||||||
// TODO: This is here for backward compatibility and will eventually be removed.
|
// TODO: This is here for backward compatibility and will eventually be removed.
|
||||||
environment["DRONE_WORKSPACE"] = path.Join(c.base, c.path)
|
environment["DRONE_WORKSPACE"] = path.Join(c.base, c.path)
|
||||||
|
|
||||||
if !isService(container) {
|
if section == "services" || container.Detached {
|
||||||
workingdir = path.Join(c.base, c.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if isService(container) {
|
|
||||||
detached = true
|
detached = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if isPlugin(container) {
|
if detached == false || len(container.Commands) != 0 {
|
||||||
paramsToEnv(container.Vargs, environment)
|
workingdir = path.Join(c.base, c.path)
|
||||||
|
|
||||||
if matchImage(container.Image, c.escalated...) {
|
|
||||||
privileged = true
|
|
||||||
entrypoint = []string{}
|
|
||||||
command = []string{}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isShell(container) {
|
if detached == false {
|
||||||
|
paramsToEnv(container.Vargs, environment)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(container.Commands) != 0 {
|
||||||
entrypoint = []string{"/bin/sh", "-c"}
|
entrypoint = []string{"/bin/sh", "-c"}
|
||||||
command = []string{"echo $CI_SCRIPT | base64 -d | /bin/sh -e"}
|
command = []string{"echo $CI_SCRIPT | base64 -d | /bin/sh -e"}
|
||||||
environment["CI_SCRIPT"] = generateScriptPosix(container.Commands)
|
environment["CI_SCRIPT"] = generateScriptPosix(container.Commands)
|
||||||
|
@ -88,6 +82,12 @@ func (c *Compiler) createProcess(name string, container *yaml.Container) *backen
|
||||||
environment["SHELL"] = "/bin/sh"
|
environment["SHELL"] = "/bin/sh"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if matchImage(container.Image, c.escalated...) {
|
||||||
|
privileged = true
|
||||||
|
entrypoint = []string{}
|
||||||
|
command = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
authConfig := backend.Auth{
|
authConfig := backend.Auth{
|
||||||
Username: container.AuthConfig.Username,
|
Username: container.AuthConfig.Username,
|
||||||
Password: container.AuthConfig.Password,
|
Password: container.AuthConfig.Password,
|
||||||
|
@ -166,15 +166,3 @@ func (c *Compiler) createProcess(name string, container *yaml.Container) *backen
|
||||||
NetworkMode: network_mode,
|
NetworkMode: network_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPlugin(c *yaml.Container) bool {
|
|
||||||
return len(c.Vargs) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func isShell(c *yaml.Container) bool {
|
|
||||||
return len(c.Commands) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func isService(c *yaml.Container) bool {
|
|
||||||
return c.Detached || (isPlugin(c) == false && isShell(c) == false)
|
|
||||||
}
|
|
||||||
|
|
65
vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/linter/linter.go
generated
vendored
65
vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/linter/linter.go
generated
vendored
|
@ -6,6 +6,12 @@ import (
|
||||||
"github.com/cncd/pipeline/pipeline/frontend/yaml"
|
"github.com/cncd/pipeline/pipeline/frontend/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
blockClone uint8 = iota
|
||||||
|
blockPipeline
|
||||||
|
blockServices
|
||||||
|
)
|
||||||
|
|
||||||
// A Linter lints a pipeline configuration.
|
// A Linter lints a pipeline configuration.
|
||||||
type Linter struct {
|
type Linter struct {
|
||||||
trusted bool
|
trusted bool
|
||||||
|
@ -22,10 +28,22 @@ func New(opts ...Option) *Linter {
|
||||||
|
|
||||||
// Lint lints the configuration.
|
// Lint lints the configuration.
|
||||||
func (l *Linter) Lint(c *yaml.Config) error {
|
func (l *Linter) Lint(c *yaml.Config) error {
|
||||||
var containers []*yaml.Container
|
if len(c.Pipeline.Containers) == 0 {
|
||||||
containers = append(containers, c.Pipeline.Containers...)
|
return fmt.Errorf("Invalid or missing pipeline section")
|
||||||
containers = append(containers, c.Services.Containers...)
|
}
|
||||||
|
if err := l.lint(c.Clone.Containers, blockClone); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := l.lint(c.Pipeline.Containers, blockPipeline); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := l.lint(c.Services.Containers, blockServices); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Linter) lint(containers []*yaml.Container, block uint8) error {
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
if err := l.lintImage(container); err != nil {
|
if err := l.lintImage(container); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -35,15 +53,14 @@ func (l *Linter) Lint(c *yaml.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isService(container) == false {
|
if block != blockServices && !container.Detached {
|
||||||
if err := l.lintEntrypoint(container); err != nil {
|
if err := l.lintEntrypoint(container); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if err := l.lintCommands(container); err != nil {
|
||||||
|
return err
|
||||||
if len(c.Pipeline.Containers) == 0 {
|
}
|
||||||
return fmt.Errorf("Invalid or missing pipeline section")
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -55,6 +72,26 @@ func (l *Linter) lintImage(c *yaml.Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Linter) lintCommands(c *yaml.Container) error {
|
||||||
|
if len(c.Commands) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(c.Vargs) != 0 {
|
||||||
|
var keys []string
|
||||||
|
for key := range c.Vargs {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Cannot configure both commands and custom attributes %v", keys)
|
||||||
|
}
|
||||||
|
if len(c.Entrypoint) != 0 {
|
||||||
|
return fmt.Errorf("Cannot configure both commands and entrypoint attributes")
|
||||||
|
}
|
||||||
|
if len(c.Command) != 0 {
|
||||||
|
return fmt.Errorf("Cannot configure both commands and command attributes")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Linter) lintEntrypoint(c *yaml.Container) error {
|
func (l *Linter) lintEntrypoint(c *yaml.Container) error {
|
||||||
if len(c.Entrypoint) != 0 {
|
if len(c.Entrypoint) != 0 {
|
||||||
return fmt.Errorf("Cannot override container entrypoint")
|
return fmt.Errorf("Cannot override container entrypoint")
|
||||||
|
@ -95,15 +132,3 @@ func (l *Linter) lintTrusted(c *yaml.Container) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isService(c *yaml.Container) bool {
|
|
||||||
return !isScript(c) && !isPlugin(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isScript(c *yaml.Container) bool {
|
|
||||||
return len(c.Commands) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func isPlugin(c *yaml.Container) bool {
|
|
||||||
return len(c.Vargs) != 0
|
|
||||||
}
|
|
||||||
|
|
56
vendor/vendor.json
vendored
56
vendor/vendor.json
vendored
|
@ -39,80 +39,80 @@
|
||||||
{
|
{
|
||||||
"checksumSHA1": "W3AuK8ocqHwlUajGmQLFvnRhTZE=",
|
"checksumSHA1": "W3AuK8ocqHwlUajGmQLFvnRhTZE=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline",
|
"path": "github.com/cncd/pipeline/pipeline",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "rO+djTfB4LrT+FBbpotyUUobOtU=",
|
"checksumSHA1": "rO+djTfB4LrT+FBbpotyUUobOtU=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/backend",
|
"path": "github.com/cncd/pipeline/pipeline/backend",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "DzP4c915B+gJTE5RCKQHzxwrUg4=",
|
"checksumSHA1": "DzP4c915B+gJTE5RCKQHzxwrUg4=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/backend/docker",
|
"path": "github.com/cncd/pipeline/pipeline/backend/docker",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "8Hj/OZnYZyz5N2hqENCTTaGtkNQ=",
|
"checksumSHA1": "8Hj/OZnYZyz5N2hqENCTTaGtkNQ=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/frontend",
|
"path": "github.com/cncd/pipeline/pipeline/frontend",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "9KYIsY8WlWbrRAP7caEpWT70P9c=",
|
"checksumSHA1": "9KYIsY8WlWbrRAP7caEpWT70P9c=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml",
|
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "k+JVxks9V84qd+3kefHEtlqLEAA=",
|
"checksumSHA1": "EgCQ0v0mExUBHMoxA6+8J8zWqFE=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/compiler",
|
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/compiler",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "Q0GkNUFamVYIA1Fd8r0A5M6Gx54=",
|
"checksumSHA1": "xBjAqRhLsJyh+8rbaKdPYOntTHw=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/linter",
|
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/linter",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "kx2sPUIMozPC/g6E4w48h3FfH3k=",
|
"checksumSHA1": "kx2sPUIMozPC/g6E4w48h3FfH3k=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/matrix",
|
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/matrix",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "L7Q5qJmPITNmvFEEaj5MPwCWFRk=",
|
"checksumSHA1": "L7Q5qJmPITNmvFEEaj5MPwCWFRk=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/types",
|
"path": "github.com/cncd/pipeline/pipeline/frontend/yaml/types",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "2/3f3oNmxXy5kcrRLCFa24Oc9O4=",
|
"checksumSHA1": "2/3f3oNmxXy5kcrRLCFa24Oc9O4=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/interrupt",
|
"path": "github.com/cncd/pipeline/pipeline/interrupt",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "uOjTfke7Qxosrivgz/nVTHeIP5g=",
|
"checksumSHA1": "uOjTfke7Qxosrivgz/nVTHeIP5g=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/multipart",
|
"path": "github.com/cncd/pipeline/pipeline/multipart",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "YlIaMsvB5fFXRolugambNzkSu4I=",
|
"checksumSHA1": "YlIaMsvB5fFXRolugambNzkSu4I=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/rpc",
|
"path": "github.com/cncd/pipeline/pipeline/rpc",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "WAQJYKWUIFBnL1s8AnY4fePnzJ8=",
|
"checksumSHA1": "WAQJYKWUIFBnL1s8AnY4fePnzJ8=",
|
||||||
"path": "github.com/cncd/pipeline/pipeline/rpc/proto",
|
"path": "github.com/cncd/pipeline/pipeline/rpc/proto",
|
||||||
"revision": "d98623616df20e535445b08baef41bde554454e3",
|
"revision": "ab22744b29732792a53fe22e322a7408ba04d758",
|
||||||
"revisionTime": "2017-07-20T13:40:08Z"
|
"revisionTime": "2017-07-21T21:40:10Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "7Qj1DK0ceAXkYztW0l3+L6sn+V8=",
|
"checksumSHA1": "7Qj1DK0ceAXkYztW0l3+L6sn+V8=",
|
||||||
|
|
Loading…
Reference in a new issue