Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
80 lines (70 loc) · 4.18 KB
/
Copy pathDockerfile
File metadata and controls
80 lines (70 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# escape=`
#
# Builds zlib on Windows (zlib.dll + import lib, and the static zlibstatic.lib)
# and packages the headers + binaries into zip files that FreeSWITCH's Windows
# build consumes -- the same zips the GitHub Actions workflow produces.
#
# This image only contains the TOOLCHAIN. The actual zlib version is built at
# `docker run` time from an env var, so you can produce a new release without
# rebuilding the (slow, multi-GB) toolchain layer.
#
# Build the toolchain image once:
# docker build -t zlib-packaging .
#
# Produce zips for a zlib release (writes to .\artifacts on the host):
# docker run --rm --cpus 4 --memory 4g `
# -e ZLIB_VERSION=1.3.2 `
# -v ${PWD}\artifacts:C:\artifacts `
# zlib-packaging
#
# Requires Windows containers. The host must be able to run a Windows base image
# of an equal-or-older build than the host (process isolation), otherwise run
# with `--isolation=hyperv`.
ARG WINDOWS_BASE=mcr.microsoft.com/windows/servercore:ltsc2025
FROM ${WINDOWS_BASE}
# The Visual Studio bootstrapper. aka.ms/vs/17/release installs the latest VS 2022
# Build Tools.
ARG VS_BOOTSTRAPPER_URL=https://aka.ms/vs/17/release/vs_buildtools.exe
SHELL ["powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue';"]
# ---------------------------------------------------------------------------
# 1. Chocolatey + CMake (zlib's build system; build-zlib.ps1 drives it with the
# "NMake Makefiles" generator from inside the VC environment).
# tar.exe (for unpacking the source tarball) ships with the base image.
# ---------------------------------------------------------------------------
RUN [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; `
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
RUN choco install -y --no-progress cmake --installargs 'ADD_CMAKE_TO_SYSTEM_PATH=System'; `
if ($LASTEXITCODE -ne 0) { throw "choco install failed ($LASTEXITCODE)" }; `
if (-not (Test-Path 'C:\Program Files\CMake\bin\cmake.exe')) { throw 'cmake.exe not found after install' }; `
& 'C:\Program Files\CMake\bin\cmake.exe' --version
# ---------------------------------------------------------------------------
# 2. Visual Studio 2022 Build Tools: the C++ workload (MSVC v143 + Windows SDK +
# nmake + rc). build-zlib.ps1 enters this environment via vcvarsall.bat.
# Exit code 3010 == success-but-reboot-required, which is fine in an image.
# ---------------------------------------------------------------------------
RUN Invoke-WebRequest -Uri $env:VS_BOOTSTRAPPER_URL -OutFile C:\vs_buildtools.exe; `
Write-Host 'Installing Visual Studio Build Tools (this takes a while)...'; `
$p = Start-Process -FilePath C:\vs_buildtools.exe -Wait -PassThru -ArgumentList `
'--quiet','--wait','--norestart','--nocache', `
'--installPath','C:\BuildTools', `
'--add','Microsoft.VisualStudio.Workload.VCTools', `
'--includeRecommended'; `
if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) { throw "VS Build Tools install failed ($($p.ExitCode))" }; `
Remove-Item C:\vs_buildtools.exe -Force
# ---------------------------------------------------------------------------
# 3. Build driver.
# ---------------------------------------------------------------------------
COPY build-zlib.ps1 C:\build-zlib.ps1
# Defaults; override any of these with `docker run -e ...`.
ENV ZLIB_VERSION=1.3.2 `
CONFIGS="Release Debug" `
PLATFORMS="x64" `
PKG_PREFIX=zlib `
OUT_DIR=C:\artifacts `
ZLIB_BUILD_ROOT=C:\zb
# NOTE: do NOT set `ENV PATH` here -- the Windows base image exports the variable
# as `Path` (mixed case) and Docker's ${...} substitution is case-sensitive, so
# `${PATH}` would expand to empty and wipe System32 from the path. The installers
# register their dirs in the machine PATH (which container processes inherit), and
# build-zlib.ps1 prepends the CMake dir defensively at runtime.
ENTRYPOINT ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\build-zlib.ps1"]