1- # escape=`
2- # Windows-based Dockerfile for OpenList
3- # Build stage using official Golang image
4- # Runtime stage using Windows Server Nano
1+ ARG WINDOWS_VERSION=ltsc2022
2+ FROM mcr.microsoft.com/windows/servercore:${WINDOWS_VERSION} AS frontend
3+ # Use PowerShell as the default shell
4+ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
5+ WORKDIR C:/app/frontend
6+ # Install Node.js
7+ RUN Invoke-WebRequest -Uri https://nodejs.org/dist/v25.1.0/node-v25.1.0-x64.msi -OutFile C:/nodejs.msi
8+ RUN Start-Process msiexec.exe -ArgumentList '/i C:\\nodejs.msi /quiet /norestart' -Wait
9+ RUN Remove-Item C:/nodejs.msi -Force
10+ RUN node --version
11+ # Install Git
12+ RUN Invoke-WebRequest -Uri https://github.com/git-for-windows/git/releases/download/v2.51.2.windows.1/Git-2.51.2-64-bit.exe -OutFile C:/gitinstaller.exe
13+ RUN Start-Process -FilePath "C:/gitinstaller.exe" -ArgumentList '/VERYSILENT', '/NORESTART', '/NOCANCEL', '/SP-', '/CLOSEAPPLICATIONS' -Wait
14+ RUN Remove-Item C:/gitinstaller.exe -Force
15+ RUN git --version
16+ # Install pnpm
17+ RUN npm install -g pnpm
18+ # Clone the frontend source code
19+ RUN git clone --depth 1 --branch main https://github.com/nbtca/OpenList-Frontend
20+
21+ # Install frontend dependencies and build
22+ WORKDIR C:/app/frontend/OpenList-Frontend
23+ RUN pnpm install
24+ RUN pnpm run build
25+
526
627# Build stage
7- FROM golang:1.25.3 -windowsservercore-ltsc2025 AS builder
28+ FROM golang:1.25-windowsservercore-${WINDOWS_VERSION} AS builder
829
930SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
1031
1132WORKDIR C:/app
1233
13- # 安装 7-Zip
14- RUN Invoke-WebRequest -Uri https://www.7-zip.org/a/7z2501-x64.msi -OutFile C:\7zip.msi
15- RUN Start-Process msiexec.exe -ArgumentList '/i C:\7zip.msi /quiet /norestart' -Wait
16- RUN Remove-Item C:\7zip.msi -Force
17-
18- # Install MinGW-w64 for CGO support
19- RUN Invoke-WebRequest -Uri https://github.com/niXman/mingw-builds-binaries/releases/download/15.2.0-rt_v13-rev0/x86_64-15.2.0-release-posix-seh-msvcrt-rt_v13-rev0.7z -OutFile C:/mingw.7z
20- # Extract to C:\
21- RUN & 'C:\Program Files\7-Zip\7z.exe' x C:/mingw.7z -oC:\ -y
22- RUN Remove-Item C:/mingw.7z -Force
23-
24- # The archive extracts to a folder like C:\mingw64 or C:\x86_64-*\mingw64
25- # Find the actual mingw64 location and rename/move it to C:\mingw64 if needed
26- RUN $mingwPath = Get-ChildItem C:\ -Directory | Where-Object { $_.Name -like 'x86_64*' -or $_.Name -eq 'mingw64' } | Select-Object -First 1; `
27- if ($mingwPath -and $mingwPath.Name -ne 'mingw64') { `
28- Write-Host "Found MinGW at: $($mingwPath.FullName)"; `
29- if (Test-Path "$($mingwPath.FullName)\mingw64") { `
30- Write-Host "Moving nested mingw64 to C:\mingw64"; `
31- Move-Item "$($mingwPath.FullName)\mingw64" C:\mingw64 -Force; `
32- Remove-Item $mingwPath.FullName -Recurse -Force; `
33- } else { `
34- Write-Host "Renaming $($mingwPath.Name) to mingw64"; `
35- Rename-Item $mingwPath.FullName C:\mingw64 -Force; `
36- } `
37- } elseif ($mingwPath) { `
38- Write-Host "MinGW already at C:\mingw64"; `
39- } else { `
40- Write-Host "ERROR: Could not find MinGW directory"; `
41- Get-ChildItem C:\ | Select-Object Name; `
42- exit 1; `
43- }
44-
45- # Verify gcc installation exists
46- RUN if (-not (Test-Path C:\mingw64\bin\gcc.exe)) { `
47- Write-Host "ERROR: gcc.exe not found at C:\mingw64\bin\gcc.exe"; `
48- Write-Host "Contents of C:\:"; `
49- Get-ChildItem C:\ | Select-Object Name; `
50- exit 1; `
51- } else { `
52- Write-Host "Successfully found gcc at C:\mingw64\bin\gcc.exe"; `
53- }
54-
55- # Verify gcc installation with full path
56- RUN C:\mingw64\bin\gcc.exe --version
57-
58- # Set environment variables for CGO
59- ENV CGO_ENABLED=1
60- ENV GOOS=windows
61- ENV GOARCH=amd64
62- ENV CC=C:\\mingw64\\bin\\gcc.exe
63- ENV CXX=C:\\mingw64\\bin\\g++.exe
64- # Add MinGW to PATH
65- RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\mingw64\bin', [EnvironmentVariableTarget]::Machine)
66-
6734COPY go.mod .
6835COPY go.sum .
6936# Download dependencies
7037RUN go mod download
7138
39+ # 安装 7-Zip
40+ RUN Invoke-WebRequest -Uri https://www.7-zip.org/a/7z2501-x64.msi -OutFile C:/7zip.msi
41+ RUN Start-Process msiexec.exe -ArgumentList '/i C:\\7zip.msi /quiet /norestart' -Wait
42+ RUN Remove-Item C:/7zip.msi -Force
43+
44+ # # Install MinGW-w64 for CGO support (which can not run in nanoserver)
45+ # RUN Invoke-WebRequest -Uri https://github.com/niXman/mingw-builds-binaries/releases/download/15.2.0-rt_v13-rev0/x86_64-15.2.0-release-mcf-seh-ucrt-rt_v13-rev0.7z -OutFile C:/mingw.7z; & 'C:\\Program Files\\7-Zip\\7z.exe' x C:/mingw.7z -oC:/ -y; Remove-Item C:/mingw.7z -Force
46+
47+ # Use llvm-mingw-MSVCRT version instead of UCRT
48+ RUN Invoke-WebRequest -Uri https://github.com/mstorsjo/llvm-mingw/releases/download/20251021/llvm-mingw-20251021-msvcrt-x86_64.zip -OutFile C:/mingw.zip; & 'C:\\Program Files\\7-Zip\\7z.exe' x C:/mingw.zip -oC:/ -y; Remove-Item C:/mingw.zip -Force;
49+ RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\\llvm-mingw-20251021-msvcrt-x86_64\\bin', [EnvironmentVariableTarget]::Machine)
50+
51+ # # Use MSVCRT version instead of UCRT
52+ # RUN Invoke-WebRequest -Uri https://github.com/brechtsanders/winlibs_mingw/releases/download/15.2.0posix-13.0.0-msvcrt-r2/winlibs-x86_64-posix-seh-gcc-15.2.0-mingw-w64msvcrt-13.0.0-r2.7z -OutFile C:/mingw.zip; & 'C:\\Program Files\\7-Zip\\7z.exe' x C:/mingw.zip -oC:/ -y; Remove-Item C:/mingw.zip -Force
53+ # # Add MinGW to PATH #ref https://stackoverflow.com/questions/42092932/appending-to-path-in-a-windows-docker-container
54+ # RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\\mingw64\\bin', [EnvironmentVariableTarget]::Machine)
55+
56+
57+ # Set environment variables for CGO
58+ ENV CGO_ENABLED=1
59+ # Verify gcc installation with full path
60+ RUN gcc --version
61+
7262# Copy source code
7363COPY . .
74-
64+ # Remove public\dist
65+ RUN Remove-Item public/dist -Recurse -Force
66+ # Copy built frontend assets
67+ COPY --from=frontend C:/app/frontend/OpenList-Frontend/dist ./public/dist
7568# Build the application with CGO enabled
76- RUN go build -o openlist.exe -trimpath -ldflags "-s -w -extldflags '-static'" .
69+ RUN go build -trimpath -ldflags='-s -w -extldflags \"-static\"' -o openlist.exe .
70+
71+ # # Compress using upx (optional)
72+ # RUN Invoke-WebRequest -Uri https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-win64.zip -OutFile C:/upx.zip; & 'C:\\Program Files\\7-Zip\\7z.exe' x C:/upx.zip -oC:/upx -y; Remove-Item C:/upx.zip -Force; C:/upx/upx-5.0.2-win64/upx.exe --best C:/app/openlist.exe
73+
7774# Runtime stage using Windows Server Nano
78- FROM mcr.microsoft.com/windows/nanoserver:ltsc2025
75+ # ADD https://aka.ms/vs/17/release/vc_redist.x64.exe C:/vc_redist.x64.exe
76+ # RUN C:\vc_redist.x64.exe /install /quiet /norestart
77+ # RUN Remove-Item C:/vc_redist.x64.exe -Force
78+ # RUN New-Item -ItemType Directory -Force -Path C:/vcruntime | Out-Null; \
79+ # Copy-Item -Path 'C:/Windows/System32/ucrtbase.dll' -Destination 'C:/vcruntime' -Force; \
80+ # Copy-Item -Path 'C:/Windows/System32/msvcp140.dll' -Destination 'C:/vcruntime' -Force -ErrorAction SilentlyContinue; \
81+ # Copy-Item -Path 'C:/Windows/System32/vcruntime140*.dll' -Destination 'C:/vcruntime' -Force -ErrorAction SilentlyContinue; \
82+ # Copy-Item -Path 'C:/Windows/System32/api-ms-win-crt-*.dll' -Destination 'C:/vcruntime' -Force -ErrorAction SilentlyContinue
83+
84+ # RUN Get-ChildItem -Path C:/vcruntime
85+
86+ # Directory: C:\vcruntime
87+ # Mode LastWriteTime Length Name
88+ # ---- ------------- ------ ----
89+ # -a---- 6/11/2025 5:21 AM 557728 msvcp140.dll
90+ # -a---- 10/22/2025 3:25 PM 1373304 ucrtbase.dll
91+ # -a---- 6/11/2025 5:21 AM 124544 vcruntime140.dll
92+ # -a---- 6/11/2025 5:21 AM 49792 vcruntime140_1.dll
93+ # -a---- 4/1/2024 2:59 PM 37800 vcruntime140_1_clr0400.dll
94+ # -a---- 4/1/2024 2:59 PM 98728 vcruntime140_clr0400.dll
95+ # -a---- 6/11/2025 5:21 AM 38528 vcruntime140_threads.dll
96+
97+ # FROM mcr.microsoft.com/windows/servercore:${WINDOWS_VERSION}
98+ FROM mcr.microsoft.com/windows/nanoserver:${WINDOWS_VERSION}
7999
80100WORKDIR C:/openlist
81101
82102# Copy the compiled binary from builder
83103COPY --from=builder C:/app/openlist.exe .
84-
85- # Create data directory in PowerShell during build
86- SHELL ["powershell", "-Command"]
87- RUN New-Item -ItemType Directory -Path C:\\openlist\\data -Force
88-
104+ # COPY --from=builder C:/vcruntime C:/vcruntime
105+ # ENV PATH "C:\Windows\system32;C:\Program Files\PowerShell;C:\vcruntime"
89106# Expose ports
90107EXPOSE 5244 5245
91108
92109# Set volume
93- VOLUME C:\\ openlist\\ data
110+ VOLUME C:/ openlist/ data
94111
95112# Run the application
96- ENTRYPOINT ["C:\\ openlist\\ openlist.exe"]
97- CMD ["server"]
113+ ENTRYPOINT ["C:/ openlist/ openlist.exe"]
114+ CMD ["server"]
0 commit comments