fix workspace type

This commit is contained in:
pat-s 2024-04-20 11:36:21 +02:00
parent 0230ea3bdd
commit 09d9853911
No known key found for this signature in database
GPG key ID: 3C6318841EF78925
5 changed files with 10 additions and 13 deletions

View file

@ -108,10 +108,10 @@ func toHostConfig(step *types.Step) *container.HostConfig {
config.Devices = toDev(step.Devices)
}
if step.Workspace.Tmpfs.Size != 0 {
config.Binds = step.Volumes
if len(step.Workspace) != 0 {
config.Tmpfs = map[string]string{step.Workspace[0].Tmpfs[0].Path: "size=" + strconv.Itoa(step.Workspace[0].Tmpfs[0].Size)}
} else {
config.Tmpfs = map[string]string{step.Workspace.Tmpfs.Path: "size=" + strconv.Itoa(step.Workspace.Tmpfs.Size)}
config.Binds = step.Volumes
}
return config

View file

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

View file

@ -213,7 +213,7 @@ func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID str
}
// add default volumes to the host configuration
if step.UseTmpfs {
if step.Workspace.Tmpfs.Size != 0 {
hostConfig.Binds = e.volumes
} else {
hostConfig.Binds = utils.DeduplicateStrings(append(hostConfig.Binds, e.volumes...))

View file

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

View file

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