Skip to content

Commit 37d65eb

Browse files
committed
Compress with ZSTD to optimize layers for size, go with all cores and default compression level but make it possible to override compression flags for CI, create unpack.ps1 which should be used at first container run
1 parent 77092c4 commit 37d65eb

File tree

2 files changed

+76
-11
lines changed

2 files changed

+76
-11
lines changed

Dockerfile

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ ARG PYTHON_VERSION=3.13.2
77
ARG NINJA_VERSION=1.12.1
88
ARG NASM_VERSION=2.16.03
99
ARG GIT_VERSION=2.48.1
10+
ARG ZSTD_VERSION=1.5.7
1011
ARG WINDOWS_11_SDK_VERSION=22621
1112
ARG WINDOWS_SDK_VERSION=10.0.${WINDOWS_11_SDK_VERSION}.0
1213
ARG VC_VERSION=14.43.17.13
14+
ARG VS_BOOTSTRAP_VERSION=17.13.6
1315

1416
# note: it seems we cannot pass version within any workflow ID to installer, though as I look at VS package cache I see it being done in json payloads!
1517
# henceforth we enforce fixed versions with nasty bootstrap URL, more details:
1618
# https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history#fixed-version-bootstrappers
17-
# Default Version: 17.13.6, Channel: Current
19+
20+
# note: if you update BUILD_TOOLS_URL then update also VS_BOOTSTRAP_VERSION
21+
# default version: ${VS_BOOTSTRAP_VERSION}, channel: Current
22+
# UPDAT ME: need to find out if there is a way to use VS_BOOTSTRAP_VERSION instead of this nasty URL which matches the bootstrap version
1823
ARG BUILD_TOOLS_URL=https://download.visualstudio.microsoft.com/download/pr/8fada5c7-8417-4239-acc3-bd499af09222/353141457abcc59eb9c38b2f30084e7271c6bcfb4e185466d98161bada905759/vs_BuildTools.exe
1924

2025
# used for validation & matches internal package payloads, note: requires adjusting BUILD_TOOLS_URL
2126
ARG MSVC_VERSION=14.43.34808
2227
ARG CLANGCL_VERSION=19.1.1
2328

2429
ARG IMPL_ARTIFACTS_DIR="C:\artifacts"
30+
ARG IMPL_COMPRESSION_ARGS=-T0
31+
2532
ARG IMPL_NANO_BASE=mcr.microsoft.com/powershell
2633
ARG IMPL_NANO_TAG=lts-nanoserver-ltsc2022
2734

@@ -56,8 +63,9 @@ SHELL ["powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Co
5663
# eg. dir name: 14.43.34808 (MSVC_VERSION) but version reported by cl.exe: 19.43.34810
5764
# more over, all package cache payloads (by default at C:\ProgramData\Microsoft\VisualStudio)
5865
# use MSVC_VERSION within workflow components ID - none of them contains 19.43.34810
59-
# which means that most likely there is a bug with versioning cl binaries
6066

67+
# UPDATE ME: once I know more about CL versioning
68+
#
6169
# RUN $version = "$env:MSVC_VERSION" ; `
6270
# $cl = Join-Path $env:IMPL_ARTIFACTS_DIR "VC\Tools\MSVC\$version\bin\Hostx64\x64\cl.exe" ; `
6371
# $pipe = & "$cl" 2>&1 ; `
@@ -151,19 +159,55 @@ Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download
151159
tar -xf C:\Temp\git.zip -C $env:IMPL_ARTIFACTS_DIR ; `
152160
Remove-Item C:\Temp\git.zip
153161

162+
# ---------------- ZSTD ----------------
163+
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as zstd
164+
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
165+
166+
ARG ZSTD_VERSION
167+
ARG IMPL_ARTIFACTS_DIR
168+
169+
RUN Write-Host "Installing Git $env:ZSTD_VERSION" ; `
170+
New-Item -ItemType Directory -Force -Path C:\Temp, $env:IMPL_ARTIFACTS_DIR ; `
171+
Invoke-WebRequest -Uri "https://github.com/facebook/zstd/releases/download/v$env:ZSTD_VERSION/zstd-v$env:ZSTD_VERSION-win64.zip" -OutFile C:\Temp\zstd.zip ; `
172+
tar -xf C:\Temp\zstd.zip -C $env:IMPL_ARTIFACTS_DIR ; `
173+
Remove-Item C:\Temp\zstd.zip
174+
175+
# ---------------- COMPRESS STEP ----------------
176+
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as compress
177+
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
178+
179+
ARG IMPL_ARTIFACTS_DIR
180+
COPY --link --from=buildtools ["C:/Program Files (x86)/Windows Kits/10", "C:/pack/WindowsKits10SDK"]
181+
COPY --link --from=buildtools ["${IMPL_ARTIFACTS_DIR}", "C:/pack/BuildTools"]
182+
COPY --link --from=cmake ["${IMPL_ARTIFACTS_DIR}", "C:/pack/CMake"]
183+
COPY --link --from=python ["${IMPL_ARTIFACTS_DIR}", "C:/pack/Python"]
184+
COPY --link --from=ninja ["${IMPL_ARTIFACTS_DIR}", "C:/pack/Ninja"]
185+
COPY --link --from=nasm ["${IMPL_ARTIFACTS_DIR}", "C:/pack/Nasm"]
186+
COPY --link --from=git ["${IMPL_ARTIFACTS_DIR}", "C:/pack/Git"]
187+
COPY --link --from=zstd ["${IMPL_ARTIFACTS_DIR}", "C:/compress"]
188+
189+
ARG ZSTD_VERSION
190+
ARG IMPL_COMPRESSION_ARGS
191+
192+
WORKDIR C:\pack
193+
RUN $dirs = Get-ChildItem -Directory | ForEach-Object { $_.Name }; $dirs; `
194+
tar -cf artifacts.tar @dirs; dir artifacts.tar; `
195+
& "C:\compress\zstd-v$env:ZSTD_VERSION-win64\zstd.exe" $env:IMPL_COMPRESSION_ARGS artifacts.tar; dir artifacts.tar.zst; `
196+
rm artifacts.tar
197+
154198
# ---------------- FINAL IMAGE ----------------
155199
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG}
156200
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
157201
USER ContainerAdministrator
158202

