File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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) {
261261func (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 , ":" )))
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments