mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 19:31:05 +00:00
Remove unused step options (#1957)
remove them as they did never had any functionality
This commit is contained in:
parent
b3f65d9d01
commit
de13aeea33
4 changed files with 30 additions and 266 deletions
|
@ -38,26 +38,21 @@ type (
|
||||||
Privileged bool `yaml:"privileged,omitempty"`
|
Privileged bool `yaml:"privileged,omitempty"`
|
||||||
|
|
||||||
// Undocumented
|
// Undocumented
|
||||||
CapAdd []string `yaml:"cap_add,omitempty"`
|
CPUQuota base.StringOrInt `yaml:"cpu_quota,omitempty"`
|
||||||
CapDrop []string `yaml:"cap_drop,omitempty"`
|
CPUSet string `yaml:"cpuset,omitempty"`
|
||||||
CPUQuota base.StringOrInt `yaml:"cpu_quota,omitempty"`
|
CPUShares base.StringOrInt `yaml:"cpu_shares,omitempty"`
|
||||||
CPUSet string `yaml:"cpuset,omitempty"`
|
Devices []string `yaml:"devices,omitempty"`
|
||||||
CPUShares base.StringOrInt `yaml:"cpu_shares,omitempty"`
|
DNSSearch base.StringOrSlice `yaml:"dns_search,omitempty"`
|
||||||
Devices []string `yaml:"devices,omitempty"`
|
DNS base.StringOrSlice `yaml:"dns,omitempty"`
|
||||||
DNSSearch base.StringOrSlice `yaml:"dns_search,omitempty"`
|
ExtraHosts []string `yaml:"extra_hosts,omitempty"`
|
||||||
DNS base.StringOrSlice `yaml:"dns,omitempty"`
|
IpcMode string `yaml:"ipc_mode,omitempty"`
|
||||||
ExtraHosts []string `yaml:"extra_hosts,omitempty"`
|
MemLimit base.MemStringOrInt `yaml:"mem_limit,omitempty"`
|
||||||
IpcMode string `yaml:"ipc_mode,omitempty"`
|
MemSwapLimit base.MemStringOrInt `yaml:"memswap_limit,omitempty"`
|
||||||
Isolation string `yaml:"isolation,omitempty"`
|
NetworkMode string `yaml:"network_mode,omitempty"`
|
||||||
MemLimit base.MemStringOrInt `yaml:"mem_limit,omitempty"`
|
Networks Networks `yaml:"networks,omitempty"`
|
||||||
MemSwapLimit base.MemStringOrInt `yaml:"memswap_limit,omitempty"`
|
ShmSize base.MemStringOrInt `yaml:"shm_size,omitempty"`
|
||||||
MemSwappiness base.MemStringOrInt `yaml:"mem_swappiness,omitempty"`
|
Sysctls base.SliceOrMap `yaml:"sysctls,omitempty"`
|
||||||
NetworkMode string `yaml:"network_mode,omitempty"`
|
Tmpfs []string `yaml:"tmpfs,omitempty"`
|
||||||
Networks Networks `yaml:"networks,omitempty"`
|
|
||||||
ShmSize base.MemStringOrInt `yaml:"shm_size,omitempty"`
|
|
||||||
Sysctls base.SliceOrMap `yaml:"sysctls,omitempty"`
|
|
||||||
Tmpfs []string `yaml:"tmpfs,omitempty"`
|
|
||||||
Ulimits Ulimits `yaml:"ulimits,omitempty"`
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ import (
|
||||||
|
|
||||||
var containerYaml = []byte(`
|
var containerYaml = []byte(`
|
||||||
image: golang:latest
|
image: golang:latest
|
||||||
cap_add: [ ALL ]
|
|
||||||
cap_drop: [ NET_ADMIN, SYS_ADMIN ]
|
|
||||||
commands:
|
commands:
|
||||||
- go build
|
- go build
|
||||||
- go test
|
- go test
|
||||||
|
@ -33,7 +31,6 @@ environment:
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- somehost:162.242.195.82
|
- somehost:162.242.195.82
|
||||||
- otherhost:50.31.209.229
|
- otherhost:50.31.209.229
|
||||||
isolation: hyperv
|
|
||||||
name: my-build-container
|
name: my-build-container
|
||||||
network_mode: bridge
|
network_mode: bridge
|
||||||
networks:
|
networks:
|
||||||
|
@ -44,7 +41,6 @@ privileged: true
|
||||||
shm_size: 1kb
|
shm_size: 1kb
|
||||||
mem_limit: 1kb
|
mem_limit: 1kb
|
||||||
memswap_limit: 1kb
|
memswap_limit: 1kb
|
||||||
mem_swappiness: 1kb
|
|
||||||
volumes:
|
volumes:
|
||||||
- /var/lib/mysql
|
- /var/lib/mysql
|
||||||
- /opt/data:/var/lib/mysql
|
- /opt/data:/var/lib/mysql
|
||||||
|
@ -62,25 +58,21 @@ settings:
|
||||||
|
|
||||||
func TestUnmarshalContainer(t *testing.T) {
|
func TestUnmarshalContainer(t *testing.T) {
|
||||||
want := Container{
|
want := Container{
|
||||||
CapAdd: []string{"ALL"},
|
Commands: base.StringOrSlice{"go build", "go test"},
|
||||||
CapDrop: []string{"NET_ADMIN", "SYS_ADMIN"},
|
CPUQuota: base.StringOrInt(11),
|
||||||
Commands: base.StringOrSlice{"go build", "go test"},
|
CPUSet: "1,2",
|
||||||
CPUQuota: base.StringOrInt(11),
|
CPUShares: base.StringOrInt(99),
|
||||||
CPUSet: "1,2",
|
Detached: true,
|
||||||
CPUShares: base.StringOrInt(99),
|
Devices: []string{"/dev/ttyUSB0:/dev/ttyUSB0"},
|
||||||
Detached: true,
|
Directory: "example/",
|
||||||
Devices: []string{"/dev/ttyUSB0:/dev/ttyUSB0"},
|
DNS: base.StringOrSlice{"8.8.8.8"},
|
||||||
Directory: "example/",
|
DNSSearch: base.StringOrSlice{"example.com"},
|
||||||
DNS: base.StringOrSlice{"8.8.8.8"},
|
Environment: base.SliceOrMap{"RACK_ENV": "development", "SHOW": "true"},
|
||||||
DNSSearch: base.StringOrSlice{"example.com"},
|
ExtraHosts: []string{"somehost:162.242.195.82", "otherhost:50.31.209.229"},
|
||||||
Environment: base.SliceOrMap{"RACK_ENV": "development", "SHOW": "true"},
|
Image: "golang:latest",
|
||||||
ExtraHosts: []string{"somehost:162.242.195.82", "otherhost:50.31.209.229"},
|
MemLimit: base.MemStringOrInt(1024),
|
||||||
Image: "golang:latest",
|
MemSwapLimit: base.MemStringOrInt(1024),
|
||||||
Isolation: "hyperv",
|
Name: "my-build-container",
|
||||||
MemLimit: base.MemStringOrInt(1024),
|
|
||||||
MemSwapLimit: base.MemStringOrInt(1024),
|
|
||||||
MemSwappiness: base.MemStringOrInt(1024),
|
|
||||||
Name: "my-build-container",
|
|
||||||
Networks: Networks{
|
Networks: Networks{
|
||||||
Networks: []*Network{
|
Networks: []*Network{
|
||||||
{Name: "some-network"},
|
{Name: "some-network"},
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ulimits represents a list of Ulimit.
|
|
||||||
// It is, however, represented in yaml as keys (and thus map in Go)
|
|
||||||
type Ulimits struct {
|
|
||||||
Elements []Ulimit
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalYAML implements the Marshaller interface.
|
|
||||||
func (u Ulimits) MarshalYAML() (interface{}, error) {
|
|
||||||
ulimitMap := make(map[string]Ulimit)
|
|
||||||
for _, ulimit := range u.Elements {
|
|
||||||
ulimitMap[ulimit.Name] = ulimit
|
|
||||||
}
|
|
||||||
return ulimitMap, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalYAML implements the Unmarshaler interface.
|
|
||||||
func (u *Ulimits) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
||||||
ulimits := make(map[string]Ulimit)
|
|
||||||
|
|
||||||
var mapType map[interface{}]interface{}
|
|
||||||
if err := unmarshal(&mapType); err == nil {
|
|
||||||
for mapKey, mapValue := range mapType {
|
|
||||||
name, ok := mapKey.(string)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name)
|
|
||||||
}
|
|
||||||
var soft, hard int64
|
|
||||||
switch mv := mapValue.(type) {
|
|
||||||
case int:
|
|
||||||
soft = int64(mv)
|
|
||||||
hard = int64(mv)
|
|
||||||
case map[string]interface{}:
|
|
||||||
if len(mv) != 2 {
|
|
||||||
return fmt.Errorf("Failed to unmarshal Ulimit: %#v", mapValue)
|
|
||||||
}
|
|
||||||
for mkey, mvalue := range mv {
|
|
||||||
switch mkey {
|
|
||||||
case "soft":
|
|
||||||
soft = int64(mvalue.(int))
|
|
||||||
case "hard":
|
|
||||||
hard = int64(mvalue.(int))
|
|
||||||
default:
|
|
||||||
// FIXME(vdemeester) Should we ignore or fail ?
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("Failed to unmarshal Ulimit: %v, %T", mapValue, mapValue)
|
|
||||||
}
|
|
||||||
ulimits[name] = Ulimit{
|
|
||||||
Name: name,
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: soft,
|
|
||||||
Hard: hard,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keys := make([]string, 0, len(ulimits))
|
|
||||||
for key := range ulimits {
|
|
||||||
keys = append(keys, key)
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
for _, key := range keys {
|
|
||||||
u.Elements = append(u.Elements, ulimits[key])
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.New("Failed to unmarshal Ulimit")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ulimit represents ulimit information.
|
|
||||||
type Ulimit struct {
|
|
||||||
ulimitValues
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ulimitValues struct {
|
|
||||||
Soft int64 `yaml:"soft"`
|
|
||||||
Hard int64 `yaml:"hard"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalYAML implements the Marshaller interface.
|
|
||||||
func (u Ulimit) MarshalYAML() (interface{}, error) {
|
|
||||||
if u.Soft == u.Hard {
|
|
||||||
return u.Soft, nil
|
|
||||||
}
|
|
||||||
return u.ulimitValues, nil
|
|
||||||
}
|
|
|
@ -1,126 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMarshalUlimit(t *testing.T) {
|
|
||||||
ulimits := []struct {
|
|
||||||
ulimits *Ulimits
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
ulimits: &Ulimits{
|
|
||||||
Elements: []Ulimit{
|
|
||||||
{
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: 65535,
|
|
||||||
Hard: 65535,
|
|
||||||
},
|
|
||||||
Name: "nstep",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: `nstep: 65535
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ulimits: &Ulimits{
|
|
||||||
Elements: []Ulimit{
|
|
||||||
{
|
|
||||||
Name: "nofile",
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: 20000,
|
|
||||||
Hard: 40000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: `nofile:
|
|
||||||
soft: 20000
|
|
||||||
hard: 40000
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ulimit := range ulimits {
|
|
||||||
bytes, err := yaml.Marshal(ulimit.ulimits)
|
|
||||||
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.Equal(t, ulimit.expected, string(bytes), "should be equal")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUnmarshalUlimits(t *testing.T) {
|
|
||||||
ulimits := []struct {
|
|
||||||
yaml string
|
|
||||||
expected *Ulimits
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
yaml: "nstep: 65535",
|
|
||||||
expected: &Ulimits{
|
|
||||||
Elements: []Ulimit{
|
|
||||||
{
|
|
||||||
Name: "nstep",
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: 65535,
|
|
||||||
Hard: 65535,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
yaml: `nofile:
|
|
||||||
soft: 20000
|
|
||||||
hard: 40000`,
|
|
||||||
expected: &Ulimits{
|
|
||||||
Elements: []Ulimit{
|
|
||||||
{
|
|
||||||
Name: "nofile",
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: 20000,
|
|
||||||
Hard: 40000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
yaml: `nstep: 65535
|
|
||||||
nofile:
|
|
||||||
soft: 20000
|
|
||||||
hard: 40000`,
|
|
||||||
expected: &Ulimits{
|
|
||||||
Elements: []Ulimit{
|
|
||||||
{
|
|
||||||
Name: "nofile",
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: 20000,
|
|
||||||
Hard: 40000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "nstep",
|
|
||||||
ulimitValues: ulimitValues{
|
|
||||||
Soft: 65535,
|
|
||||||
Hard: 65535,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ulimit := range ulimits {
|
|
||||||
actual := &Ulimits{}
|
|
||||||
err := yaml.Unmarshal([]byte(ulimit.yaml), actual)
|
|
||||||
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.Equal(t, ulimit.expected, actual, "should be equal")
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue