From 913dbdc973d700c2aed93ff69597da339799b923 Mon Sep 17 00:00:00 2001 From: Gabriel Smith Date: Sun, 7 Feb 2021 01:01:08 -0500 Subject: [PATCH 1/3] Add support for MSVC toolchain on Windows Server Core This dockerfile cannot be pushed to public hubs due to licensing restrictions, but we might as well provide the dockerfile for others and test against it. Please see the comment at the top of the MSVC template file for more information. Co-authored-by: Nelson Chen --- 1.50.0/windowsservercore-1809/msvc/Dockerfile | 72 +++++++++++++++++++ Dockerfile-windows-msvc.template | 72 +++++++++++++++++++ x.py | 26 +++++++ 3 files changed, 170 insertions(+) create mode 100644 1.50.0/windowsservercore-1809/msvc/Dockerfile create mode 100644 Dockerfile-windows-msvc.template diff --git a/1.50.0/windowsservercore-1809/msvc/Dockerfile b/1.50.0/windowsservercore-1809/msvc/Dockerfile new file mode 100644 index 0000000..0dee5ac --- /dev/null +++ b/1.50.0/windowsservercore-1809/msvc/Dockerfile @@ -0,0 +1,72 @@ +# escape=` + +# IMAGES BUILT FROM THIS DOCKERFILE ARE NOT TO BE SHARED ON PUBLIC DOCKER HUBs. +# +# WARNING: NON-FREE AND DISTRIBUTION RESTRICTED ENCUMBERED SOFTWARE IN IMAGE. +# +# The VS Build Tools are very encumbered. +# +# IMAGE SHOULD ONLY BE BUILT BY USERS WHO CAN FOLLOW THESE TERMS: +# https://visualstudio.microsoft.com/license-terms/mlt553512/ +# +# See the fourth paragraph of this blog post for a warning from a Microsoftie: +# https://blogs.msdn.microsoft.com/vcblog/2018/08/13/using-msvc-in-a-docker-container-for-your-c-projects/ +# +# """ +# The VS Build Tools are licensed as a supplement to your existing Visual Studio license. +# Any images built with these tools should be for your personal use or for use in your +# organization in accordance with your existing Visual Studio and Windows licenses. +# Please don’t share these images on a public Docker hub. +# """ +# +# That said, this Dockerfile will be built in a CI system for validation and testing in the project +# but most definitely will skip deployment. + +FROM mcr.microsoft.com/windows/servercore:1809 + +SHELL ["powershell.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN $url = 'https://download.visualstudio.microsoft.com/download/pr/20130c62-1bc8-43d6-b4f0-c20bb7c79113/7276a7355219f7988c480d198e23c2973bbb7ab971c4f0415c26cab2955344e5/vs_BuildTools.exe'; ` + $sha256 = '7276A7355219F7988C480D198E23C2973BBB7AB971C4F0415C26CAB2955344E5'; ` + Invoke-WebRequest -Uri $url -OutFile C:\vs_BuildTools.exe; ` + $actual256 = (Get-FileHash vs_BuildTools.exe -Algorithm sha256).Hash; ` + if ($actual256 -ne $sha256) { ` + Write-Host 'FAILED!'; ` + Write-Host ('expected: {0}' -f $sha256); ` + Write-Host ('got: {0}' -f $actual256); ` + exit 1; ` + }; ` + Start-Process -filepath C:\vs_BuildTools.exe -wait -argumentlist ' ` + --quiet --wait --norestart --nocache ` + --installPath C:\BuildTools ` + --add Microsoft.Component.MSBuild ` + --add Microsoft.VisualStudio.Component.Windows10SDK.17763 ` + --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64'; ` + Remove-Item 'C:\\vs_BuildTools.exe'; ` + Remove-Item -Force -Recurse 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer'; ` + [Environment]::SetEnvironmentVariable('__VSCMD_ARG_NO_LOGO', '1', [EnvironmentVariableTarget]::Machine) + +ENV RUSTUP_HOME=C:\rustup ` + CARGO_HOME=C:\cargo ` + RUST_VERSION=1.50.0 + +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` + $url = 'https://static.rust-lang.org/rustup/archive/1.23.1/x86_64-pc-windows-msvc/rustup-init.exe'; ` + $sha256 = 'a586cf9de3e4aa791fd5796b6a5f99ca05591ccef8bb94e53af5b69f0261fb03'; ` + Invoke-WebRequest -Uri $url -OutFile C:\rustup-init.exe; ` + $actual256 = (Get-FileHash rustup-init.exe -Algorithm sha256).Hash; ` + if ($actual256 -ne $sha256) { ` + Write-Host 'FAILED!'; ` + Write-Host ('expected: {0}' -f $sha256); ` + Write-Host ('got: {0}' -f $actual256); ` + exit 1; ` + }; ` + New-Item ${env:CARGO_HOME}\bin -type directory | Out-Null; ` + $newPath = ('{0}\bin;{1}' -f ${env:CARGO_HOME}, ${env:PATH}); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Process); ` + C:\rustup-init.exe -y -v --no-modify-path --default-toolchain ${env:RUST_VERSION} --default-host x86_64-pc-windows-msvc; ` + Remove-Item C:\rustup-init.exe; ` + rustup -V; ` + cargo -V; ` + rustc -V diff --git a/Dockerfile-windows-msvc.template b/Dockerfile-windows-msvc.template new file mode 100644 index 0000000..8d498ee --- /dev/null +++ b/Dockerfile-windows-msvc.template @@ -0,0 +1,72 @@ +# escape=` + +# IMAGES BUILT FROM THIS DOCKERFILE ARE NOT TO BE SHARED ON PUBLIC DOCKER HUBs. +# +# WARNING: NON-FREE AND DISTRIBUTION RESTRICTED ENCUMBERED SOFTWARE IN IMAGE. +# +# The VS Build Tools are very encumbered. +# +# IMAGE SHOULD ONLY BE BUILT BY USERS WHO CAN FOLLOW THESE TERMS: +# https://visualstudio.microsoft.com/license-terms/mlt553512/ +# +# See the fourth paragraph of this blog post for a warning from a Microsoftie: +# https://blogs.msdn.microsoft.com/vcblog/2018/08/13/using-msvc-in-a-docker-container-for-your-c-projects/ +# +# """ +# The VS Build Tools are licensed as a supplement to your existing Visual Studio license. +# Any images built with these tools should be for your personal use or for use in your +# organization in accordance with your existing Visual Studio and Windows licenses. +# Please don’t share these images on a public Docker hub. +# """ +# +# That said, this Dockerfile will be built in a CI system for validation and testing in the project +# but most definitely will skip deployment. + +FROM mcr.microsoft.com/windows/servercore:%%WINDOWS-VERSION%% + +SHELL ["powershell.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN $url = 'https://download.visualstudio.microsoft.com/download/pr/20130c62-1bc8-43d6-b4f0-c20bb7c79113/7276a7355219f7988c480d198e23c2973bbb7ab971c4f0415c26cab2955344e5/vs_BuildTools.exe'; ` + $sha256 = '7276A7355219F7988C480D198E23C2973BBB7AB971C4F0415C26CAB2955344E5'; ` + Invoke-WebRequest -Uri $url -OutFile C:\vs_BuildTools.exe; ` + $actual256 = (Get-FileHash vs_BuildTools.exe -Algorithm sha256).Hash; ` + if ($actual256 -ne $sha256) { ` + Write-Host 'FAILED!'; ` + Write-Host ('expected: {0}' -f $sha256); ` + Write-Host ('got: {0}' -f $actual256); ` + exit 1; ` + }; ` + Start-Process -filepath C:\vs_BuildTools.exe -wait -argumentlist ' ` + --quiet --wait --norestart --nocache ` + --installPath C:\BuildTools ` + --add Microsoft.Component.MSBuild ` + --add Microsoft.VisualStudio.Component.Windows10SDK.%%SDK-BUILD%% ` + --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64'; ` + Remove-Item 'C:\\vs_BuildTools.exe'; ` + Remove-Item -Force -Recurse 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer'; ` + [Environment]::SetEnvironmentVariable('__VSCMD_ARG_NO_LOGO', '1', [EnvironmentVariableTarget]::Machine) + +ENV RUSTUP_HOME=C:\rustup ` + CARGO_HOME=C:\cargo ` + RUST_VERSION=%%RUST-VERSION%% + +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` + $url = 'https://static.rust-lang.org/rustup/archive/%%RUSTUP-VERSION%%/x86_64-pc-windows-msvc/rustup-init.exe'; ` + $sha256 = '%%RUSTUP-SHA256%%'; ` + Invoke-WebRequest -Uri $url -OutFile C:\rustup-init.exe; ` + $actual256 = (Get-FileHash rustup-init.exe -Algorithm sha256).Hash; ` + if ($actual256 -ne $sha256) { ` + Write-Host 'FAILED!'; ` + Write-Host ('expected: {0}' -f $sha256); ` + Write-Host ('got: {0}' -f $actual256); ` + exit 1; ` + }; ` + New-Item ${env:CARGO_HOME}\bin -type directory | Out-Null; ` + $newPath = ('{0}\bin;{1}' -f ${env:CARGO_HOME}, ${env:PATH}); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Process); ` + C:\rustup-init.exe -y -v --no-modify-path --default-toolchain ${env:RUST_VERSION} --default-host x86_64-pc-windows-msvc; ` + Remove-Item C:\rustup-init.exe; ` + rustup -V; ` + cargo -V; ` + rustc -V diff --git a/x.py b/x.py index d8b6d15..83ee44e 100755 --- a/x.py +++ b/x.py @@ -38,11 +38,25 @@ default_alpine_version = "3.13" +# (Windows Server tag, Windows SDK build number) +# The build number is specifically used to select the right Windows 10 SDK to +# install from the Visual Studio Build Tools installer. See +# https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2019#c-build-tools +# for the build version numbers. +windows_servercore_versions = [ + ("1809", "17763"), +] + def rustup_hash(arch): url = f"https://static.rust-lang.org/rustup/archive/{rustup_version}/{arch}/rustup-init.sha256" with request.urlopen(url) as f: return f.read().decode('utf-8').split()[0] +def rustup_hash_windows(arch): + url = f"https://static.rust-lang.org/rustup/archive/{rustup_version}/{arch}/rustup-init.exe.sha256" + with request.urlopen(url) as f: + return f.read().decode('utf-8').split()[0] + def read_file(file): with open(file, "r") as f: return f.read() @@ -100,6 +114,17 @@ def update_alpine(): .replace("%%ARCH-CASE%%", arch_case) write_file(f"{rust_version}/alpine{version}/Dockerfile", rendered) +def update_windows(): + template = read_file("Dockerfile-windows-msvc.template") + for version, build in windows_servercore_versions: + rendered = template \ + .replace("%%RUST-VERSION%%", rust_version) \ + .replace("%%RUSTUP-VERSION%%", rustup_version) \ + .replace("%%WINDOWS-VERSION%%", version) \ + .replace("%%SDK-BUILD%%", build) \ + .replace("%%RUSTUP-SHA256%%", rustup_hash_windows("x86_64-pc-windows-msvc")) + write_file(f"{rust_version}/windowsservercore-{version}/msvc/Dockerfile", rendered) + def update_travis(): file = ".travis.yml" config = read_file(file) @@ -209,6 +234,7 @@ def usage(): update_debian() update_alpine() update_travis() + update_windows() elif task == "generate-stackbrew-library": generate_stackbrew_library() else: From 323705a75072568372364416bd6ceeb043c77efa Mon Sep 17 00:00:00 2001 From: Gabriel Smith Date: Sat, 13 Feb 2021 14:15:20 -0500 Subject: [PATCH 2/3] Move CI to GitHub Actions --- .github/workflows/build-images.yml | 51 ++++++++++++++++++++++++++++++ .travis.yml | 25 --------------- x.py | 25 +++++++++++---- 3 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/build-images.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml new file mode 100644 index 0000000..e57469f --- /dev/null +++ b/.github/workflows/build-images.yml @@ -0,0 +1,51 @@ +name: Build Docker Images + +on: [push, pull_request] + +jobs: + build-images: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + include: +#VERSIONS + - variant: buster + os: ubuntu-18.04 + version: 1.50.0 + - variant: buster/slim + os: ubuntu-18.04 + version: 1.50.0 + - variant: alpine3.12 + os: ubuntu-18.04 + version: 1.50.0 + - variant: alpine3.13 + os: ubuntu-18.04 + version: 1.50.0 + - variant: windowsservercore-1809/msvc + os: windows-2019 + version: 1.50.0 +#VERSIONS + + steps: + - name: Check out repo + uses: actions/checkout@v2 + with: + ref: ${{ github.ref }} + - name: Check out Docker official images repo + uses: actions/checkout@v2 + with: + repository: docker-library/official-images + path: official-images + - name: Build and test docker image + shell: bash + env: + VERSION: ${{ matrix.version }} + VARIANT: ${{ matrix.variant }} + run: | + env | sort + cd "${VERSION}/${VARIANT}" + slash='/'; image="rust:${VERSION}-${VARIANT//$slash/-}" + docker build -t "$image" . + ${GITHUB_WORKSPACE}/official-images/test/run.sh "$image" + docker images diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9afc77a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: bash -services: docker - -env: -#VERSIONS - - VERSION=1.50.0 VARIANT=buster - - VERSION=1.50.0 VARIANT=buster/slim - - VERSION=1.50.0 VARIANT=alpine3.12 - - VERSION=1.50.0 VARIANT=alpine3.13 -#VERSIONS - -install: - - git clone https://github.com/docker-library/official-images.git ~/official-images - -before_script: - - env | sort - - cd "$VERSION/$VARIANT" - - slash='/'; image="rust:${VERSION}-${VARIANT//$slash/-}" - -script: - - travis_retry docker build -t "$image" . - - ~/official-images/test/run.sh "$image" - -after_script: - - docker images diff --git a/x.py b/x.py index 83ee44e..8e9c021 100755 --- a/x.py +++ b/x.py @@ -125,17 +125,30 @@ def update_windows(): .replace("%%RUSTUP-SHA256%%", rustup_hash_windows("x86_64-pc-windows-msvc")) write_file(f"{rust_version}/windowsservercore-{version}/msvc/Dockerfile", rendered) -def update_travis(): - file = ".travis.yml" +def update_github_actions(): + file = ".github/workflows/build-images.yml" config = read_file(file) versions = "" for variant in debian_variants: - versions += f" - VERSION={rust_version} VARIANT={variant}\n" - versions += f" - VERSION={rust_version} VARIANT={variant}/slim\n" + versions += f" - variant: {variant}\n" + versions += f" os: ubuntu-18.04\n" + versions += f" version: {rust_version}\n" + + versions += f" - variant: {variant}/slim\n" + versions += f" os: ubuntu-18.04\n" + versions += f" version: {rust_version}\n" for version in alpine_versions: - versions += f" - VERSION={rust_version} VARIANT=alpine{version}\n" + versions += f" - variant: alpine{version}\n" + versions += f" os: ubuntu-18.04\n" + versions += f" version: {rust_version}\n" + + for version, build in windows_servercore_versions: + versions += f" - variant: windowsservercore-{version}/msvc\n" + versions += f" os: windows-2019\n" + versions += f" version: {rust_version}\n" + marker = "#VERSIONS\n" split = config.split(marker) @@ -233,8 +246,8 @@ def usage(): if task == "update": update_debian() update_alpine() - update_travis() update_windows() + update_github_actions() elif task == "generate-stackbrew-library": generate_stackbrew_library() else: From ba375b78b82507ebae9242b294f3183a7cb8c22d Mon Sep 17 00:00:00 2001 From: Gabriel Smith Date: Sun, 14 Feb 2021 02:05:54 -0500 Subject: [PATCH 3/3] Add support for GNU toolchain on Windows Co-authored-by: Nelson Chen --- .github/workflows/build-images.yml | 3 ++ 1.50.0/windowsservercore-1809/gnu/Dockerfile | 30 ++++++++++++++++++++ Dockerfile-windows-gnu.template | 30 ++++++++++++++++++++ x.py | 25 ++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 1.50.0/windowsservercore-1809/gnu/Dockerfile create mode 100644 Dockerfile-windows-gnu.template diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index e57469f..1de1b31 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -25,6 +25,9 @@ jobs: - variant: windowsservercore-1809/msvc os: windows-2019 version: 1.50.0 + - variant: windowsservercore-1809/gnu + os: windows-2019 + version: 1.50.0 #VERSIONS steps: diff --git a/1.50.0/windowsservercore-1809/gnu/Dockerfile b/1.50.0/windowsservercore-1809/gnu/Dockerfile new file mode 100644 index 0000000..4b72b8b --- /dev/null +++ b/1.50.0/windowsservercore-1809/gnu/Dockerfile @@ -0,0 +1,30 @@ +# escape=` + +FROM mcr.microsoft.com/windows/servercore:1809 + +SHELL ["powershell.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +ENV RUSTUP_HOME=C:\rustup ` + CARGO_HOME=C:\cargo ` + RUST_VERSION=1.50.0 + +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` + $url = 'https://static.rust-lang.org/rustup/archive/1.23.1/x86_64-pc-windows-msvc/rustup-init.exe'; ` + $sha256 = 'a586cf9de3e4aa791fd5796b6a5f99ca05591ccef8bb94e53af5b69f0261fb03'; ` + Invoke-WebRequest -Uri $url -OutFile C:\rustup-init.exe; ` + $actual256 = (Get-FileHash rustup-init.exe -Algorithm sha256).Hash; ` + if ($actual256 -ne $sha256) { ` + Write-Host 'FAILED!'; ` + Write-Host ('expected: {0}' -f $sha256); ` + Write-Host ('got: {0}' -f $actual256); ` + exit 1; ` + }; ` + New-Item ${env:CARGO_HOME}\bin -type directory | Out-Null; ` + $newPath = ('{0}\bin;{1}' -f ${env:CARGO_HOME}, ${env:PATH}); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Process); ` + C:\rustup-init.exe -y -v --no-modify-path --default-toolchain ${env:RUST_VERSION} --default-host x86_64-pc-windows-gnu; ` + Remove-Item C:\rustup-init.exe; ` + rustup -V; ` + cargo -V; ` + rustc -V diff --git a/Dockerfile-windows-gnu.template b/Dockerfile-windows-gnu.template new file mode 100644 index 0000000..b7c75e1 --- /dev/null +++ b/Dockerfile-windows-gnu.template @@ -0,0 +1,30 @@ +# escape=` + +FROM mcr.microsoft.com/windows/servercore:%%WINDOWS-VERSION%% + +SHELL ["powershell.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +ENV RUSTUP_HOME=C:\rustup ` + CARGO_HOME=C:\cargo ` + RUST_VERSION=%%RUST-VERSION%% + +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` + $url = 'https://static.rust-lang.org/rustup/archive/%%RUSTUP-VERSION%%/x86_64-pc-windows-msvc/rustup-init.exe'; ` + $sha256 = '%%RUSTUP-SHA256%%'; ` + Invoke-WebRequest -Uri $url -OutFile C:\rustup-init.exe; ` + $actual256 = (Get-FileHash rustup-init.exe -Algorithm sha256).Hash; ` + if ($actual256 -ne $sha256) { ` + Write-Host 'FAILED!'; ` + Write-Host ('expected: {0}' -f $sha256); ` + Write-Host ('got: {0}' -f $actual256); ` + exit 1; ` + }; ` + New-Item ${env:CARGO_HOME}\bin -type directory | Out-Null; ` + $newPath = ('{0}\bin;{1}' -f ${env:CARGO_HOME}, ${env:PATH}); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); ` + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Process); ` + C:\rustup-init.exe -y -v --no-modify-path --default-toolchain ${env:RUST_VERSION} --default-host x86_64-pc-windows-gnu; ` + Remove-Item C:\rustup-init.exe; ` + rustup -V; ` + cargo -V; ` + rustc -V diff --git a/x.py b/x.py index 8e9c021..626e005 100755 --- a/x.py +++ b/x.py @@ -125,6 +125,15 @@ def update_windows(): .replace("%%RUSTUP-SHA256%%", rustup_hash_windows("x86_64-pc-windows-msvc")) write_file(f"{rust_version}/windowsservercore-{version}/msvc/Dockerfile", rendered) + template = read_file("Dockerfile-windows-gnu.template") + for version, build in windows_servercore_versions: + rendered = template \ + .replace("%%RUST-VERSION%%", rust_version) \ + .replace("%%RUSTUP-VERSION%%", rustup_version) \ + .replace("%%WINDOWS-VERSION%%", version) \ + .replace("%%RUSTUP-SHA256%%", rustup_hash_windows("x86_64-pc-windows-msvc")) + write_file(f"{rust_version}/windowsservercore-{version}/gnu/Dockerfile", rendered) + def update_github_actions(): file = ".github/workflows/build-images.yml" config = read_file(file) @@ -149,6 +158,11 @@ def update_github_actions(): versions += f" os: windows-2019\n" versions += f" version: {rust_version}\n" + for version, build in windows_servercore_versions: + versions += f" - variant: windowsservercore-{version}/gnu\n" + versions += f" os: windows-2019\n" + versions += f" version: {rust_version}\n" + marker = "#VERSIONS\n" split = config.split(marker) @@ -232,6 +246,17 @@ def generate_stackbrew_library(): map(lambda a: a.bashbrew, alpine_arches), os.path.join(rust_version, f"alpine{version}")) + for version, build in windows_servercore_versions: + tags = [] + for version_tag in version_tags(): + tags.append(f"{version_tag}-windowsservercore-{version}-gnu") + tags.append(f"windowsservercore-{version}-gnu") + + library += single_library( + tags, + ["x86_64"], + os.path.join(rust_version, f"windowsservercore-{version}", "gnu")) + print(library) def usage():