mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-27 16:46:22 +00:00
Move plugin config to root.pipeline.[step].settings (#464)
* Move Vargs to Settings * Allow both until deprecation * Add more tests * Adjust schema * Add missing detach option, fix schema tests Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
568dceaccf
commit
71b9179078
11 changed files with 85 additions and 17 deletions
|
@ -380,6 +380,11 @@ Woodpecker gives the ability to define Docker volumes in the Yaml. You can use t
|
||||||
|
|
||||||
For more details check the [volumes docs](/docs/usage/volumes/).
|
For more details check the [volumes docs](/docs/usage/volumes/).
|
||||||
|
|
||||||
|
### `detach`
|
||||||
|
|
||||||
|
Woodpecker gives the ability to detach steps to run them in background until the pipeline finishes.
|
||||||
|
|
||||||
|
For more details check the [service docs](/docs/usage/services#detachment).
|
||||||
|
|
||||||
## Advanced Configurations
|
## Advanced Configurations
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (c *volumeCacher) Restore(repo, branch string, mounts []string) *yaml.Conta
|
||||||
return &yaml.Container{
|
return &yaml.Container{
|
||||||
Name: "rebuild_cache",
|
Name: "rebuild_cache",
|
||||||
Image: "plugins/volume-cache:1.0.0",
|
Image: "plugins/volume-cache:1.0.0",
|
||||||
Vargs: map[string]interface{}{
|
Settings: map[string]interface{}{
|
||||||
"mount": mounts,
|
"mount": mounts,
|
||||||
"path": "/cache",
|
"path": "/cache",
|
||||||
"restore": true,
|
"restore": true,
|
||||||
|
@ -46,7 +46,7 @@ func (c *volumeCacher) Rebuild(repo, branch string, mounts []string) *yaml.Conta
|
||||||
return &yaml.Container{
|
return &yaml.Container{
|
||||||
Name: "rebuild_cache",
|
Name: "rebuild_cache",
|
||||||
Image: "plugins/volume-cache:1.0.0",
|
Image: "plugins/volume-cache:1.0.0",
|
||||||
Vargs: map[string]interface{}{
|
Settings: map[string]interface{}{
|
||||||
"mount": mounts,
|
"mount": mounts,
|
||||||
"path": "/cache",
|
"path": "/cache",
|
||||||
"rebuild": true,
|
"rebuild": true,
|
||||||
|
@ -76,7 +76,7 @@ func (c *s3Cacher) Restore(repo, branch string, mounts []string) *yaml.Container
|
||||||
return &yaml.Container{
|
return &yaml.Container{
|
||||||
Name: "rebuild_cache",
|
Name: "rebuild_cache",
|
||||||
Image: "plugins/s3-cache:latest",
|
Image: "plugins/s3-cache:latest",
|
||||||
Vargs: map[string]interface{}{
|
Settings: map[string]interface{}{
|
||||||
"mount": mounts,
|
"mount": mounts,
|
||||||
"access_key": c.access,
|
"access_key": c.access,
|
||||||
"secret_key": c.secret,
|
"secret_key": c.secret,
|
||||||
|
@ -91,7 +91,7 @@ func (c *s3Cacher) Rebuild(repo, branch string, mounts []string) *yaml.Container
|
||||||
return &yaml.Container{
|
return &yaml.Container{
|
||||||
Name: "rebuild_cache",
|
Name: "rebuild_cache",
|
||||||
Image: "plugins/s3-cache:latest",
|
Image: "plugins/s3-cache:latest",
|
||||||
Vargs: map[string]interface{}{
|
Settings: map[string]interface{}{
|
||||||
"mount": mounts,
|
"mount": mounts,
|
||||||
"access_key": c.access,
|
"access_key": c.access,
|
||||||
"secret_key": c.secret,
|
"secret_key": c.secret,
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||||
// TODO: switch to `:latest` once v1.1.0 got released
|
// TODO: switch to `:latest` once v1.1.0 got released
|
||||||
// https://github.com/woodpecker-ci/plugin-git/issues/3
|
// https://github.com/woodpecker-ci/plugin-git/issues/3
|
||||||
Image: "woodpeckerci/plugin-git:next",
|
Image: "woodpeckerci/plugin-git:next",
|
||||||
Vargs: map[string]interface{}{"depth": "0"},
|
Settings: map[string]interface{}{"depth": "0"},
|
||||||
Environment: c.cloneEnv,
|
Environment: c.cloneEnv,
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("%s_clone", c.prefix)
|
name := fmt.Sprintf("%s_clone", c.prefix)
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (c *Compiler) createProcess(name string, container *yaml.Container, section
|
||||||
}
|
}
|
||||||
|
|
||||||
if !detached {
|
if !detached {
|
||||||
if err := paramsToEnv(container.Vargs, environment); err != nil {
|
if err := paramsToEnv(container.Settings, environment); err != nil {
|
||||||
log.Error().Err(err).Msg("paramsToEnv")
|
log.Error().Err(err).Msg("paramsToEnv")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,9 @@ type (
|
||||||
Secrets Secrets `yaml:"secrets,omitempty"`
|
Secrets Secrets `yaml:"secrets,omitempty"`
|
||||||
Sysctls types.SliceorMap `yaml:"sysctls,omitempty"`
|
Sysctls types.SliceorMap `yaml:"sysctls,omitempty"`
|
||||||
Constraints Constraints `yaml:"when,omitempty"`
|
Constraints Constraints `yaml:"when,omitempty"`
|
||||||
Vargs map[string]interface{} `yaml:",inline"`
|
Settings map[string]interface{} `yaml:"settings"`
|
||||||
|
// Deprecated
|
||||||
|
Vargs map[string]interface{} `yaml:",inline"` // TODO: remove deprecated with v0.16.0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,5 +86,17 @@ func (c *Containers) UnmarshalYAML(value *yaml.Node) error {
|
||||||
c.Containers = append(c.Containers, &container)
|
c.Containers = append(c.Containers, &container)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: drop Vargs in favor of Settings in v1.16.0 release
|
||||||
|
for _, cc := range c.Containers {
|
||||||
|
if cc.Settings == nil && cc.Vargs != nil {
|
||||||
|
cc.Settings = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
for k, v := range cc.Vargs {
|
||||||
|
cc.Settings[k] = v
|
||||||
|
}
|
||||||
|
cc.Vargs = nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,10 @@ tmpfs:
|
||||||
- /var/lib/test
|
- /var/lib/test
|
||||||
when:
|
when:
|
||||||
branch: master
|
branch: master
|
||||||
|
settings:
|
||||||
|
foo: bar
|
||||||
|
baz: false
|
||||||
|
deprecated_setting: fallback
|
||||||
`)
|
`)
|
||||||
|
|
||||||
func TestUnmarshalContainer(t *testing.T) {
|
func TestUnmarshalContainer(t *testing.T) {
|
||||||
|
@ -110,6 +114,13 @@ func TestUnmarshalContainer(t *testing.T) {
|
||||||
Include: []string{"master"},
|
Include: []string{"master"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Settings: map[string]interface{}{
|
||||||
|
"foo": "bar",
|
||||||
|
"baz": false,
|
||||||
|
},
|
||||||
|
Vargs: map[string]interface{}{
|
||||||
|
"deprecated_setting": "fallback",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
got := Container{}
|
got := Container{}
|
||||||
err := yaml.Unmarshal(containerYaml, &got)
|
err := yaml.Unmarshal(containerYaml, &got)
|
||||||
|
@ -135,11 +146,15 @@ func TestUnmarshalContainers(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: "test: { name: unit_test, image: node }",
|
from: "test: { name: unit_test, image: node, deprecated_setting: fallback, settings: { normal_setting: true } }",
|
||||||
want: []*Container{
|
want: []*Container{
|
||||||
{
|
{
|
||||||
Name: "unit_test",
|
Name: "unit_test",
|
||||||
Image: "node",
|
Image: "node",
|
||||||
|
Settings: map[string]interface{}{
|
||||||
|
"deprecated_setting": "fallback",
|
||||||
|
"normal_setting": true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -76,9 +76,9 @@ func (l *Linter) lintCommands(c *yaml.Container) error {
|
||||||
if len(c.Commands) == 0 {
|
if len(c.Commands) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(c.Vargs) != 0 {
|
if len(c.Settings) != 0 {
|
||||||
var keys []string
|
var keys []string
|
||||||
for key := range c.Vargs {
|
for key := range c.Settings {
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Cannot configure both commands and custom attributes %v", keys)
|
return fmt.Errorf("Cannot configure both commands and custom attributes %v", keys)
|
||||||
|
|
|
@ -21,6 +21,8 @@ pipeline:
|
||||||
publish:
|
publish:
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
repo: foo/bar
|
repo: foo/bar
|
||||||
|
settings:
|
||||||
|
foo: bar
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
image: redis
|
image: redis
|
||||||
|
|
|
@ -7,9 +7,11 @@ pipeline:
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
repo: foo/bar
|
repo: foo/bar
|
||||||
tags: latest
|
tags: latest
|
||||||
|
|
||||||
notify:
|
notify:
|
||||||
image: plugins/slack
|
image: plugins/slack
|
||||||
|
settings:
|
||||||
channel: dev
|
channel: dev
|
||||||
|
|
|
@ -21,6 +21,15 @@ pipeline:
|
||||||
- go test
|
- go test
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
image: golang
|
||||||
|
environment:
|
||||||
|
CGO: 0
|
||||||
|
GOOS: linux
|
||||||
|
GOARCH: amd64
|
||||||
|
commands:
|
||||||
|
- go test
|
||||||
|
|
||||||
|
environment-array:
|
||||||
image: golang
|
image: golang
|
||||||
environment:
|
environment:
|
||||||
- CGO=0
|
- CGO=0
|
||||||
|
|
|
@ -97,7 +97,7 @@
|
||||||
"step": {
|
"step": {
|
||||||
"description": "Every step of your pipeline executes arbitrary commands inside a specified docker container. Read more: https://woodpecker-ci.org/docs/usage/pipeline-syntax#steps",
|
"description": "Every step of your pipeline executes arbitrary commands inside a specified docker container. Read more: https://woodpecker-ci.org/docs/usage/pipeline-syntax#steps",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": true,
|
"additionalProperties": false,
|
||||||
"required": ["image"],
|
"required": ["image"],
|
||||||
"properties": {
|
"properties": {
|
||||||
"image": {
|
"image": {
|
||||||
|
@ -121,10 +121,20 @@
|
||||||
},
|
},
|
||||||
"environment": {
|
"environment": {
|
||||||
"description": "Pass environment variables to a pipeline step. Read more: https://woodpecker-ci.org/docs/usage/environment",
|
"description": "Pass environment variables to a pipeline step. Read more: https://woodpecker-ci.org/docs/usage/environment",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "type": "string" },
|
"items": { "type": "string" },
|
||||||
"minLength": 1
|
"minLength": 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": ["boolean", "string", "number"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"secrets": {
|
"secrets": {
|
||||||
"description": "Pass secrets to a pipeline step at runtime. Read more: https://woodpecker-ci.org/docs/usage/secrets",
|
"description": "Pass secrets to a pipeline step at runtime. Read more: https://woodpecker-ci.org/docs/usage/secrets",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
@ -156,6 +166,17 @@
|
||||||
{ "type": "string" },
|
{ "type": "string" },
|
||||||
{ "type": "array", "items": { "type": "string" }, "minLength": 1 }
|
{ "type": "array", "items": { "type": "string" }, "minLength": 1 }
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"detach": {
|
||||||
|
"description": "Detach a step to run in background until pipeline finishes. Read more: https://woodpecker-ci.org/docs/usage/services#detachment",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"description": "Change the settings of your plugin. Read more: https://woodpecker-ci.org/docs/usage/plugins/plugins",
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": ["boolean", "string", "number"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue