mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-16 19:35:14 +00:00
parent
c64340cf8f
commit
12df59d0ec
2 changed files with 39 additions and 5 deletions
|
@ -17,6 +17,7 @@ package docker
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"maps"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -29,24 +30,29 @@ import (
|
||||||
// returns a container configuration.
|
// returns a container configuration.
|
||||||
func (e *docker) toConfig(step *types.Step) *container.Config {
|
func (e *docker) toConfig(step *types.Step) *container.Config {
|
||||||
config := &container.Config{
|
config := &container.Config{
|
||||||
Image: step.Image,
|
Image: step.Image,
|
||||||
Labels: map[string]string{"wp_uuid": step.UUID},
|
Labels: map[string]string{
|
||||||
|
"wp_uuid": step.UUID,
|
||||||
|
"wp_step": step.Name,
|
||||||
|
},
|
||||||
WorkingDir: step.WorkingDir,
|
WorkingDir: step.WorkingDir,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
}
|
}
|
||||||
|
env := make(map[string]string)
|
||||||
|
maps.Copy(env, step.Environment)
|
||||||
|
|
||||||
if len(step.Commands) != 0 {
|
if len(step.Commands) != 0 {
|
||||||
env, entry, cmd := common.GenerateContainerConf(step.Commands, e.info.OSType)
|
env, entry, cmd := common.GenerateContainerConf(step.Commands, e.info.OSType)
|
||||||
for k, v := range env {
|
for k, v := range env {
|
||||||
step.Environment[k] = v
|
env[k] = v
|
||||||
}
|
}
|
||||||
config.Entrypoint = entry
|
config.Entrypoint = entry
|
||||||
config.Cmd = cmd
|
config.Cmd = cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(step.Environment) != 0 {
|
if len(env) != 0 {
|
||||||
config.Env = toEnv(step.Environment)
|
config.Env = toEnv(env)
|
||||||
}
|
}
|
||||||
if len(step.Volumes) != 0 {
|
if len(step.Volumes) != 0 {
|
||||||
config.Volumes = toVol(step.Volumes)
|
config.Volumes = toVol(step.Volumes)
|
||||||
|
|
|
@ -17,6 +17,12 @@ package docker
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
backend "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSplitVolumeParts(t *testing.T) {
|
func TestSplitVolumeParts(t *testing.T) {
|
||||||
|
@ -85,3 +91,25 @@ func TestSplitVolumeParts(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToConfigSmall(t *testing.T) {
|
||||||
|
engine := docker{info: types.Info{OSType: "linux/riscv64"}}
|
||||||
|
|
||||||
|
conf := engine.toConfig(&backend.Step{
|
||||||
|
Name: "test",
|
||||||
|
UUID: "09238932",
|
||||||
|
Commands: []string{"go test"},
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.NotNil(t, conf)
|
||||||
|
assert.EqualValues(t, &container.Config{
|
||||||
|
AttachStdout: true,
|
||||||
|
AttachStderr: true,
|
||||||
|
Cmd: []string{"echo $CI_SCRIPT | base64 -d | /bin/sh -e"},
|
||||||
|
Entrypoint: []string{"/bin/sh", "-c"},
|
||||||
|
Labels: map[string]string{
|
||||||
|
"wp_step": "test",
|
||||||
|
"wp_uuid": "09238932",
|
||||||
|
},
|
||||||
|
}, conf)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue