From b1af464b223160827773565908ff3d5787a74b4a Mon Sep 17 00:00:00 2001
From: YasInvolved <szrtxm.op@gmail.com>
Date: Tue, 25 Mar 2025 21:58:36 +0100
Subject: [PATCH 1/4] new dockerfile based on windows nanoserver

---
 Dockerfile | 110 ++++++++++++++---------------------------------------
 1 file changed, 29 insertions(+), 81 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index fee715b..255d5f5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,94 +1,42 @@
-# escape=`
+ARG IMPL_NANO_BASE=mcr.microsoft.com/powershell
+ARG IMPL_NANO_TAG=lts-nanoserver-ltsc2022
+ARG IMPL_ARTIFACTS_DIR="C:\artifacts"
+ARG NODE_VERSION=23.10.0
 
-ARG BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022-amd64
+# nodejs
+FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as node
+SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
 
-FROM ${BASE_IMAGE}
+ARG NODE_VERSION
+ARG IMPL_ARTIFACTS_DIR
 
-SHELL ["cmd", "/S", "/C"]
+RUN New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR && Invoke-WebRequest -Uri https://nodejs.org/download/release/latest/node-v$env:NODE_VERSION-win-x64.zip -OutFile C:\Temp\nodejs.zip && tar -xf C:\Temp\nodejs.zip -C $env:IMPL_ARTIFACTS_DIR && Remove-Item C:\Temp\nodejs.zip && ls $env:IMPL_ARTIFACTS_DIR
 
-ENV GIT_VERSION=2.47.1
+# compiler-explorer
+FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as compiler-explorer
+SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
 
-RUN `
-	# Download Git
-	`
-	curl -SL --output git.zip https://github.com/git-for-windows/git/releases/download/v%GIT_VERSION%.windows.1/MinGit-%GIT_VERSION%-64-bit.zip `
-	`
-	&& mkdir "C:\\git" `
-	`
-	&& tar -xf git.zip -C "C:\\git" `
-	`
-	&& setx PATH "%PATH%;C:\\git\\cmd" /M `
-	`
-	&& del /q git.zip
-	
-RUN `
-	# Post git configuration
-	`
-	git config --system --add safe.directory *
+ARG IMPL_ARTIFACTS_DIR
 
-ENV PYTHON_VERSION=3.11.0
+RUN New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR && Invoke-WebRequest -Uri https://github.com/Devsh-Graphics-Programming/compiler-explorer/archive/refs/heads/main.zip -OutFile C:\Temp\CompilerExplorer.zip && tar -xf C:\Temp\CompilerExplorer.zip -C $env:IMPL_ARTIFACTS_DIR && Remove-Item C:\Temp\CompilerExplorer.zip
 
-RUN `
-    # Download Python
-    `
-    curl -SL --output python.zip https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-embed-amd64.zip `
-    `
-    && mkdir "C:\\python" `
-    `
-    && tar -xf python.zip -C "C:\\python" `
-    `
-    && setx PATH "%PATH%;C:\\python" /M `
-    `
-    && del /q python.zip
+# final image
+FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
+SHELL ["cmd.exe", "/C"]
 
-ENV NODEJS_MSI=https://nodejs.org/dist/v18.19.0/node-v18.19.0-x64.msi
+ARG IMPL_ARTIFACTS_DIR
+ARG NODE_VERSION
 
-RUN `
-	# Install Node LTS
-	`
-	curl -SL --output nodejs.msi %NODEJS_MSI% `
-	`
-	&& msiexec /i nodejs.msi /qn `
-	`
-	&& del /q nodejs.msi
+COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
+COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/compiler-explorer-main", "C:/Compiler-Explorer"]
 
-ENV GIT_GODBOLT_REPOSITORY_PATH=C:\compiler-explorer
-ENV CE_URL=https://github.com/Devsh-Graphics-Programming/compiler-explorer.git
-ENV CE_SHA=ce980aded514ae6a0a1b1f63e7fb358e57c9ed57
+USER ContainerAdministrator
+ENV NODE_VERSION=${NODE_VERSION} NODE_OPTIONS="--max-old-space-size=4096" GIT_VERSION=${GIT_VERSION} PATH="C:\Windows\system32;C\Windows;C:\Program Files\PowerShell;C:\Git\cmd;C:\Git\bin;C:\Git\usr\bin;C:\Git\mingw64\bin;C:\Node"
 
-RUN `
-    # Checkout Compiler-Explorer
-    `
-	mkdir %GIT_GODBOLT_REPOSITORY_PATH% `
-	`
-	&& git -C %GIT_GODBOLT_REPOSITORY_PATH% init `
-	`
-	&& git -C %GIT_GODBOLT_REPOSITORY_PATH% remote add origin %CE_URL% `
-	`
-	&& git -C %GIT_GODBOLT_REPOSITORY_PATH% fetch --depth=1 -- origin %CE_SHA% `
-	`
-	&& git -C %GIT_GODBOLT_REPOSITORY_PATH% checkout %CE_SHA% `
-    `
-    && setx GIT_GODBOLT_REPOSITORY_PATH %GIT_GODBOLT_REPOSITORY_PATH% /M
+EXPOSE 10240
+WORKDIR C:\\Compiler-Explorer
 
-ENV NODE_OPTIONS="--max-old-space-size=4096"
+RUN npm install && npm run webpack
 
-RUN `
-    # Install Node.js dependencies & precompile production
-    `
-    cd %GIT_GODBOLT_REPOSITORY_PATH% `
-    `
-    && npm ci `
-    `
-    && npm run webpack
-	
-RUN `
-	# Post registry configuration
-	`
-    reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v "LongPathsEnabled" /t REG_DWORD /d 1 /f
-
-COPY ce_healthy_check.py /ce_healthy_check.py
-
-SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]
-ENTRYPOINT ["powershell.exe", "-ExecutionPolicy", "Bypass"]
-CMD ["-NoExit"]
\ No newline at end of file
+ENTRYPOINT ["cmd.exe", "/C"]
+CMD ["npm", "run", "start"]
\ No newline at end of file

From eef996715b9ae06a84accfcf33a6d073482f0c7e Mon Sep 17 00:00:00 2001
From: AnastaZIuk <areklachowicz@gmail.com>
Date: Wed, 26 Mar 2025 14:33:25 +0100
Subject: [PATCH 2/4] Make godbolt work with windows nano image, refactor
 Dockerfile & collect only output dist artifacts; leave some comments for Yas

---
 Dockerfile            | 79 +++++++++++++++++++++++++++++++++++--------
 scripts/build-win.ps1 | 76 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 141 insertions(+), 14 deletions(-)
 create mode 100644 scripts/build-win.ps1

diff --git a/Dockerfile b/Dockerfile
index 255d5f5..0865509 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,42 +1,93 @@
+# syntax=docker/dockerfile:1
+# escape=`
+
+# ---------------- GLOBAL VARS ----------------
+ARG NODE_VERSION=23.10.0
+
+# TODO: YAS please fix our lib/compilers/nsc-spirv.ts errors
+# ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
+# ARG GODBOLT_SHA=cbbbe343dd1594c922a091b1e98b6c81dbe2c2b3
+
+# TMP from original upstream
+ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
+ARG GODBOLT_SHA=6b5553d7267afe76ae4f2edceed3fb346309cc3d
+
 ARG IMPL_NANO_BASE=mcr.microsoft.com/powershell
 ARG IMPL_NANO_TAG=lts-nanoserver-ltsc2022
+ARG IMPL_GIT_VERSION=2.48.1
 ARG IMPL_ARTIFACTS_DIR="C:\artifacts"
-ARG NODE_VERSION=23.10.0
 
-# nodejs
+# ---------------- NODE JS ----------------
 FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as node
 SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
 
 ARG NODE_VERSION
 ARG IMPL_ARTIFACTS_DIR
 
-RUN New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR && Invoke-WebRequest -Uri https://nodejs.org/download/release/latest/node-v$env:NODE_VERSION-win-x64.zip -OutFile C:\Temp\nodejs.zip && tar -xf C:\Temp\nodejs.zip -C $env:IMPL_ARTIFACTS_DIR && Remove-Item C:\Temp\nodejs.zip && ls $env:IMPL_ARTIFACTS_DIR
+RUN Write-Host "Installing NodeJS $env:NODE_VERSION" ; `
+New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR ; `
+Invoke-WebRequest -Uri https://nodejs.org/download/release/latest/node-v$env:NODE_VERSION-win-x64.zip -OutFile C:\Temp\nodejs.zip ; `
+tar -xf C:\Temp\nodejs.zip -C $env:IMPL_ARTIFACTS_DIR ; Remove-Item C:\Temp\nodejs.zip
+
+# ---------------- GIT ----------------
+FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as git
+SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
+
+ARG IMPL_GIT_VERSION
+ARG IMPL_ARTIFACTS_DIR
+
+RUN Write-Host "Installing Git $env:IMPL_GIT_VERSION" ; `
+New-Item -ItemType Directory -Force -Path C:\Temp, $env:IMPL_ARTIFACTS_DIR ; `
+Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download/v$env:IMPL_GIT_VERSION.windows.1/MinGit-$env:IMPL_GIT_VERSION-busybox-64-bit.zip" -OutFile C:\Temp\git.zip ; `
+tar -xf C:\Temp\git.zip -C $env:IMPL_ARTIFACTS_DIR ; Remove-Item C:\Temp\git.zip
 
-# compiler-explorer
+# ---------------- COMPILER EXPLORER ----------------
 FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as compiler-explorer
 SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
 
+ARG NODE_VERSION
 ARG IMPL_ARTIFACTS_DIR
 
-RUN New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR && Invoke-WebRequest -Uri https://github.com/Devsh-Graphics-Programming/compiler-explorer/archive/refs/heads/main.zip -OutFile C:\Temp\CompilerExplorer.zip && tar -xf C:\Temp\CompilerExplorer.zip -C $env:IMPL_ARTIFACTS_DIR && Remove-Item C:\Temp\CompilerExplorer.zip
+COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
+COPY --link --from=git ["${IMPL_ARTIFACTS_DIR}", "C:/Git"]
+ENV PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Git\cmd;C:\Git\bin;C:\Git\usr\bin;C:\Git\mingw64\bin;C:\Node"
+
+ARG GODBOLT_REMOTE
+ARG GODBOLT_SHA
+
+RUN Write-Host "Installing Compiler Explorer" ; Write-Host "Remote $env:GODBOLT_REMOTE" ; Write-Host "SHA $env:GODBOLT_SHA" ; `
+New-Item -ItemType Directory -Force -Path $env:IMPL_ARTIFACTS_DIR ; `
+git config --system --add safe.directory * ; `
+git -C "$env:IMPL_ARTIFACTS_DIR" init ; `
+git -C "$env:IMPL_ARTIFACTS_DIR" remote add origin $env:GODBOLT_REMOTE ; `
+git -C "$env:IMPL_ARTIFACTS_DIR" fetch --depth=1 -- origin $env:GODBOLT_SHA ; `
+git -C "$env:IMPL_ARTIFACTS_DIR" checkout $env:GODBOLT_SHA
+
+COPY scripts/build-win.ps1 ${IMPL_ARTIFACTS_DIR}/build-win.ps1 
+WORKDIR ${IMPL_ARTIFACTS_DIR}
+ENV NODE_OPTIONS="--max-old-space-size=69000"
+RUN cd $env:IMPL_ARTIFACTS_DIR ; ` 
+Write-Host "Building Compiler Explorer" ; `
+pwsh -File build-win.ps1 -CEWD "$env:IMPL_ARTIFACTS_DIR"
 
