1# This dockerfile is taken from go/rbe-windows-user-guide 2# Local modifications: 3# * install VS2019 (instead of VS2022) 4# TODO(jtattermusch): check the --compilation_mode=dbg fix 5 6# This Dockerfile creates an image that has the following: 7# * correct MTU setting for networking from inside the container to work. 8# * metadata server routes correctly installed 9# * VC++ redistributable installed 10# * Visual Studio 2019 Build Tools installed 11# * msys2 + git, curl, zip, unzip installed 12# * Python 3.10.4 installed 13# * JDK 17.0.2 installed 14# Use the latest stable Windows Server Core image (mainstream support ends 1/9/2024). 15FROM mcr.microsoft.com/windows/servercore:ltsc2019 16# Set default powershell policy for this script (ProgressPreference='SilentlyContinue' makes 17# downloads with Invoke-WebRequest not show the progress bar and is MUCH faster). 18SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; $VerbosePreference = 'Continue';"] 19# Workaround for networking (b/112379377) was closed as won't fix for MTU setting. 20# Remaining lines handle making the metadata server on the VM accessible inside docker. 21RUN Get-NetAdapter | Where-Object Name -like "*Ethernet*" | ForEach-Object { \ 22 & netsh interface ipv4 set subinterface $_.InterfaceIndex mtu=1460 store=persistent }; \ 23 $gateway = (Get-NetRoute | Where { $_.DestinationPrefix -eq \"0.0.0.0/0\" } | Sort-Object RouteMetric \ 24 | Select NextHop).NextHop; \ 25 $ifIndex = (Get-NetAdapter -InterfaceDescription \"Hyper-V Virtual Ethernet*\" | Sort-Object \ 26 | Select ifIndex).ifIndex; \ 27 New-NetRoute -DestinationPrefix 169.254.169.254/32 -InterfaceIndex $ifIndex -NextHop $gateway 28# Enable Long Paths for Win32 File/Folder APIs. 29RUN New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem \ 30 -Name LongPathsEnabled -Value 1 -PropertyType DWORD -Force 31# Install Visual C++ Redistributable for Visual Studio 2015-2022. 32RUN New-Item -Path "C:/" -Name "TEMP" -ItemType "directory"; \ 33 Invoke-WebRequest "https://aka.ms/vs/17/release/vc_redist.x64.exe" \ 34 -OutFile C:/TEMP/vc_redist.x64.exe -UseBasicParsing; \ 35 Start-Process -filepath C:/TEMP/vc_redist.x64.exe -ArgumentList '/install', '/passive', '/norestart' -Wait; \ 36 Remove-Item C:/TEMP/vc_redist.x64.exe 37 38# Install Visual Studio 2019 Build Tools. 39RUN Invoke-WebRequest "https://aka.ms/vs/16/release/vs_buildtools.exe" \ 40 -OutFile C:/TEMP/vs_buildtools.exe -UseBasicParsing; \ 41 Start-Process -FilePath C:/TEMP/vs_buildtools.exe -ArgumentList "--installPath", "C:/VS", \ 42 "--quiet", "--wait", "--nocache", \ 43 "--add", "Microsoft.VisualStudio.Workload.VCTools", \ 44 "--add", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", \ 45 "--add", "Microsoft.VisualStudio.Component.Windows10SDK.20348" -Wait; \ 46 Remove-Item C:/TEMP/vs_buildtools.exe; \ 47 [Environment]::SetEnvironmentVariable(\"BAZEL_VC\", \"C:\VS\VC\", \"Machine\") 48# Install msys2 and add to path. 49RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \ 50 Invoke-WebRequest "https://repo.msys2.org/distrib/x86_64/msys2-base-x86_64-20220319.sfx.exe" \ 51 -OutFile msys2_install.exe -UseBasicParsing; \ 52 .\msys2_install.exe -y -oC:\; \ 53 Remove-Item msys2_install.exe; \ 54 function msys() { C:\msys64\usr\bin\bash.exe @('-lc') + @Args; } \ 55 msys ' '; \ 56 msys 'pacman --noconfirm -Syy zstd'; \ 57 msys 'pacman --noconfirm -Syy git curl zip unzip'; \ 58 $old_path = [Environment]::GetEnvironmentVariable(\"PATH\", \"Machine\"); \ 59 [Environment]::SetEnvironmentVariable(\"PATH\", $old_path + \";C:\msys64;C:\msys64\usr\bin\", \"Machine\"); 60# Install Python 3. 61RUN Invoke-WebRequest "https://www.python.org/ftp/python/3.10.4/python-3.10.4-amd64.exe" \ 62 -OutFile C:/TEMP/python_install.exe -UseBasicParsing; \ 63 Start-Process C:/TEMP/python_install.exe -ArgumentList "/quiet", "/log", "C:/TEMP/python_install_log.txt", \ 64 "InstallAllUsers=1", "PrependPath=1" -wait; \ 65 Remove-Item C:/TEMP/python_install.exe; \ 66 Remove-Item C:/TEMP/python_install_log.txt 67# Install JDK 17 68RUN Add-Type -AssemblyName "System.IO.Compression.FileSystem"; \ 69 $zulu_url = \"https://cdn.azul.com/zulu/bin/zulu17.32.13-ca-jdk17.0.2-win_x64.zip\"; \ 70 $zulu_zip = \"c:/temp/jdk_install.zip\"; \ 71 $zulu_extracted_path = \"c:/temp/\" + [IO.Path]::GetFileNameWithoutExtension($zulu_url); \ 72 $zulu_root = \"c:/openjdk\"; \ 73 (New-Object Net.WebClient).DownloadFile($zulu_url, $zulu_zip); \ 74 [System.IO.Compression.ZipFile]::ExtractToDirectory($zulu_zip, \"c:/temp\"); \ 75 Move-Item $zulu_extracted_path -Destination $zulu_root; \ 76 Remove-Item $zulu_zip; \ 77 $old_path = [Environment]::GetEnvironmentVariable(\"PATH\", \"Machine\"); \ 78 [Environment]::SetEnvironmentVariable(\"PATH\", $old_path + \";${zulu_root}\bin\", \"Machine\"); \ 79 [Environment]::SetEnvironmentVariable(\"JAVA_HOME\", $zulu_root, \"Machine\") 80# Restore default shell for Windows containers. 81SHELL ["cmd.exe", "/s", "/c"] 82# Default to PowerShell if no other command specified. 83CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] 84