diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index d8aed914b3a6..d51ea970407d 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -208,6 +208,7 @@ var allTests = integration.TestFuncs( testEmptyStages, testLocalCustomSessionID, testTargetStageNameArg, + testPowershellInDefaultPathOnWindows, ) // Tests that depend on the `security.*` entitlements @@ -1782,7 +1783,7 @@ COPY Dockerfile . entrypoint []string env []string }{ - {p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows"}}, + {p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows;C:\\Windows\\System32\\WindowsPowerShell\\v1.0"}}, {p: "linux/amd64", entrypoint: []string{"/bin/sh", "-c", "foo bar"}, env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}}, } { t.Run(exp.p, func(t *testing.T) { @@ -1919,6 +1920,49 @@ COPY --from=base /out/ / require.Equal(t, "value:final", string(dt)) } +func testPowershellInDefaultPathOnWindows(t *testing.T, sb integration.Sandbox) { + integration.SkipOnPlatform(t, "!windows") + + f := getFrontend(t, sb) + + // just testing that the powershell path is in PATH + // but not testing powershell itself since it will need + // servercore image that is too bulky for just one single test. + dockerfile := []byte(` +FROM nanoserver +USER ContainerAdministrator +RUN echo %PATH% > env_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, "env_path.txt")) + require.NoError(t, err) + + envPath := string(dt) + require.Contains(t, envPath, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0") +} + func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) { integration.SkipOnPlatform(t, "windows") workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter, workers.FeatureMultiPlatform) diff --git a/util/system/path.go b/util/system/path.go index cdfff68007f5..14f02b495c50 100644 --- a/util/system/path.go +++ b/util/system/path.go @@ -16,7 +16,7 @@ const DefaultPathEnvUnix = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s // 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" +const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows;C:\\Windows\\System32\\WindowsPowerShell\\v1.0" func DefaultPathEnv(os string) string { if os == "windows" {