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

[Swift] Add support for Windows Docker image #15071

Merged
merged 2 commits into from
Nov 9, 2023

Conversation

shahmishal
Copy link
Contributor

No description provided.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@shahmishal
Copy link
Contributor Author

Run set -- 'swift:5.8.1-windowsservercore-ltsc2022'
  set -- 'swift:5.8.1-windowsservercore-ltsc2022'
  if [ -s ./.test/config.sh ]; then set -- --config ~/oi/test/config.sh --config ./.test/config.sh "$@"; fi
  ./test/run.sh "$@"
  shell: C:\Program Files\Git\bin\bash.EXE -Eeuo pipefail -x {0}
  env:
    GIT_LFS_SKIP_SMUDGE: 1
    MSYS: winsymlinks:nativestrict
    BASHBREW_VERSION: v0.1.8
    BASHBREW_SCRIPTS: D:\a\_actions\docker-library\bashbrew\v0.1.8/scripts
    BASHBREW_BUILDKIT_SYNTAX: docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a38360f4d6a7782a409b14
+ set -- swift:5.8.1-windowsservercore-ltsc2022
+ '[' -s ./.test/config.sh ']'
+ ./test/run.sh swift:5.8.1-windowsservercore-ltsc2022
testing swift:5.8.1-windowsservercore-ltsc2022
	'override-cmd' [1/2]...passed
<unknown>:0: error: could not load the swift standard library
	'swift-hello-world' [2/2]...failed
Error: Process completed with exit code 1.

cc: @compnerd

@tianon
Copy link
Member

tianon commented Jul 24, 2023

This feels familiar 👀 (#13093)

@compnerd
Copy link

@shahmishal where is that script? I suspect that we should change that to run docker run -it ... for Windows. Thanks @tianon for the pointer to the older PR :)

@grooverdan
Copy link
Contributor

@compnerd
Copy link

@grooverdan, @tianon thanks! I did poke a bit more at this - the problem is that this is running under MinGW (bash) and that is not supported. That tends to break pretty often and is not supported. Can we run this as a PowerShell script somehow?

@yosifkit
Copy link
Member

I have a fix for the test to make it work on windows. The solution is to just use swiftc and then run the result. I am happy to add the commit to this branch but figured I'd get review done first. The change in testing would also apply to the non-windows versions so it is OS agnostic. Here is what I came up with:

Diff:
--- a/test/tests/run-swift-in-container.sh
+++ b/test/tests/run-swift-in-container.sh
@@ -4,4 +4,15 @@ set -e
 testDir="$(readlink -f "$(dirname "$BASH_SOURCE")")"
 runDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

-source "$runDir/run-in-container.sh" "$testDir" "$1" swift ./container.swift
+image="$1"
+
+testName="$(basename "$testDir")"
+newImage="$("$runDir/image-name.sh" "librarytest/$testName" "$image")"
+"$runDir/docker-build.sh" "$testDir" "$newImage" <<EOD
+FROM $image
+COPY dir/container.swift /
+RUN swiftc /container.swift -o container
+CMD [ "/container" ]
+EOD
+
+docker run --rm "$newImage"

Dockerfile review:

The installers for vs_buildtools, git, swift and python should be verified in some way: https://github.com/docker-library/official-images/tree/15490443c295a651575af2e18a78003be2f1747c#image-build.

Python 3.10.* no longer receives updates to the binary builds, so this version is already out of date. I don't have a great solution other than updating to Python 3.11. Have you considered just using FROM python:3.11-windowsservercore-ltsc2022 instead?

I am also very intrigued by the size disparity between this python install layer and the one in the python images. The size here is 10x bigger. I did some investigations and even copied the python Dockerfile and it was still huge. I discovered that if python is installed before vs_buildtools, then it is the expected ~90MB instead of 990MB. I also noticed the swift layer gets smaller also, but then the VS layer gains almost as much as the swift layer saved.

More space can be saved by cleaning up the $TEMP directory in each RUN layer. I also recommend adding something like the python image so that any installer errors can print a log on failure to help debug later issues.

@compnerd
Copy link

Unfortunately, the python version is pinned and we cannot update that easily :-( (the lldb instance relies on the python matching since python has no stable ABI). I didn't know about the python base image, if that shaves size, I'm happy to swap to it.

@yosifkit
Copy link
Member

Unfortunately, the python version is pinned and we cannot update that easily :-( (the lldb instance relies on the python matching since python has no stable ABI). I didn't know about the python base image, if that shaves size, I'm happy to swap to it.

Well, since you need a specific, pinned version python, then the images we maintain won't help since we don't maintain old releases (and 3.10 doesn't have binary releases for windows anymore, so that combination is dropped altogether). I would suggest changing the order of installation to get some space saving though. Installing vs_buildtools last should save about 900MB.

@compnerd
Copy link

compnerd commented Aug 30, 2023

That is slightly ludicrous. Is there an explanation for why? I'm not against it, just completely flabbergasted at the results. It absolutely is worth the effort to do (unfortunately for older releases of Swift, like 5.8.x, this would not be possible since there is a dependency on install ordering).

@compnerd
Copy link

compnerd commented Sep 1, 2023

@yosifkit - that diff looks reasonable to me, do you need anything from our side?

@compnerd
Copy link

@tianon @yosifkit @grooverdan - anything that I can do to help push this along?

@yosifkit
Copy link
Member

Apologies for the delay. The Dockerfiles need a few updates.

The installers for vs_buildtools, git, swift and python should be verified in some way (at least a sha256sum embedded in the Dockerfile): https://github.com/docker-library/official-images/tree/15490443c295a651575af2e18a78003be2f1747c#image-build.

To get the size saving, I'd suggest installing python before vs_buildtools. It seems to be coming from ProgramData/Package Cache when doing a diff of files between the two layers that install python.

The $TEMP directory should be cleaned out in each RUN layer. I also recommend adding something like the python image so that any installer errors can print a log on failure to help debug later issues.

For cacheability optimization we suggest putting all ARG/ENV lines just before the RUN in which they are used to maximize build cache if only a later item changed. For example, if swift is last and the only item is a swift version bump, then only the last layers need to build.


This last part has me very confused. If I use the same python install arguments you have, but running it via powershell (same as the python image), it exits with a failure and so fails to install. I could only solve it by removing the Include_launcher=0 argument. So, I am a little hesitant to trust the start /w of these installations from CMD, since it didn't capture this python installation failure (this is unrelated to the size issue as I was using powershell in both cases).

@compnerd
Copy link

@yosifkit do you have examples for Windows that do that with sha?

@LaurentGoderre
Copy link
Member

@compnerd
Copy link

Thank you! I ended up with something similar (and tweaking the order as well for the space savings).

@compnerd
Copy link

@LaurentGoderre @yosifkit - seems that we cannot really do the hash checking on the VS installer as the bootstrapper seems to change.

@LaurentGoderre
Copy link
Member

@compnerd isn't a CI creating the final installer? Would it change from that?

@compnerd
Copy link

@LaurentGoderre no, the VS installer is a dependency that we are installing that is not under our control and only has a "latest" version.

@LaurentGoderre
Copy link
Member

@compnerd is it this step? https://github.com/apple/swift-docker

@compnerd
Copy link

@LaurentGoderre I think that I might have a version that works for now? Let me upload the version so I can indicate the step.

@compnerd
Copy link

@LaurentGoderre, @yosifkit:

  • added verification for the installers (sha256sum)
  • installing python before vs build tools
  • cleaning out $TEMP logs
  • moved the ARG to near site of use
  • migrated the rules to powershell

Tested on Windows 22H2 (22621.2428).

@shahmishal shahmishal force-pushed the support-windows-swift branch from 548a2c9 to 07d2f55 Compare October 24, 2023 00:22
@github-actions

This comment has been minimized.

@compnerd
Copy link

@LaurentGoderre - seems that the bootstrapper has changed between yesterday and today. What do you recommend as the best way to deal with this?

SHA256 yesterday: 96e08166034c5110cdb8361ba55f8a2010d0bad714b311a7c8f1c7c8f7c03bce
SHA256 today: d4e08524cb0e5bd061a24f507928d1cfb91dce192c5e12ed964b8343fc4cdedd

@compnerd
Copy link

compnerd commented Oct 26, 2023

@LaurentGoderre that is something on your side: #15071 (comment)

--- a/test/tests/run-swift-in-container.sh
+++ b/test/tests/run-swift-in-container.sh
@@ -4,4 +4,15 @@ set -e
 testDir="$(readlink -f "$(dirname "$BASH_SOURCE")")"
 runDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

-source "$runDir/run-in-container.sh" "$testDir" "$1" swift ./container.swift
+image="$1"
+
+testName="$(basename "$testDir")"
+newImage="$("$runDir/image-name.sh" "librarytest/$testName" "$image")"
+"$runDir/docker-build.sh" "$testDir" "$newImage" <<EOD
+FROM $image
+COPY dir/container.swift /
+RUN swiftc /container.swift -o container
+CMD [ "/container" ]
+EOD
+
+docker run --rm "$newImage"

@yosifkit had a patch for that.

@LaurentGoderre
Copy link
Member

@compnerd yep, talked to him about it

@compnerd
Copy link

@LaurentGoderre what's the best way forward for this? Do we want to just push that change into this PR, have a separate PR? Or will @yosifkit push that?

@yosifkit
Copy link
Member

I can add it as an extra commit to this PR once we're ready. I'm just working on reviewing it once again.

@yosifkit
Copy link
Member

I haven't really realized this before (and I think some of our own images might have this bug), but it looks like just running Start-Process is not enough to correctly fail a build if the started process fails (even with $ErrorActionPreference = 'Stop set). So, the recommendation is to implement a check of the exit code like the python windows images do, summarized and explained below:

# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process
$exitCode = (Start-Process executable-to-run -Wait -NoNewWindow -PassThru \
		-ArgumentList @( \
			'arg1', \
			'arg2', \
			'argn' \
		) \
	).ExitCode; \
	if ($exitCode -ne 0) { \
		Write-Host ('Message to print when the executable-to-run exited non-zero: {0}' -f $exitCode); \
# not required, but attempting to print some log files from TEMP can be helpful in debugging failing installs.
# this example might miss printing the correct log file if there are multiple with the same LastWrite time
		Get-ChildItem $env:TEMP | Sort-Object -Descending -Property LastWriteTime | Select-Object -First 1 | Get-Content; \
# be sure to fail the build so that a partially installed dependency doesn't get committed to a layer
		exit $exitCode; \
	} \

@compnerd
Copy link

Okay, redid some of the image setup; found that Microsoft has a pre-setup python image and I opted to use that and add the additional checking around the other installations.

@github-actions

This comment has been minimized.

@compnerd
Copy link

@yosifkit, the changes that you requested are now completed. The python installation ordering is important, and using the Microsoft provided python bundled image results in a smaller image overall (~13.2G vs ~14.8G).

@compnerd
Copy link

@yosifkit @tianon @LaurentGoderre - sorry to keep bugging you guys about this, but I really would like to get this PR resolved.

@yosifkit
Copy link
Member

From the failing "Naughty" test:

error: unknown Windows image: mcr.microsoft.com/windows-cssc/python:3.9-servercore-ltsc2022
Error: Process completed with exit code 1.

And then from the Official Images Readme:

No official images can be derived from, or depend on, non-official images (allowing the non-image scratch and the intentionally limited exceptions pinned in .external-pins -- see also .external-pins/list.sh).

Unfortunately, the mcr.microsoft.com/windows-cssc/python:* images are not part of the allowed exceptions.

@compnerd
Copy link

compnerd commented Nov 1, 2023

@yosifkit - is there a way to get the Dockerfile for that image? It would be nice to do something similar - otherwise, we can ignore the error and just run the python installer I suppose.

@whalelines
Copy link
Contributor

Depending on how the image was created, you can sometimes extract details about the Dockerfile by inspecting the image or interrogating the image's provenance, if provided.

https://docs.docker.com/engine/reference/commandline/inspect/
https://docs.docker.com/build/attestations/slsa-provenance/

@shahmishal
Copy link
Contributor Author

I updated the SHA to pick up changes from @compnerd

This comment has been minimized.

@shahmishal
Copy link
Contributor Author

+ ./test/run.sh swift:5.9.1-windowsservercore-ltsc2022
testing swift:5.9.1-windowsservercore-ltsc2022
	'override-cmd' [1/2]...passed
<unknown>:0: error: could not load the swift standard library
	'swift-hello-world' [2/2]...failed
Error: Process completed with exit code 1.

@compnerd
Copy link

compnerd commented Nov 2, 2023

I can add it as an extra commit to this PR once we're ready. I'm just working on reviewing it once again.

I think that we are at that point!

@LaurentGoderre
Copy link
Member

It seem problematic that the Sha changes all the time. It would mean that if the Windows base image gets a security patch, a rebuild of this will fail because the Sha will have changed

@compnerd
Copy link

compnerd commented Nov 2, 2023

@LaurentGoderre - for now, it just records that the SHA for the VS build tools bootstrapper is mismatched, so it should rebuild. I don't see any way to control that as there is no pinned URL that Microsoft has.

@yosifkit
Copy link
Member

yosifkit commented Nov 3, 2023

Just a couple review points:

  • minor typo in the python installation block:
    -    Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:PY39_SH256}); \
    +    Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:PY39_SHA256}); \
  • The python installation got moved after vs_buildtools, so the image is bigger again:
$ docker images
REPOSITORY                             TAG                 IMAGE ID       CREATED          SIZE
swift                                  test-reorder        47f92e93d96f   2 minutes ago    12.9GB
swift                                  test-new            d3215fc02273   17 hours ago     13.8GB
$ docker history swift:test-reorder
IMAGE          CREATED             CREATED BY                                      SIZE      COMMENT
47f92e93d96f   About an hour ago   powershell -Command $ErrorActionPreference =…   41kB
f14b5afaf41b   About an hour ago   |8 GIT=https://github.com/git-for-windows/gi…   3.88GB
e3c9d85e859b   About an hour ago   powershell -Command $ErrorActionPreference =…   41kB
428846da6b5b   About an hour ago   powershell -Command $ErrorActionPreference =…   41kB
5be92c0cb314   2 hours ago         |6 GIT=https://github.com/git-for-windows/gi…   4.49GB
4ff06a63cd2c   2 hours ago         powershell -Command $ErrorActionPreference =…   41kB
25fc6976ebd4   2 hours ago         powershell -Command $ErrorActionPreference =…   41kB
66f2d9d9e559   2 hours ago         |4 GIT=https://github.com/git-for-windows/gi…   91.6MB
a1f55ed4f134   2 hours ago         powershell -Command $ErrorActionPreference =…   41kB
3e1a580e48e0   2 hours ago         powershell -Command $ErrorActionPreference =…   41kB
682acaf68a0c   21 hours ago        |2 GIT=https://github.com/git-for-windows/gi…   379MB
5ae0ef8cdb2a   21 hours ago        powershell -Command $ErrorActionPreference =…   41kB
1c6169758db4   21 hours ago        powershell -Command $ErrorActionPreference =…   41kB
81addb6469a1   21 hours ago        powershell -Command $ErrorActionPreference =…   41kB
565570542ca6   8 days ago          powershell -Command $ErrorActionPreference =…   41kB
72fdef526f1c   2 months ago        cmd /S /C #(nop)  LABEL description=Docker C…   41kB
e5bd6c080618   2 months ago        cmd /S /C #(nop)  LABEL maintainer=Swift Inf…   41kB
4742812abba1   3 months ago        Install update 10.0.20348.1906                  961MB
<missing>      4 months ago        Apply image 10.0.20348.1787                     3.06GB
$ docker history swift:test-new
IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT
d3215fc02273   19 hours ago   powershell -Command $ErrorActionPreference =…   41kB
fcdb5e22f47d   19 hours ago   |8 GIT=https://github.com/git-for-windows/gi…   1.04GB
8c30f588be56   19 hours ago   powershell -Command $ErrorActionPreference =…   41kB
29c7881674e7   19 hours ago   powershell -Command $ErrorActionPreference =…   41kB
e69bc25b3a53   19 hours ago   |6 GIT=https://github.com/git-for-windows/gi…   3.87GB
eca397835e43   20 hours ago   powershell -Command $ErrorActionPreference =…   41kB
3d137b648862   20 hours ago   powershell -Command $ErrorActionPreference =…   41kB
fecd9c6100fa   20 hours ago   |4 GIT=https://github.com/git-for-windows/gi…   4.48GB
1209e34793e8   21 hours ago   powershell -Command $ErrorActionPreference =…   41kB
6249d947eaa2   21 hours ago   powershell -Command $ErrorActionPreference =…   41kB
682acaf68a0c   21 hours ago   |2 GIT=https://github.com/git-for-windows/gi…   379MB
5ae0ef8cdb2a   21 hours ago   powershell -Command $ErrorActionPreference =…   41kB
1c6169758db4   21 hours ago   powershell -Command $ErrorActionPreference =…   41kB
81addb6469a1   21 hours ago   powershell -Command $ErrorActionPreference =…   41kB
565570542ca6   8 days ago     powershell -Command $ErrorActionPreference =…   41kB
72fdef526f1c   2 months ago   cmd /S /C #(nop)  LABEL description=Docker C…   41kB
e5bd6c080618   2 months ago   cmd /S /C #(nop)  LABEL maintainer=Swift Inf…   41kB
4742812abba1   3 months ago   Install update 10.0.20348.1906                  961MB
<missing>      4 months ago   Apply image 10.0.20348.1787                     3.06GB

@compnerd
Copy link

compnerd commented Nov 3, 2023

Swapped the order but I don't see a difference locally (its 13.1G either way).

@yosifkit
Copy link
Member

yosifkit commented Nov 4, 2023

Swapped the order but I don't see a difference locally (its 13.1G either way).

That's super strange. I re-pulled the windows base image to get it more up-to-date and tried again and still they are very different. I'm building on a Windows 11 host using Powershell and Docker Desktop.

docker images
REPOSITORY                             TAG            IMAGE ID       CREATED          SIZE
swift                                  test-reorder   b5bfe34d3d86   54 minutes ago   13GB
swift                                  test-new       bb65ec56ae86   2 hours ago      13.9GB

@compnerd
Copy link

compnerd commented Nov 9, 2023

@yosifkit interesting. I think it might have something to do with a pretty old installation of Windows in my case. Can you help get the test changes applied so that we can get this merged?

@yosifkit yosifkit force-pushed the support-windows-swift branch from 053118d to 83d6a98 Compare November 9, 2023 19:52
Copy link

github-actions bot commented Nov 9, 2023

Diff for 83d6a98:
diff --git a/_bashbrew-arches b/_bashbrew-arches
index e85a97f..09c6ecf 100644
--- a/_bashbrew-arches
+++ b/_bashbrew-arches
@@ -1,2 +1,3 @@
 amd64
 arm64v8
+windows-amd64
diff --git a/_bashbrew-cat b/_bashbrew-cat
index 892e6b8..af2f893 100644
--- a/_bashbrew-cat
+++ b/_bashbrew-cat
@@ -258,3 +258,9 @@ Tags: 5.9.1-slim, 5.9-slim, 5.9.1-jammy-slim, 5.9-jammy-slim, jammy-slim, slim
 Architectures: amd64, arm64v8
 GitCommit: df8e8e36df704e52b2fabf9e732a0f08fbb333e4
 Directory: 5.9/ubuntu/22.04/slim
+
+Tags: 5.9.1-windowsservercore-ltsc2022, 5.9-windowsservercore-ltsc2022, windowsservercore-ltsc2022
+Architectures: windows-amd64
+GitCommit: 3fc609343f771e31c17140ed90d6cb2023e6e701
+Directory: 5.9/windows/LTSC2022
+Constraints: windowsservercore-ltsc2022
diff --git a/_bashbrew-list b/_bashbrew-list
index 15a24db..1b4c831 100644
--- a/_bashbrew-list
+++ b/_bashbrew-list
@@ -114,6 +114,7 @@ swift:5.9-jammy-slim
 swift:5.9-rhel-ubi9
 swift:5.9-rhel-ubi9-slim
 swift:5.9-slim
+swift:5.9-windowsservercore-ltsc2022
 swift:5.9.1
 swift:5.9.1-amazonlinux2
 swift:5.9.1-amazonlinux2-slim
@@ -126,6 +127,7 @@ swift:5.9.1-jammy-slim
 swift:5.9.1-rhel-ubi9
 swift:5.9.1-rhel-ubi9-slim
 swift:5.9.1-slim
+swift:5.9.1-windowsservercore-ltsc2022
 swift:amazonlinux2
 swift:amazonlinux2-slim
 swift:centos7
@@ -138,3 +140,4 @@ swift:latest
 swift:rhel-ubi9
 swift:rhel-ubi9-slim
 swift:slim
+swift:windowsservercore-ltsc2022
diff --git a/_bashbrew-list-build-order b/_bashbrew-list-build-order
index 8c23f03..ab03fe4 100644
--- a/_bashbrew-list-build-order
+++ b/_bashbrew-list-build-order
@@ -56,3 +56,4 @@ swift:focal-slim
 swift:rhel-ubi9
 swift:rhel-ubi9-slim
 swift:slim
