33# [run] docker run -it --rm bitbishop-windows
44# NOTE: Before trying to build this dockerfile, ensure docker engine runs in windows container mode
55
6- FROM mcr.microsoft.com/windows/servercore:ltsc2022
7-
8- # Configure PowerShell as the default shell with strict error handling
9- # - PowerShell is more powerful than cmd for scripting and package management
10- # - $ErrorActionPreference = 'Stop' ensures the build fails on any error (critical for CI/CD)
11- # - $ProgressPreference = 'SilentlyContinue' suppresses progress bars that can clutter build logs
12- SHELL ["C:\\ Windows\\ System32\\ WindowsPowerShell\\ v1.0\\ powershell.exe" , "-Command" , "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
13-
14- # Install Chocolatey package manager
15- # - Chocolatey is the standard package manager for Windows, similar to apt/yum on Linux
16- # - Set-ExecutionPolicy Bypass allows script execution for this process only (security)
17- # - SecurityProtocol 3072 = TLS 1.2, required for secure HTTPS downloads
18- # - iex (Invoke-Expression) downloads and executes the Chocolatey install script
19- RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
20- [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
21- iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1' ))
22-
23- # Install core build dependencies via Chocolatey
24- # - git: version control, required to clone vcpkg and project repositories
25- # - cmake: cross-platform build system generator, industry standard for C++ projects
26- # - ninja: fast build system, alternative to MSBuild, preferred for faster compilation
27- # - zip: archive utility, often needed for packaging and handling compressed files
28- # - llvm: compiler infrastructure including clang, useful for cross-platform builds
29- # - -y: automatic yes to prompts (non-interactive installation for Docker builds)
30- # NOTE: Installing each tool separately ensures proper PATH registration
31- RUN choco install -y git
6+ # Use the official GitHub Actions Windows runner image
7+ # This image already has most development tools pre-installed:
8+ # - Chocolatey
9+ # - Git
10+ # - Visual Studio Build Tools
11+ # - Windows SDK
12+ # - PowerShell
13+ # - And many more tools commonly used in CI/CD
14+ FROM ghcr.io/actions/actions-runner:windows-2025
15+
16+ # Switch to PowerShell with strict error handling
17+ SHELL ["powershell" , "-Command" , "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
18+
19+ # Install additional tools not included in the base image
20+ # CMake, Ninja, and LLVM are needed for your C++ builds
3221RUN choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
3322RUN choco install -y ninja
34- RUN choco install -y zip
3523RUN choco install -y llvm
3624
37- # Update PATH environment variable to make installed tools accessible
38- # CRITICAL: Must use [Environment]::SetEnvironmentVariable to persist changes to the system
39- # This ensures PATH modifications survive container restarts and are available at runtime
40- # - Machine scope: system-wide PATH that persists across sessions
41- RUN [Environment]::SetEnvironmentVariable('PATH' , \
42- \" C:\\ Windows\\ System32\\ WindowsPowerShell\\ v1.0;\" + \
43- \" C:\\ Program Files\\ Git\\ cmd;\" + \
44- \" C:\\ Program Files\\ CMake\\ bin;\" + \
45- \" C:\\ ProgramData\\ chocolatey\\ bin;\" + \
46- \" C:\\ Tools\\ ninja;\" + \
47- \" C:\\ Program Files\\ LLVM\\ bin;\" + \
48- $env:PATH, \
49- [EnvironmentVariableTarget]::Machine)
50-
51- # Refresh the current session's PATH to include newly installed tools
52- # This is necessary for subsequent RUN commands in the Dockerfile
53- RUN refreshenv; \
54- $env:PATH = [System.Environment]::GetEnvironmentVariable('PATH' ,'Machine' )
25+ # Refresh environment to ensure newly installed tools are in PATH
26+ RUN refreshenv
5527
56- # Install Visual Studio Build Tools 2022
57- # This provides the MSVC compiler toolchain required for building native Windows C++ applications
58- # - Invoke-WebRequest: downloads the VS Build Tools installer
59- # - Start-Process with -Wait: ensures installation completes before proceeding
60- # - --quiet --wait --norestart --nocache: silent, synchronous install without restart or cache
61- #
62- # Component selection rationale:
63- # - Microsoft.VisualStudio.Workload.VCTools:
64- # Core C++ build tools workload (compilers, libraries, build tools)
65- # - Microsoft.VisualStudio.Component.Windows11SDK.22000:
66- # Windows 11 SDK (22000 = version 10.0.22000.0), provides Windows API headers and libraries
67- # Note: Compatible with Windows 10 projects as well, backward compatible
68- # - Microsoft.VisualStudio.Component.VC.Tools.x86.x64:
69- # MSVC v143 compiler toolset for x86 and x64 (both 32-bit and 64-bit compilation)
70- # - --includeRecommended:
71- # Adds recommended components for selected workloads (debuggers, profilers, etc.)
72- #
73- # Remove installer after completion to reduce image size
74- RUN Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -OutFile vs_buildtools.exe; \
75- Start-Process -FilePath .\v s_buildtools.exe -ArgumentList '--quiet' , '--wait' , '--norestart' , '--nocache' , \
76- '--add' , 'Microsoft.VisualStudio.Workload.VCTools' , \
77- '--add' , 'Microsoft.VisualStudio.Component.Windows11SDK.22000' , \
78- '--add' , 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64' , \
79- '--includeRecommended' \
80- -NoNewWindow -Wait; \
81- Remove-Item vs_buildtools.exe -Force
82-
83- # Clone the vcpkg C++ package manager
84- # - vcpkg is Microsoft's cross-platform C++ package manager
85- # - Cloning from GitHub ensures we get the latest version with all port definitions
86- # - C:\vcpkg: standard installation location, commonly used in documentation
28+ # Clone and bootstrap vcpkg
29+ # vcpkg is Microsoft's C++ package manager
8730RUN git clone https://github.com/microsoft/vcpkg.git C:\v cpkg
8831
89- # Bootstrap vcpkg - this step requires special shell handling
90- # WHY SHELL SWITCH IS NECESSARY:
91- # - bootstrap-vcpkg.bat is a Windows batch script that internally calls powershell.exe
92- # - When executed from PowerShell context, it cannot find powershell.exe in its environment
93- # - cmd.exe provides the native environment where batch scripts expect to run
94- # - The batch script will successfully locate and execute powershell.exe from PATH
95- #
96- # - /S /C: cmd switches for silent execution and command execution
97- # - -disableMetrics: opts out of vcpkg telemetry collection
32+ # Bootstrap vcpkg using cmd shell (required for batch script)
9833SHELL ["cmd" , "/S" , "/C" ]
9934RUN C:\v cpkg\b ootstrap-vcpkg.bat -disableMetrics
10035
101- # Switch back to PowerShell for remaining operations
102- # PowerShell is preferred for its superior scripting capabilities and error handling
103- SHELL ["C:\\ Windows\\ System32\\ WindowsPowerShell\\ v1.0\\ powershell.exe" , "-Command" , "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
36+ # Switch back to PowerShell
37+ SHELL ["powershell" , "-Command" , "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
10438
10539# Configure vcpkg environment variables
106- # - VCPKG_ROOT: tells tools where vcpkg is installed (standard vcpkg convention)
107- # - VCPKG_FEATURE_FLAGS: enables advanced vcpkg features
108- # * manifest: enables vcpkg.json manifest mode for declarative dependency management
109- # * binarycaching: enables binary package caching to speed up builds
110- # - VCPKG_BINARY_SOURCES: configures where binary cache is stored
111- # * clear: clears any inherited cache configuration
112- # * files: uses local filesystem cache (C:\vcpkg\binarycache)
113- # NOTE: x-gha backend has been removed, using local file cache instead
11440ENV VCPKG_ROOT="C:\\ vcpkg"
11541ENV VCPKG_FEATURE_FLAGS="manifest,binarycaching"
11642ENV VCPKG_BINARY_SOURCES="clear;files,C:\\ vcpkg\\ binarycache,readwrite"
11743
11844# Create binary cache directory
11945RUN New-Item -ItemType Directory -Path C:\v cpkg\b inarycache -Force
12046
121- # Final PATH configuration with all build tools
122- # Add VS Build Tools and vcpkg to the system PATH
123- # This ensures all tools are available when the container starts
124- # CRITICAL: Include MSVC compiler binaries for ninja/cmake to find cl.exe
125- RUN $vsPath = (Get-ChildItem 'C:\P rogram Files (x86)\M icrosoft Visual Studio\2 022\B uildTools\V C\T ools\M SVC' | Select-Object -Last 1).FullName; \
126- [Environment]::SetEnvironmentVariable('PATH' , \
127- \" C:\\ Program Files (x86)\\ Microsoft Visual Studio\\ 2022\\ BuildTools\\ Common7\\ Tools;\" + \
128- \" $vsPath\\ bin\\ Hostx64\\ x64;\" + \
129- \" C:\\ Program Files (x86)\\ Microsoft Visual Studio\\ 2022\\ BuildTools\\ Common7\\ IDE\\ CommonExtensions\\ Microsoft\\ CMake\\ Ninja;\" + \
130- \" C:\\ vcpkg;\" + \
131- [System.Environment]::GetEnvironmentVariable('PATH' ,'Machine' ), \
132- [EnvironmentVariableTarget]::Machine)
133-
134- # Set up MSVC environment variables required for compilation
135- # These environment variables are normally set by vcvarsall.bat or VsDevCmd.bat
136- # Setting them explicitly ensures cmake/ninja can find and use the MSVC toolchain
137- RUN $vsPath = (Get-ChildItem 'C:\P rogram Files (x86)\M icrosoft Visual Studio\2 022\B uildTools\V C\T ools\M SVC' | Select-Object -Last 1).FullName; \
138- $sdkPath = 'C:\P rogram Files (x86)\W indows Kits\1 0' ; \
139- $sdkVersion = (Get-ChildItem \" $sdkPath\I nclude\" | Select-Object -Last 1).Name; \
140- [Environment]::SetEnvironmentVariable('INCLUDE' , \
141- \" $vsPath\\ include;\" + \
142- \" $sdkPath\\ Include\\ $sdkVersion\\ ucrt;\" + \
143- \" $sdkPath\\ Include\\ $sdkVersion\\ um;\" + \
144- \" $sdkPath\\ Include\\ $sdkVersion\\ shared\" , \
145- [EnvironmentVariableTarget]::Machine); \
146- [Environment]::SetEnvironmentVariable('LIB' , \
147- \" $vsPath\\ lib\\ x64;\" + \
148- \" $sdkPath\\ Lib\\ $sdkVersion\\ ucrt\\ x64;\" + \
149- \" $sdkPath\\ Lib\\ $sdkVersion\\ um\\ x64\" , \
150- [EnvironmentVariableTarget]::Machine); \
151- [Environment]::SetEnvironmentVariable('LIBPATH' , \
152- \" $vsPath\\ lib\\ x64;\" + \
153- \" $sdkPath\\ UnionMetadata\\ $sdkVersion;\" + \
154- \" $sdkPath\\ References\\ $sdkVersion\" , \
47+ # Create custom vcpkg triplet that uses MSBuild instead of Ninja
48+ # This avoids rc.exe access violations in Windows Server Core containers
49+ RUN New-Item -ItemType Directory -Path C:\v cpkg\t riplets\c ommunity -Force
50+ RUN $content = @(); \
51+ $content += 'set(VCPKG_TARGET_ARCHITECTURE x64)' ; \
52+ $content += 'set(VCPKG_CRT_LINKAGE dynamic)' ; \
53+ $content += 'set(VCPKG_LIBRARY_LINKAGE dynamic)' ; \
54+ $content += 'set(VCPKG_CMAKE_GENERATOR \" Visual Studio 17 2022\" )' ; \
55+ $content += 'set(VCPKG_PLATFORM_TOOLSET v143)' ; \
56+ $content | Out-File -FilePath C:\v cpkg\t riplets\c ommunity\x 64-windows-msbuild.cmake -Encoding ASCII
57+
58+ # Set the custom triplet as default
59+ ENV VCPKG_DEFAULT_TRIPLET="x64-windows-msbuild"
60+
61+ # Add vcpkg to PATH
62+ RUN [Environment]::SetEnvironmentVariable('PATH' , \
63+ 'C:\v cpkg;' + [System.Environment]::GetEnvironmentVariable('PATH' ,'Machine' ), \
15564 [EnvironmentVariableTarget]::Machine)
15665
157- # Set working directory for when container starts
158- # C:\workspace is a conventional location for build operations
66+ # Set working directory
15967WORKDIR C:\\ workspace
16068
161- COPY . .
162-
163- # Default command when container starts
164- # PowerShell provides better interactive experience and scripting capabilities than cmd
69+ # Default command
16570CMD ["powershell.exe" ]
0 commit comments