mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-09-26 13:40:06 +00:00
Rework entrypoints
This commit is contained in:
parent
f1956b209d
commit
0b3c3a4299
3 changed files with 6 additions and 10 deletions
|
@ -18,21 +18,19 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateContainerConf(commands []string, goos string) (env map[string]string, entry []string, cmd string) {
|
func GenerateContainerConf(commands []string, goos string) (env map[string]string, entry []string) {
|
||||||
env = make(map[string]string)
|
env = make(map[string]string)
|
||||||
if goos == "windows" {
|
if goos == "windows" {
|
||||||
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptWindows(commands)))
|
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptWindows(commands)))
|
||||||
env["HOME"] = "c:\\root"
|
env["HOME"] = "c:\\root"
|
||||||
env["SHELL"] = "powershell.exe"
|
env["SHELL"] = "powershell.exe"
|
||||||
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
|
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command", "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"}
|
||||||
cmd = "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"
|
|
||||||
} else {
|
} else {
|
||||||
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptPosix(commands)))
|
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptPosix(commands)))
|
||||||
env["HOME"] = "/root"
|
env["HOME"] = "/root"
|
||||||
env["SHELL"] = "/bin/sh"
|
env["SHELL"] = "/bin/sh"
|
||||||
entry = []string{"/bin/sh", "-c"}
|
entry = []string{"/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"}
|
||||||
cmd = "echo $CI_SCRIPT | base64 -d | /bin/sh -e"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, entry, cmd
|
return env, entry
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (e *docker) toConfig(step *types.Step) *container.Config {
|
||||||
maps.Copy(configEnv, step.Environment)
|
maps.Copy(configEnv, step.Environment)
|
||||||
|
|
||||||
if len(step.Commands) != 0 {
|
if len(step.Commands) != 0 {
|
||||||
env, entry, cmd := common.GenerateContainerConf(step.Commands, e.info.OSType)
|
env, entry := common.GenerateContainerConf(step.Commands, e.info.OSType)
|
||||||
for k, v := range env {
|
for k, v := range env {
|
||||||
configEnv[k] = v
|
configEnv[k] = v
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ func (e *docker) toConfig(step *types.Step) *container.Config {
|
||||||
entry = step.Entrypoint
|
entry = step.Entrypoint
|
||||||
}
|
}
|
||||||
config.Entrypoint = entry
|
config.Entrypoint = entry
|
||||||
config.Cmd = []string{cmd}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(configEnv) != 0 {
|
if len(configEnv) != 0 {
|
||||||
|
|
|
@ -145,12 +145,11 @@ func podContainer(step *types.Step, podName, goos string, options BackendOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(step.Commands) != 0 {
|
if len(step.Commands) != 0 {
|
||||||
scriptEnv, command, args := common.GenerateContainerConf(step.Commands, goos)
|
scriptEnv, command := common.GenerateContainerConf(step.Commands, goos)
|
||||||
if len(step.Entrypoint) > 0 {
|
if len(step.Entrypoint) > 0 {
|
||||||
command = step.Entrypoint
|
command = step.Entrypoint
|
||||||
}
|
}
|
||||||
container.Command = command
|
container.Command = command
|
||||||
container.Args = []string{args}
|
|
||||||
maps.Copy(step.Environment, scriptEnv)
|
maps.Copy(step.Environment, scriptEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue