Skip to content

Commit

Permalink
Don't set a default PATH for Windows
Browse files Browse the repository at this point in the history
Commit ecf070a updated DefaultPathEnv to return
platform specific values, but also defined a default PATH for Windows.

However, Windows does not have a default PATH, and the PATH to use must be set
by the container image. Also see moby/moby@3c177dc,
which removed the default PATH on Windows;

> This is deliberately empty on Windows as the default path will be set by
> the container. Docker has no context of what the default path should be.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 9, 2022
1 parent f394afc commit b20c277
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion exporter/containerimage/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ func defaultImageConfig() ([]byte, error) {
}
img.RootFS.Type = "layers"
img.Config.WorkingDir = "/"
img.Config.Env = []string{"PATH=" + system.DefaultPathEnv(pl.OS)}
if env := system.DefaultPathEnv(pl.OS); env != "" {
img.Config.Env = []string{"PATH=" + env}
}
dt, err := json.Marshal(img)
return dt, errors.Wrap(err, "failed to create empty image config")
}
Expand Down
8 changes: 5 additions & 3 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,13 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS

// make sure that PATH is always set
if _, ok := shell.BuildEnvs(d.image.Config.Env)["PATH"]; !ok {
var os string
var pOS string
if d.platform != nil {
os = d.platform.OS
pOS = d.platform.OS
}
if env := system.DefaultPathEnv(pOS); env != "" {
d.image.Config.Env = append(d.image.Config.Env, "PATH="+env)
}
d.image.Config.Env = append(d.image.Config.Env, "PATH="+system.DefaultPathEnv(os))
}

// initialize base metadata from image conf
Expand Down
4 changes: 3 additions & 1 deletion frontend/dockerfile/dockerfile2llb/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func emptyImage(platform ocispecs.Platform) Image {
}
img.RootFS.Type = "layers"
img.Config.WorkingDir = "/"
img.Config.Env = []string{"PATH=" + system.DefaultPathEnv(platform.OS)}
if env := system.DefaultPathEnv(platform.OS); env != "" {
img.Config.Env = []string{"PATH=" + env}
}
return img
}
4 changes: 3 additions & 1 deletion frontend/gateway/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ func (gwCtr *gatewayContainer) Start(ctx context.Context, req client.StartReques
if procInfo.Meta.Cwd == "" {
procInfo.Meta.Cwd = "/"
}
procInfo.Meta.Env = addDefaultEnvvar(procInfo.Meta.Env, "PATH", utilsystem.DefaultPathEnv(gwCtr.platform.OS))
if env := utilsystem.DefaultPathEnv(gwCtr.platform.OS); env != "" {
procInfo.Meta.Env = addDefaultEnvvar(procInfo.Meta.Env, "PATH", env)
}
if req.Tty {
procInfo.Meta.Env = addDefaultEnvvar(procInfo.Meta.Env, "TERM", "xterm")
}
Expand Down
4 changes: 3 additions & 1 deletion solver/llbsolver/ops/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ func (e *execOp) Exec(ctx context.Context, g session.Group, inputs []solver.Resu
if e.platform != nil {
currentOS = e.platform.OS
}
meta.Env = addDefaultEnvvar(meta.Env, "PATH", utilsystem.DefaultPathEnv(currentOS))
if env := utilsystem.DefaultPathEnv(currentOS); env != "" {
meta.Env = addDefaultEnvvar(meta.Env, "PATH", env)
}

secretEnv, err := e.loadSecretEnv(ctx, g)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions util/system/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package system
// ':' character .
const DefaultPathEnvUnix = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

// DefaultPathEnvWindows is windows style list of directories to search for
// executables. Each directory is separated from the next by a colon
// ';' character .
const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows"
// DefaultPathEnvWindows is deliberately empty on Windows and the default path
// must be set by the image. BuildKit has no context of what the default
// path should be.
const DefaultPathEnvWindows = ""

func DefaultPathEnv(os string) string {
if os == "windows" {
Expand Down

0 comments on commit b20c277

Please sign in to comment.