From 7b1de15d12c643f6cafca251e983ff0111eec554 Mon Sep 17 00:00:00 2001 From: Daniel Githinji Date: Thu, 2 May 2024 08:28:16 +0300 Subject: [PATCH 1/3] Removed the default set PATH for Windows environments to allow Windows images to set the PATH while running Signed-off-by: Daniel Githinji --- util/system/path.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/util/system/path.go b/util/system/path.go index 422651ecea5ce..be6d9db0e9b5b 100644 --- a/util/system/path.go +++ b/util/system/path.go @@ -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 = "" func DefaultPathEnv(os string) string { if os == "windows" { From 018a0de2cfe56c279fca3cbc97b34ddbc5796dda Mon Sep 17 00:00:00 2001 From: Daniel Githinji Date: Thu, 2 May 2024 08:28:16 +0300 Subject: [PATCH 2/3] Removed the default set PATH for Windows environments to allow Windows images to set the PATH while running Signed-off-by: Daniel Githinji --- util/system/path.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/util/system/path.go b/util/system/path.go index cdfff68007f5f..47160034c47ce 100644 --- a/util/system/path.go +++ b/util/system/path.go @@ -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 = "" func DefaultPathEnv(os string) string { if os == "windows" { From fc562426c7082ffff7a336d99a5b1e51ccf4c073 Mon Sep 17 00:00:00 2001 From: Daniel Githinji Date: Thu, 15 Aug 2024 00:10:04 +0300 Subject: [PATCH 3/3] Added a 'testSetPath' test in dockerfile_windows_test.go. The test checks whether the path in a Windows container image can be set or not. --- .../dockerfile/dockerfile_windows_test.go | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 frontend/dockerfile/dockerfile_windows_test.go diff --git a/frontend/dockerfile/dockerfile_windows_test.go b/frontend/dockerfile/dockerfile_windows_test.go new file mode 100644 index 0000000000000..f8d19bc4ab0de --- /dev/null +++ b/frontend/dockerfile/dockerfile_windows_test.go @@ -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) { + 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") +}