From 966cd034992917087338485a0892d25c9e08cd2e Mon Sep 17 00:00:00 2001 From: aca Date: Sat, 4 Jul 2020 01:14:35 +0900 Subject: [PATCH 1/5] Set correct PATH for exec form Fixes #1304 --- pkg/commands/run.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index b99461eaa..23d7ee24f 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -63,6 +63,21 @@ func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun newCommand = append(shell, strings.Join(cmdRun.CmdLine, " ")) } else { newCommand = cmdRun.CmdLine + // Find and set absolute path of executable by setting PATH temporary + replacementEnvs := buildArgs.ReplacementEnvs(config.Env) + for _, v := range replacementEnvs{ + entry := strings.SplitN(v, "=", 2) + if entry[0] != "PATH" { + continue + } + oldPath := os.Getenv("PATH") + os.Setenv("PATH", entry[1]) + path, err := exec.LookPath(newCommand[0]) + if err == nil { + newCommand[0] = path + } + os.Setenv("PATH", oldPath) + } } logrus.Infof("cmd: %s", newCommand[0]) From dd4191ad3d8bf2797368f2dc3ad179f8bdd788ce Mon Sep 17 00:00:00 2001 From: aca Date: Sat, 4 Jul 2020 03:46:41 +0900 Subject: [PATCH 2/5] gofmt --- pkg/commands/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 23d7ee24f..f010ceddd 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -65,7 +65,7 @@ func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun newCommand = cmdRun.CmdLine // Find and set absolute path of executable by setting PATH temporary replacementEnvs := buildArgs.ReplacementEnvs(config.Env) - for _, v := range replacementEnvs{ + for _, v := range replacementEnvs { entry := strings.SplitN(v, "=", 2) if entry[0] != "PATH" { continue From 8f1528764fcb7c5fcd795b1cb3f6ab22fe33f5d3 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Thu, 13 Aug 2020 10:47:35 -0700 Subject: [PATCH 3/5] add defer. --- pkg/commands/run.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index f010ceddd..28dec9fa3 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -71,12 +71,13 @@ func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun continue } oldPath := os.Getenv("PATH") + defer os.Setenv("PATH", oldPath) os.Setenv("PATH", entry[1]) path, err := exec.LookPath(newCommand[0]) if err == nil { newCommand[0] = path } - os.Setenv("PATH", oldPath) + } } From 472376307e80ddab7c3459899c5a0a4283674072 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Thu, 13 Aug 2020 13:17:42 -0700 Subject: [PATCH 4/5] Update run.go --- pkg/commands/run.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 28dec9fa3..03b4e69c3 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -76,8 +76,7 @@ func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun path, err := exec.LookPath(newCommand[0]) if err == nil { newCommand[0] = path - } - + } } } From abcc16b4ccee2f22acc2ea867cfa81fcd6abf9eb Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Thu, 13 Aug 2020 13:59:58 -0700 Subject: [PATCH 5/5] fix gofmt --- pkg/commands/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 03b4e69c3..27b05ed45 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -76,7 +76,7 @@ func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun path, err := exec.LookPath(newCommand[0]) if err == nil { newCommand[0] = path - } + } } }