1+ # Use Windows Server Core as the base image
2+ FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS builder
3+
4+ # Define build arguments
5+ ARG VERSION="latest"
6+
7+ # Set PowerShell as the default shell
8+ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
9+
10+ # Set working directory
11+ WORKDIR C:/build
12+
13+ # Install Chocolatey package manager
14+ RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
15+ [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
16+ iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
17+
18+ # Install required tools
19+ RUN choco install -y git php composer visualstudio2022buildtools visualstudio2022-workload-vctools
20+
21+ # Create build directories
22+ RUN mkdir -p .build/phar .build/bin
23+
24+ # Download box tool for PHAR creation
25+ RUN Invoke-WebRequest -Uri "https://github.com/box-project/box/releases/download/4.6.6/box.phar" -OutFile ".build/bin/box.phar"
26+
27+ # Download static-php-cli for Windows
28+ RUN Invoke-WebRequest -Uri "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe" -OutFile ".build/bin/spc.exe"
29+
30+ # Download required PHP extensions
31+ RUN .build/bin/spc.exe download micro `
32+ --for-extensions=ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl `
33+ --with-php=8.3 `
34+ --prefer-pre-built
35+
36+ # Install UPX for compression
37+ RUN .build/bin/spc.exe install-pkg upx
38+
39+ # Verify environment is ready
40+ RUN .build/bin/spc.exe doctor --auto-fix
41+
42+ # Build the self-executable binary with required extensions
43+ RUN .build/bin/spc.exe build "ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl" `
44+ --build-micro `
45+ --with-upx-pack
46+
47+ # Default command to display info
48+ CMD ["echo", "PHP Builder image is ready for use"]
0 commit comments