Rework entrypoints

This commit is contained in:
qwerty287 2024-03-24 15:33:53 +01:00
parent f1956b209d
commit 0b3c3a4299
No known key found for this signature in database
GPG key ID: 1218A32A886A5002
3 changed files with 6 additions and 10 deletions

View file

@ -18,21 +18,19 @@ import (
"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)
if goos == "windows" {
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptWindows(commands)))
env["HOME"] = "c:\\root"
env["SHELL"] = "powershell.exe"
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
cmd = "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command", "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"}
} else {
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptPosix(commands)))
env["HOME"] = "/root"
env["SHELL"] = "/bin/sh"
entry = []string{"/bin/sh", "-c"}
cmd = "echo $CI_SCRIPT | base64 -d | /bin/sh -e"
entry = []string{"/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"}
}
return env, entry, cmd
return env, entry
}

View file

@ -46,7 +46,7 @@ func (e *docker) toConfig(step *types.Step) *container.Config {
maps.Copy(configEnv, step.Environment)
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 {
configEnv[k] = v
}
@ -54,7 +54,6 @@ func (e *docker) toConfig(step *types.Step) *container.Config {
entry = step.Entrypoint
}
config.Entrypoint = entry
config.Cmd = []string{cmd}
}
if len(configEnv) != 0 {

View file

@ -145,12 +145,11 @@ func podContainer(step *types.Step, podName, goos string, options BackendOptions
}
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 {
command = step.Entrypoint
}
container.Command = command
container.Args = []string{args}
maps.Copy(step.Environment, scriptEnv)
}