-# final image
+# ---------------- FINAL IMAGE ----------------
 FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
-SHELL ["cmd.exe", "/C"]
 
 ARG IMPL_ARTIFACTS_DIR
 ARG NODE_VERSION
 
+USER ContainerAdministrator
+
 COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
-COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/compiler-explorer-main", "C:/Compiler-Explorer"]
+COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/dist", "C:/Compiler-Explorer"]
+COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/dist-bin/dist", "C:/Compiler-Explorer"]
+COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/webpack/static", "C:/Compiler-Explorer/static"]
 
-USER ContainerAdministrator
-ENV NODE_VERSION=${NODE_VERSION} NODE_OPTIONS="--max-old-space-size=4096" GIT_VERSION=${GIT_VERSION} PATH="C:\Windows\system32;C\Windows;C:\Program Files\PowerShell;C:\Git\cmd;C:\Git\bin;C:\Git\usr\bin;C:\Git\mingw64\bin;C:\Node"
+ENV NODE_VERSION=${NODE_VERSION} NODE_ENV=production `
+PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Node"
 
 EXPOSE 10240
 WORKDIR C:\\Compiler-Explorer
-
-RUN npm install && npm run webpack
-
 ENTRYPOINT ["cmd.exe", "/C"]
-CMD ["npm", "run", "start"]
\ No newline at end of file
+CMD ["node", "--import=tsx", "./app.js"]
+# <...> --language HLSL, for instance
\ No newline at end of file
diff --git a/scripts/build-win.ps1 b/scripts/build-win.ps1
new file mode 100644
index 0000000..f5b0703
--- /dev/null
+++ b/scripts/build-win.ps1
@@ -0,0 +1,76 @@
+param(
+    [string]$CEWD
+)
+
+$ErrorActionPreference = 'Stop'
+
+Set-Location -Path $CEWD
+$ROOT = Get-Location
+
+$HASH = (git rev-parse HEAD) -join [Environment]::NewLine
+$RELEASE_FILE_NAME = $HASH
+$RELEASE_NAME = $HASH
+$BRANCH = $HASH
+
+Write-Host "RELEASE_FILE_NAME: $RELEASE_FILE_NAME"
+Write-Host "RELEASE_NAME: $RELEASE_NAME"
+Write-Host "HASH: $HASH"
+Write-Host "BRANCH: $BRANCH"
+
+Remove-Item -Path "out" -Recurse -Force -ErrorAction Ignore
+New-Item -Path . -Name "out/dist" -Force -ItemType "directory"
+
+Set-Location -Path "./out/dist"
+
+New-Item -Name "git_hash"
+Set-Content -Path "git_hash" -Value "$HASH"
+
+New-Item -Name "release_build"
+Set-Content -Path "release_build" -Value "$RELEASE_NAME"
+
+Copy-Item -Path "$ROOT/etc" -Destination . -Recurse
+Copy-Item -Path "$ROOT/examples" -Destination . -Recurse
+Copy-Item -Path "$ROOT/views" -Destination . -Recurse
+Copy-Item -Path "$ROOT/types" -Destination . -Recurse
+Copy-Item -Path "$ROOT/package*.json" -Destination . -Recurse
+
+Remove-Item -Path "$ROOT/lib/storage/data" -Force -Recurse -ErrorAction Ignore
+
+Set-Location -Path $ROOT
+
+npm install --no-audit
+if ($LASTEXITCODE -ne 0) {
+   throw "npm install exited with error $LASTEXITCODE"
+}
+
+npm run webpack
+if ($LASTEXITCODE -ne 0) {
+   throw "npm run webpack exited with error $LASTEXITCODE"
+}
+
+npm run ts-compile
+if ($LASTEXITCODE -ne 0) {
+   throw "npm run ts-compile exited with error $LASTEXITCODE"
+}
+
+Set-Location -Path "./out/dist"
+npm install --no-audit --ignore-scripts --production
+if ($LASTEXITCODE -ne 0) {
+   throw "npm install (prod) exited with error $LASTEXITCODE"
+}
+
+Remove-Item -Path "node_modules/.cache" -Force -Recurse -ErrorAction Ignore
+Remove-Item -Path "node_modules/monaco-editor" -Force -Recurse -ErrorAction Ignore
+Remove-Item -Path "node_modules" -Include "*.ts" -Force -Recurse -ErrorAction Ignore
+
+node --import=tsx --no-warnings=ExperimentalWarning ./app.js --version --dist
+if ($LASTEXITCODE -ne 0) {
+   throw "node exited with error $LASTEXITCODE"
+}
+
+$DIST_DIR = "$ROOT/out/dist-bin/dist"
+Remove-Item -Path $DIST_DIR -Recurse -Force -ErrorAction Ignore
+New-Item -ItemType Directory -Force -Path $DIST_DIR
+Set-Content -Path "$DIST_DIR/$HASH.txt" -Value "$HASH"
+
+Set-Location -Path $ROOT
\ No newline at end of file

From faaf9ddd8f4acf0edf0a3bbfa909462efb1fd023 Mon Sep 17 00:00:00 2001
From: AnastaZIuk <areklachowicz@gmail.com>
Date: Thu, 27 Mar 2025 11:23:28 +0100
Subject: [PATCH 3/4] update godbolt commit reference with typescript fixes,
 CMD updates

---
 Dockerfile | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 0865509..ea6a1a5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,13 +4,8 @@
 # ---------------- GLOBAL VARS ----------------
 ARG NODE_VERSION=23.10.0
 
-# TODO: YAS please fix our lib/compilers/nsc-spirv.ts errors
-# ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
-# ARG GODBOLT_SHA=cbbbe343dd1594c922a091b1e98b6c81dbe2c2b3
-
-# TMP from original upstream
 ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
-ARG GODBOLT_SHA=6b5553d7267afe76ae4f2edceed3fb346309cc3d
+ARG GODBOLT_SHA=fc1b97ef9325eacbb8100d280aee0b0158a5adca
 
 ARG IMPL_NANO_BASE=mcr.microsoft.com/powershell
 ARG IMPL_NANO_TAG=lts-nanoserver-ltsc2022
@@ -89,5 +84,5 @@ PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Node"
 EXPOSE 10240
 WORKDIR C:\\Compiler-Explorer
 ENTRYPOINT ["cmd.exe", "/C"]
-CMD ["node", "--import=tsx", "./app.js"]
-# <...> --language HLSL, for instance
\ No newline at end of file
+CMD ["node", "--no-warnings", "--no-deprecation", "--import=tsx", "./app.js", "--language", "python"]
+# for instance, <...> --language HLSL; note we are running without any compilers in this example, one have to provide them
\ No newline at end of file

From 09ce2f4a49e1e38c7a9d319bc5bc607590ba2979 Mon Sep 17 00:00:00 2001
From: Arkadiusz Lachowicz <34793522+AnastaZIuk@users.noreply.github.com>
Date: Sat, 12 Apr 2025 00:01:15 +0200
Subject: [PATCH 4/4] Update compose.yml

---
 compose.yml | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/compose.yml b/compose.yml
index aa301b3..26f5f22 100644
--- a/compose.yml
+++ b/compose.yml
@@ -5,7 +5,6 @@ services:
       dockerfile: Dockerfile
     image: dr.devsh.eu/compiler-explorer/windows:latest
     container_name: dev.ce.base
-    entrypoint: ["cmd", "/c", "npm --prefix %GIT_GODBOLT_REPOSITORY_PATH% run dev"]
     networks:
       docker_default:
     deploy:
@@ -18,4 +17,4 @@ services:
 
 networks:
   docker_default:
-    external: true
\ No newline at end of file
+    external: true