+swift:windowsservercore-ltsc2022
diff --git a/swift_windowsservercore-ltsc2022/Dockerfile b/swift_windowsservercore-ltsc2022/Dockerfile
new file mode 100644
index 0000000..be0b6ff
--- /dev/null
+++ b/swift_windowsservercore-ltsc2022/Dockerfile
@@ -0,0 +1,156 @@
+FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS windows
+
+LABEL maintainer="Swift Infrastructure <swift-infrastructure@forums.swift.org>"
+LABEL description="Docker Container for the Swift programming language"
+
+SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
+
+ENV PYTHONIOENCODING UTF-8
+
+# Install Git.
+# See: git-[version]-[bit].exe /SAVEINF=git.inf and /?
+ARG GIT=https://github.com/git-for-windows/git/releases/download/v2.42.0.windows.2/Git-2.42.0.2-64-bit.exe
+ARG GIT_SHA256=BD9B41641A258FD16D99BEECEC66132160331D685DFB4C714CEA2BCC78D63BDB
+RUN Write-Host -NoNewLine ('Downloading {0} ... ' -f ${env:GIT});               \
+    Invoke-WebRequest -Uri ${env:GIT} -OutFile git.exe;                         \
+    Write-Host '✓';                                                             \
+    Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:GIT_SHA256}); \
+    $Hash = Get-FileHash git.exe -Algorithm sha256;                             \
+    if ($Hash.Hash -eq ${env:GIT_SHA256}) {                                     \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Hash.Hash);                                     \
+      exit 1;                                                                   \
+    }                                                                           \
+    Write-Host -NoNewLine 'Installing git ... ';                                \
+    $Process =                                                                  \
+        Start-Process git.exe -Wait -PassThru -NoNewWindow -ArgumentList @(     \
+          '/SP-',                                                               \
+          '/VERYSILENT',                                                        \
+          '/SUPPRESSMSGBOXES',                                                  \
+          '/NOCANCEL',                                                          \
+          '/NORESTART',                                                         \
+          '/CLOSEAPPLICATIONS',                                                 \
+          '/FORCECLOSEAPPLICATIONS',                                            \
+          '/NOICONS',                                                           \
+          '/COMPONENTS="gitlfs"',                                               \
+          '/EditorOption=VIM',                                                  \
+          '/PathOption=Cmd',                                                    \
+          '/SSHOption=OpenSSH',                                                 \
+          '/CURLOption=WinSSL',                                                 \
+          '/UseCredentialManager=Enabled',                                      \
+          '/EnableSymlinks=Enabled',                                            \
+          '/EnableFSMonitor=Enabled'                                            \
+        );                                                                      \
+    if ($Process.ExitCode -eq 0) {                                              \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Process.ExitCode);                              \
+      exit 1;                                                                   \
+    }                                                                           \
+    Remove-Item -Force git.exe;                                                 \
+    Remove-Item -ErrorAction SilentlyContinue -Force -Recurse ${env:TEMP}\*
+
+# Install Python
+ARG PY39=https://www.python.org/ftp/python/3.9.13/python-3.9.13-amd64.exe
+ARG PY39_SHA256=FB3D0466F3754752CA7FD839A09FFE53375FF2C981279FD4BC23A005458F7F5D
+RUN Write-Host -NoNewLine ('Downloading {0} ... ' -f ${env:PY39});              \
+    Invoke-WebRequest -Uri ${env:PY39} -OutFile python-3.9.13-amd64.exe;        \
+    Write-Host '✓';                                                             \
+    Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:PY39_SHA256});\
+    $Hash = Get-FileHash python-3.9.13-amd64.exe -Algorithm sha256;             \
+    if ($Hash.Hash -eq ${env:PY39_SHA256}) {                                    \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Hash.Hash);                                     \
+      exit 1;                                                                   \
+    }                                                                           \
+    Write-Host -NoNewLine 'Installing Python ... ';                             \
+    $Process =                                                                  \
+        Start-Process python-3.9.13-amd64.exe -Wait -PassThru -NoNewWindow -ArgumentList @( \
+           'AssociateFiles=0',                                                  \
+           'Include_doc=0',                                                     \
+           'Include_debug=0',                                                   \
+           'Include_lib=1',                                                     \
+           'Include_tcltk=0',                                                   \
+           'Include_test=0',                                                    \
+           'InstallAllUsers=1',                                                 \
+           'InstallLauncherAllUsers=0',                                         \
+           'PrependPath=1',                                                     \
+           '/quiet'                                                             \
+         );                                                                     \
+    if ($Process.ExitCode -eq 0) {                                              \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Process.ExitCode);                              \
+      exit 1;                                                                   \
+    }                                                                           \
+    Remove-Item -Force python-3.9.13-amd64.exe;                                 \
+    Remove-Item -ErrorAction SilentlyContinue -Force -Recurse ${env:TEMP}\*
+
+# Install Visual Studio Build Tools
+ARG VSB=https://aka.ms/vs/17/release/vs_buildtools.exe
+ARG VSB_SHA256=D4E08524CB0E5BD061A24F507928D1CFB91DCE192C5E12ED964B8343FC4CDEDD
+RUN Write-Host -NoNewLine ('Downloading {0} ... ' -f ${env:VSB});               \
+    Invoke-WebRequest -Uri ${env:VSB} -OutFile vs_buildtools.exe;               \
+    Write-Host '✓';                                                             \
+    Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:VSB_SHA256}); \
+    $Hash = Get-FileHash vs_buildtools.exe -Algorithm sha256;                   \
+    if ($Hash.Hash -eq ${env:VSB_SHA256}) {                                     \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Hash.Hash);                                     \
+    }                                                                           \
+    Write-Host -NoNewLine 'Installing Visual Studio Build Tools ... ';          \
+    $Process =                                                                  \
+        Start-Process vs_buildtools.exe -Wait -PassThru -NoNewWindow -ArgumentList @( \
+          '--quiet',                                                            \
+          '--wait',                                                             \
+          '--norestart',                                                        \
+          '--nocache',                                                          \
+          '--add', 'Microsoft.VisualStudio.Component.Windows11SDK.22000',       \
+          '--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'          \
+        );                                                                      \
+    if ($Process.ExitCode -eq 0 -or $Process.ExitCode -eq 3010) {               \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Process.ExitCode);                              \
+      exit 1;                                                                   \
+    }                                                                           \
+    Remove-Item -Force vs_buildtools.exe;                                       \
+    Remove-Item -ErrorAction SilentlyContinue -Force -Recurse ${env:TEMP}\*
+
+# Install Swift toolchain.
+ARG SWIFT=https://download.swift.org/swift-5.9.1-release/windows10/swift-5.9.1-RELEASE/swift-5.9.1-RELEASE-windows10.exe
+ARG SWIFT_SHA256=B219D472EEB87612E9977518D2253ED88FBA9CE2CD42CB8FEF3011583B7D1369
+RUN Write-Host -NoNewLine ('Downloading {0} ... ' -f ${env:SWIFT});             \
+    Invoke-WebRequest -Uri ${env:SWIFT} -OutFile installer.exe;                 \
+    Write-Host '✓';                                                             \
+    Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:SWIFT_SHA256}); \
+    $Hash = Get-FileHash installer.exe -Algorithm sha256;                       \
+    if ($Hash.Hash -eq ${env:SWIFT_SHA256}) {                                   \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Hash.Hash);                                     \
+      exit 1;                                                                   \
+    }                                                                           \
+    Write-Host -NoNewLine 'Installing Swift ... ';                              \
+    $Process =                                                                  \
+        Start-Process installer.exe -Wait -PassThru -NoNewWindow -ArgumentList @( \
+           '/quiet',                                                            \
+           '/norestart'                                                         \
+         );                                                                     \
+    if ($Process.ExitCode -eq 0) {                                              \
+      Write-Host '✓';                                                           \
+    } else {                                                                    \
+      Write-Host ('✘ ({0})' -f $Process.ExitCode);                              \
+      exit 1;                                                                   \
+    }                                                                           \
+    Remove-Item -Force installer.exe;                                           \
+    Remove-Item -ErrorAction SilentlyContinue -Force -Recurse ${env:TEMP}\*
+
+# Default to powershell
+# FIXME: we need to grant ContainerUser the SeCreateSymbolicLinkPrivilege
+# privilege so that it can create symbolic links.
+# USER ContainerUser
+CMD ["powershell.exe", "-nologo", "-ExecutionPolicy", "Bypass"]

Relevant Maintainers:

@yosifkit
Copy link
Member

yosifkit commented Nov 9, 2023

Squash & rebased, updated swift test, added updated swift-docker 5.9 Windows commit to library file: swiftlang/swift-docker@3fc6093

@shahmishal
Copy link
Contributor Author

🎉

@yosifkit yosifkit merged commit 1f3ec9d into docker-library:master Nov 9, 2023
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants