-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile.windows
More file actions
123 lines (98 loc) · 5.15 KB
/
Dockerfile.windows
File metadata and controls
123 lines (98 loc) · 5.15 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# escape=`
# Stage 1: Bootstrap - development environment only (VS, SDK, tools)
FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS bootstrap
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Install Chocolatey with non-interactive settings
ENV CHOCO NON_INTERACTIVE=1
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
[System.Environment]::SetEnvironmentVariable('ChocolateyInstall', 'C:\ProgramData\chocolatey', 'Machine'); `
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); `
$env:PATH = $env:PATH + ';' + [System.Environment]::GetEnvironmentVariable('PATH','Machine');
# Install PowerShell Core and Git
RUN choco install -y --no-progress git powershell-core
# Set up PATH for PowerShell Core
ENV PATH="C:\Program Files\PowerShell\7;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;${PATH}"
# Create workspace directory and configure git
RUN New-Item -ItemType Directory -Force -Path C:\workspace; `
git config --global core.autocrlf false; `
git config --global core.eol lf; `
git config --global core.longpaths true; `
git config --global --add safe.directory C:\workspace\bun;
# Clone Bun repository to get bootstrap script
WORKDIR C:\workspace
RUN git clone https://github.com/oven-sh/bun.git C:\workspace\bun
WORKDIR C:\workspace\bun
# Bust cache if bootstrap script changes
ARG BOOTSTRAP_HASH=unknown
RUN Write-Host "Bootstrap hash: $env:BOOTSTRAP_HASH"
# Run bootstrap with minimal patches - just fix what breaks in containers
RUN git pull; `
$bootstrapPath = '.\scripts\bootstrap.ps1'; `
$content = Get-Content $bootstrapPath -Raw; `
$content = $content -replace '"--passive"', '"--quiet"'; `
Set-Content -Path $bootstrapPath -Value $content; `
pwsh -ExecutionPolicy Bypass -File $bootstrapPath -Optimize:$false; `
git checkout $bootstrapPath; `
refreshenv;
# Install additional VS components that --includeRecommended doesn't include in containers
RUN & 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' modify `
--installPath 'C:\Program Files\Microsoft Visual Studio\2022\Community' `
--add Microsoft.VisualStudio.Component.Windows11SDK.22621 `
--add Microsoft.VisualStudio.Component.Windows10SDK `
--quiet --norestart --wait; `
refreshenv;
# Reload environment and add SDK bin to PATH
RUN $sdkBin = Get-ChildItem 'C:\Program Files (x86)\Windows Kits' -Recurse -Filter 'rc.exe' -ErrorAction SilentlyContinue | `
Where-Object { $_.Directory.Name -eq 'x64' } | `
Select-Object -First 1 | ForEach-Object { $_.Directory.FullName }; `
if ($sdkBin) { [System.Environment]::SetEnvironmentVariable('SDK_BIN', $sdkBin, 'Machine') }; `
refreshenv;
# Add SDK bin to PATH via ENV so CMake can find rc.exe and mt.exe
ENV PATH="${SDK_BIN};${PATH}"
ENV BUN_NO_CORE_DUMP=1
# Stage 2: Base - bootstrap environment + specific Bun commit
FROM bootstrap AS base
# Bust cache when Bun code changes
ARG GIT_SHA=unknown
RUN Write-Host "Bun SHA: $env:GIT_SHA"
WORKDIR C:\workspace\bun
# Update to specific commit
RUN git pull
# Pre-install the repo-pinned Rust toolchain. bootstrap.ps1 installed rustup
# with a stable default; when rust-toolchain.toml is present (the Rust port)
# invoking cargo via the rustup proxy here pulls the exact pinned nightly +
# components + targets into the image so the build step doesn't re-download.
# No-op on refs without rust-toolchain.toml. ErrorActionPreference is relaxed
# for this block because rustup writes progress to stderr, which Windows
# PowerShell 5.1 otherwise promotes to a terminating error.
RUN $ErrorActionPreference = 'Continue'; `
$env:PATH = $env:PATH + ';' + [System.Environment]::GetEnvironmentVariable('PATH','Machine'); `
if (Test-Path rust-toolchain.toml) { `
cargo --version; `
rustup component add rustfmt clippy rust-src; `
rustup show; `
}
# Stage 3: Prebuilt - base + built Bun binary
FROM base AS prebuilt
# Set build environment variables for Windows
ENV ENABLE_ZIG_ASAN=0
ENV BUN_DEBUG_QUIET_LOGS=1
ENV BUN_GARBAGE_COLLECTOR_LEVEL=0
ENV BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING=1
# Build Bun
RUN $env:PATH = $env:PATH + ';' + [System.Environment]::GetEnvironmentVariable('PATH','Machine') + ';C:\Users\ContainerAdministrator\.bun\bin'; `
bun run build; `
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue C:\Users\ContainerAdministrator\AppData\Local\Temp\*;
# Test that the binary works
RUN C:\workspace\bun\build\debug\bun-debug.exe --version
CMD ["powershell.exe"]
# Minimal stage for extracting build artifacts
# Note: Windows doesn't support FROM scratch, so we use the base Windows image
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 AS artifacts
COPY --from=prebuilt C:\workspace\bun\build C:\build
FROM prebuilt as run
RUN New-Item -ItemType Directory -Force -Path C:\workspace\cwd
VOLUME C:\workspace\cwd
WORKDIR C:\workspace\cwd
ENTRYPOINT ["C:\\workspace\\bun\\build\\debug\\bun-debug.exe"]