Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Removed the default set PATH for Windows environments. #4895

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions frontend/dockerfile/dockerfile_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//go:build windows
// +build windows

package dockerfile

import (
"os"
"path/filepath"
"testing"

"github.com/containerd/continuity/fs/fstest"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/frontend/dockerui"
"github.com/moby/buildkit/util/testutil/integration"
"github.com/stretchr/testify/require"
"github.com/tonistiigi/fsutil"
)

var windowsTests = integration.TestFuncs(
testSetPath,
)

func init() {
allTests = append(allTests, windowsTests...)
}

func testSetPath(t *testing.T, sb integration.Sandbox) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW this needs to only run on Windows.

f := getFrontend(t, sb)

dockerfile := []byte(`
FROM nanoserver
RUN setx PATH "C:\NewPath1;C:\NewPath2;%PATH%"
RUN echo %PATH% > path.txt
`)
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

destDir := t.TempDir()
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
Exports: []client.ExportEntry{
{
Type: client.ExporterLocal,
OutputDir: destDir,
},
},
LocalMounts: map[string]fsutil.FS{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
},
}, nil)
require.NoError(t, err)

dt, err := os.ReadFile(filepath.Join(destDir, "path.txt"))
require.NoError(t, err)

envStr := string(dt)
require.Contains(t, envStr, "C:\\NewPath1;C:\\NewPath2")
}
6 changes: 2 additions & 4 deletions util/system/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
// ':' 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 empty to allow windows to set the PATH when it runs
const DefaultPathEnvWindows = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: so this ensures backward compatibility with classic docker build, but on the downside, you can't do something like this:

ENV PATH "$PATH;C:\\add\\my\\path"

You end up with PATH=;C:\\add\\my\\path, and the one coming from the registry is now ignored. We therefore end up with some inconsistencies.


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