Dockerfile 6.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # This dockerfile is taken from go/rbe-windows-user-guide
  2. # (including the fix --compilation_mode=dbg)
  3. # This Dockerfile creates an image that:
  4. # - Has the correct MTU setting for networking from inside the container to work.
  5. # - Has Visual Studio 2015 Build Tools installed.
  6. # - Has msys2 + git, curl, zip, unzip installed.
  7. # - Has Python 2.7 installed.
  8. # TODO(jsharpe): Consider replacing "ADD $URI $DEST" with "Invoke-WebRequest -Method Get -Uri $URI -OutFile $DEST"
  9. # Use the latest Windows Server Core image.
  10. #
  11. # WARNING: What's the `:ltsc2019` about?
  12. # There are two versions of Windows Server 2019:
  13. # 1. A "regular" one (corresponding to `mcr.microsoft.com/windows/servercore:ltsc2019`)
  14. # is on a slow release cadence and is the Long-Term Servicing Channel.
  15. # Mainstream support for this image will end on 1/9/2024.
  16. # 2. A "fast" release cadence one (corresponding to
  17. # `mcr.microsoft.com/windows/servercore:1909`) is the Semi-Annual Channel.
  18. # Mainstream support for this image will end on 5/11/2021.
  19. #
  20. # If you choose a different
  21. # image than described above, change the `:ltsc2019` tag.
  22. # Start a temporary container in which we install 7-Zip to extract msys2
  23. FROM mcr.microsoft.com/windows/servercore:ltsc2019 as extract-msys2
  24. SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; $VerbosePreference = 'Continue';"]
  25. # Install 7-Zip and add it to the path.
  26. ADD https://www.7-zip.org/a/7z1801-x64.msi C:\\TEMP\\7z.msi
  27. RUN Start-Process msiexec.exe -ArgumentList \"/i C:\\TEMP\\7z.msi /qn /norestart /log C:\\TEMP\\7z_install_log.txt\" -wait
  28. RUN $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path; \
  29. $newpath = \"$oldpath;C:\Program Files\7-Zip\"; \
  30. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  31. # Extract msys2
  32. ADD http://repo.msys2.org/distrib/x86_64/msys2-base-x86_64-20181211.tar.xz C:\\TEMP\\msys2.tar.xz
  33. RUN 7z x C:\TEMP\msys2.tar.xz -oC:\TEMP\msys2.tar
  34. RUN 7z x C:\TEMP\msys2.tar -oC:\tools
  35. # Start building the actual image
  36. FROM mcr.microsoft.com/windows/servercore:ltsc2019
  37. SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; $VerbosePreference = 'Continue';"]
  38. # TODO(b/112379377): Workaround until bug is fixed.
  39. RUN Get-NetAdapter | Where-Object Name -like "*Ethernet*" | ForEach-Object { & netsh interface ipv4 set subinterface $_.InterfaceIndex mtu=1460 store=persistent }
  40. # Enable Long Paths for Win32 File/Folder APIs.
  41. RUN New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1 -PropertyType DWORD -Force
  42. # Install Visual Studio 2015 Build Tools.
  43. RUN Invoke-WebRequest "https://download.microsoft.com/download/5/f/7/5f7acaeb-8363-451f-9425-68a90f98b238/visualcppbuildtools_full.exe" \
  44. -OutFile visualcppbuildtools_full.exe -UseBasicParsing ; \
  45. Start-Process -FilePath 'visualcppbuildtools_full.exe' -ArgumentList '/quiet', '/NoRestart', '/InstallSelectableItems "Win10SDK_VisibleV1"' -Wait ; \
  46. Remove-Item .\visualcppbuildtools_full.exe;
  47. # Add ucrtbased.dll to the system directory to allow --compilation_mode=dbg to
  48. # work. This DLL should be automatically copied to C:\Windows\System32 by the
  49. # installer, but isn't when the installer is run on Docker, for some reason.
  50. RUN Copy-Item \"C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt\ucrtbased.dll\" C:\Windows\System32
  51. # TODO(jsharpe): Alternate install for msys2: https://github.com/StefanScherer/dockerfiles-windows/issues/30
  52. # From the temporary extract-msys2 container, copy the tools directory to this container
  53. COPY --from=extract-msys2 ["C:/tools", "C:/tools"]
  54. # Add msys2 to the PATH variable
  55. RUN $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path; \
  56. $newpath = \"$oldpath;C:\tools\msys64;C:\tools\msys64\usr\bin\"; \
  57. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  58. # Bazel documentation says to use -Syuu but this doesn't work in Docker. See
  59. # http://g/foundry-windows/PDMVXbGew7Y
  60. RUN bash.exe -c \"pacman-key --init && pacman-key --populate msys2 && pacman-key --refresh-keys && pacman --noconfirm -Syy git curl zip unzip\"
  61. # Install Visual C++ Redistributable for Visual Studio 2015:
  62. ADD https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe C:\\TEMP\\vc_redist.x64.exe
  63. RUN C:\TEMP\vc_redist.x64.exe /quiet /install
  64. # Install Python 2.7.
  65. ADD https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi C:\\TEMP\\python.msi
  66. RUN Start-Process msiexec.exe -ArgumentList \"/i C:\\TEMP\\python.msi /qn /norestart /log C:\\TEMP\\python_install_log.txt\" -wait
  67. RUN $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path; \
  68. $newpath = \"$oldpath;C:\Python27\"; \
  69. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  70. RUN \
  71. Add-Type -AssemblyName \"System.IO.Compression.FileSystem\"; \
  72. $zulu_url = \"https://cdn.azul.com/zulu/bin/zulu8.28.0.1-jdk8.0.163-win_x64.zip\"; \
  73. $zulu_zip = \"c:\\temp\\zulu8.28.0.1-jdk8.0.163-win_x64.zip\"; \
  74. $zulu_extracted_path = \"c:\\temp\\\" + [IO.Path]::GetFileNameWithoutExtension($zulu_zip); \
  75. $zulu_root = \"c:\\openjdk\"; \
  76. (New-Object Net.WebClient).DownloadFile($zulu_url, $zulu_zip); \
  77. [System.IO.Compression.ZipFile]::ExtractToDirectory($zulu_zip, \"c:\\temp\"); \
  78. Move-Item $zulu_extracted_path -Destination $zulu_root; \
  79. Remove-Item $zulu_zip; \
  80. $env:PATH = [Environment]::GetEnvironmentVariable(\"PATH\", \"Machine\") + \";${zulu_root}\\bin\"; \
  81. [Environment]::SetEnvironmentVariable(\"PATH\", $env:PATH, \"Machine\"); \
  82. $env:JAVA_HOME = $zulu_root; \
  83. [Environment]::SetEnvironmentVariable(\"JAVA_HOME\", $env:JAVA_HOME, \"Machine\")
  84. # Restore default shell for Windows containers.
  85. SHELL ["cmd.exe", "/s", "/c"]
  86. # Default to PowerShell if no other command specified.
  87. CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]