use workspace struct

This commit is contained in:
pat-s 2024-04-20 10:55:43 +02:00
parent b9fc030ca5
commit 0230ea3bdd
No known key found for this signature in database
GPG key ID: 3C6318841EF78925
6 changed files with 23 additions and 6 deletions

View file

@ -19,6 +19,7 @@ import (
"encoding/json"
"maps"
"regexp"
"strconv"
"strings"
"github.com/docker/docker/api/types/container"
@ -107,10 +108,10 @@ func toHostConfig(step *types.Step) *container.HostConfig {
config.Devices = toDev(step.Devices)
}
if !step.UseTmpfs {
if step.Workspace.Tmpfs.Size != 0 {
config.Binds = step.Volumes
} else {
config.Tmpfs = map[string]string{"/woodpecker": ""}
config.Tmpfs = map[string]string{step.Workspace.Tmpfs.Path: "size=" + strconv.Itoa(step.Workspace.Tmpfs.Size)}
}
return config

View file

@ -154,7 +154,7 @@ func TestToConfigFull(t *testing.T) {
AuthConfig: backend.Auth{Username: "user", Password: "123456"},
NetworkMode: "bridge",
Ports: []backend.Port{{Number: 21}, {Number: 22}},
UseTmpfs: true,
UseTmpfs: true,
})
assert.NotNil(t, conf)

View file

@ -47,7 +47,12 @@ type Step struct {
NetworkMode string `json:"network_mode,omitempty"`
Ports []Port `json:"ports,omitempty"`
BackendOptions map[string]any `json:"backend_options,omitempty"`
UseTmpfs bool `json:"use_tmpfs,omitempty"`
Workspace struct {
Tmpfs struct {
Size int
Path string
}
}
}
// StepType identifies the type of step

View file

@ -0,0 +1,11 @@
package types
// BackendOptions defines all the advanced options for the kubernetes backend
type Workspace struct {
Tmpfs []Tmpfs `json:"Tmpfs"`
}
type Tmpfs struct {
Path string `json:"path,omitempty"`
Size int `json:"size,omitempty"`
}

View file

@ -215,7 +215,7 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
NetworkMode: networkMode,
Ports: ports,
BackendOptions: container.BackendOptions,
UseTmpfs: container.UseTmpfs,
Workspace: container.Workspace,
}, nil
}

View file

@ -71,7 +71,7 @@ type (
Networks Networks `yaml:"networks,omitempty"`
ShmSize base.MemStringOrInt `yaml:"shm_size,omitempty"`
Tmpfs []string `yaml:"tmpfs,omitempty"`
UseTmpfs bool `yaml:"use_tmpfs,omitempty"`
Workspace []Workspace `yaml:"workspace"`
}
)