203+
LABEL org.opencontainers.image.title="MSVC & ClangCL Build Tools with CMake toolchains"
204+
LABEL org.opencontainers.image.source=https://github.com/Devsh-Graphics-Programming/docker-nanoserver-msvc-winsdk
205+
LABEL org.opencontainers.image.description="Build MSVC/ClangCL + WinSDK projects with CMake toolchains in Windows Nano Server!"
206+
LABEL org.opencontainers.image.licenses=Apache-2.0
207+
159208
ARG IMPL_ARTIFACTS_DIR
160-
COPY --link --from=buildtools ["C:/Program Files (x86)/Windows Kits/10", "C:/WindowsKits10SDK"]
161-
COPY --link --from=buildtools ["${IMPL_ARTIFACTS_DIR}", "C:/BuildTools"]
162-
COPY --link --from=cmake ["${IMPL_ARTIFACTS_DIR}", "C:/CMake"]
163-
COPY --link --from=python ["${IMPL_ARTIFACTS_DIR}", "C:/Python"]
164-
COPY --link --from=ninja ["${IMPL_ARTIFACTS_DIR}", "C:/Ninja"]
165-
COPY --link --from=nasm ["${IMPL_ARTIFACTS_DIR}", "C:/Nasm"]
166-
COPY --link --from=git ["${IMPL_ARTIFACTS_DIR}", "C:/Git"]
209+
COPY --link --from=compress ["C:/pack/artifacts.tar.zst", "C:/artifacts.tar.zst"]
210+
COPY --link --from=zstd ["${IMPL_ARTIFACTS_DIR}", "C:/compress"]
167211

168212
ARG CMAKE_VERSION
169213
ARG PYTHON_VERSION
@@ -176,6 +220,8 @@ ARG VC_VERSION
176220
ARG MSVC_VERSION
177221
ARG CLANGCL_VERSION
178222
ARG BUILD_TOOLS_URL
223+
ARG VS_BOOTSTRAP_VERSION
224+
ARG ZSTD_VERSION
179225

180226
ENV CMAKE_WINDOWS_KITS_10_DIR="C:\WindowsKits10SDK" `
181227
CMAKE_VERSION=${CMAKE_VERSION} `
@@ -190,11 +236,12 @@ VS_INSTANCE_LOCATION=C:\BuildTools `
190236
MSVC_VERSION=${MSVC_VERSION} `
191237
CLANGCL_VERSION=${CLANGCL_VERSION} `
192238
BUILD_TOOLS_URL=${BUILD_TOOLS_URL} `
239+
VS_BOOTSTRAP_VERSION=${VS_BOOTSTRAP_VERSION} `
193240
MSVC_TOOLSET_DIR=C:\BuildTools\VC\Tools\MSVC\${MSVC_VERSION} `
194241
LLVM_TOOLSET_DIR=C:\BuildTools\VC\Tools\Llvm `
195-
PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Git\cmd;C:\Git\bin;C:\Git\usr\bin;C:\Git\mingw64\bin;C:\CMake\cmake-${CMAKE_VERSION}-windows-x86_64\bin;C:\Python;C:\Nasm;C:\Nasm\nasm-${NASM_VERSION};C:\Ninja;"
242+
PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Git\cmd;C:\Git\bin;C:\Git\usr\bin;C:\Git\mingw64\bin;C:\CMake\cmake-${CMAKE_VERSION}-windows-x86_64\bin;C:\Python;C:\Nasm;C:\Nasm\nasm-${NASM_VERSION};C:\Ninja;C:\compress\zstd-v${ZSTD_VERSION}-win64;"
196243

197-
RUN git config --system --add safe.directory '*'
198244
COPY . sample/
245+
COPY unpack.ps1 .
199246
WORKDIR C:\sample\tests
200247
CMD ["pwsh.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass"]

unpack.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$oldLocation = Get-Location
2+
try {
3+
Set-Location -Path 'C:\'
4+
5+
if (Test-Path -Path 'artifacts.tar.zst') {
6+
if (-not (Test-Path -Path 'artifacts.tar')) {
7+
& zstd -d -T0 artifacts.tar.zst -o artifacts.tar
8+
}
9+
tar -xf artifacts.tar
10+
}
11+
12+
Remove-Item -Path 'artifacts.tar' -ErrorAction SilentlyContinue
13+
Remove-Item -Path 'artifacts.tar.zst' -ErrorAction SilentlyContinue
14+
dir
15+
}
16+
finally {
17+
Set-Location -Path $oldLocation
18+
}

0 commit comments

Comments
 (0)