Skip to content

Commit 88f1541

Browse files
authored
fix(v1): keep the PATH from the base image (#1673)
Signed-off-by: Keming <kemingyang@tensorchord.ai>
1 parent 7379401 commit 88f1541

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

pkg/lang/ir/v1/compile.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewGraph() ir.Graph {
3939
runtimeGraph := ir.RuntimeGraph{
4040
RuntimeCommands: make(map[string]string),
4141
RuntimeEnviron: make(map[string]string),
42-
RuntimeEnvPaths: []string{types.DefaultSystemPath},
42+
RuntimeEnvPaths: strings.Split(types.DefaultSystemPath, ":"),
4343
}
4444
return &generalGraph{
4545
uid: -1,
@@ -261,6 +261,9 @@ func (g generalGraph) ExposedPorts() (map[string]struct{}, error) {
261261
func (g generalGraph) EnvString() []string {
262262
var envs []string
263263
for k, v := range g.RuntimeEnviron {
264+
if k == "PATH" {
265+
continue
266+
}
264267
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
265268
}
266269
envs = append(envs, fmt.Sprintf("PATH=%s", strings.Join(g.RuntimeEnvPaths, ":")))

pkg/lang/ir/v1/system.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,25 @@ func (g *generalGraph) compileBaseImage() (llb.State, error) {
347347
// in case the env value also contains `=`
348348
kv := strings.SplitN(e, "=", 2)
349349
g.RuntimeEnviron[kv[0]] = kv[1]
350+
if kv[0] == "PATH" {
351+
// deduplicate the PATH but keep the order as:
352+
// 0. default Unix PATH
353+
// 1. configured paths in the Starlark frontend `runtime.environ(extra_path=[...])`
354+
// 2. paths in the base image
355+
// 3. others added during the image building (Python paths, etc.)
356+
extraPaths := make(map[string]bool)
357+
for _, path := range strings.Split(kv[1], ":") {
358+
extraPaths[path] = true
359+
}
360+
for _, path := range g.RuntimeEnvPaths {
361+
extraPaths[path] = false
362+
}
363+
for path, required := range extraPaths {
364+
if required {
365+
g.RuntimeEnvPaths = append(g.RuntimeEnvPaths, path)
366+
}
367+
}
368+
}
350369
}
351370

352371
// add necessary envs

0 commit comments

Comments
 (0)