Skip to content

Commit

Permalink
Rework entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Mar 24, 2024
1 parent f1956b2 commit 0b3c3a4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
10 changes: 4 additions & 6 deletions pipeline/backend/common/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions pipeline/backend/docker/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ 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
}
if len(step.Entrypoint) > 0 {
entry = step.Entrypoint
}
config.Entrypoint = entry
config.Cmd = []string{cmd}
}

if len(configEnv) != 0 {
Expand Down
3 changes: 1 addition & 2 deletions pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 0b3c3a4

Please sign in to comment.