Skip to content

Commit eef9967

Browse files
committed
Make godbolt work with windows nano image, refactor Dockerfile & collect only output dist artifacts; leave some comments for Yas
1 parent b1af464 commit eef9967

File tree

2 files changed

+141
-14
lines changed

2 files changed

+141
-14
lines changed

Dockerfile

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,93 @@
1+
# syntax=docker/dockerfile:1
2+
# escape=`
3+
4+
# ---------------- GLOBAL VARS ----------------
5+
ARG NODE_VERSION=23.10.0
6+
7+
# TODO: YAS please fix our lib/compilers/nsc-spirv.ts errors
8+
# ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
9+
# ARG GODBOLT_SHA=cbbbe343dd1594c922a091b1e98b6c81dbe2c2b3
10+
11+
# TMP from original upstream
12+
ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
13+
ARG GODBOLT_SHA=6b5553d7267afe76ae4f2edceed3fb346309cc3d
14+
115
ARG IMPL_NANO_BASE=mcr.microsoft.com/powershell
216
ARG IMPL_NANO_TAG=lts-nanoserver-ltsc2022
17+
ARG IMPL_GIT_VERSION=2.48.1
318
ARG IMPL_ARTIFACTS_DIR="C:\artifacts"
4-
ARG NODE_VERSION=23.10.0
519

6-
# nodejs
20+
# ---------------- NODE JS ----------------
721
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as node
822
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
923

1024
ARG NODE_VERSION
1125
ARG IMPL_ARTIFACTS_DIR
1226

13-
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
27+
RUN Write-Host "Installing NodeJS $env:NODE_VERSION" ; `
28+
New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR ; `
29+
Invoke-WebRequest -Uri https://nodejs.org/download/release/latest/node-v$env:NODE_VERSION-win-x64.zip -OutFile C:\Temp\nodejs.zip ; `
30+
tar -xf C:\Temp\nodejs.zip -C $env:IMPL_ARTIFACTS_DIR ; Remove-Item C:\Temp\nodejs.zip
31+
32+
# ---------------- GIT ----------------
33+
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as git
34+
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
35+
36+
ARG IMPL_GIT_VERSION
37+
ARG IMPL_ARTIFACTS_DIR
38+
39+
RUN Write-Host "Installing Git $env:IMPL_GIT_VERSION" ; `
40+
New-Item -ItemType Directory -Force -Path C:\Temp, $env:IMPL_ARTIFACTS_DIR ; `
41+
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 ; `
42+
tar -xf C:\Temp\git.zip -C $env:IMPL_ARTIFACTS_DIR ; Remove-Item C:\Temp\git.zip
1443

15-
# compiler-explorer
44+
# ---------------- COMPILER EXPLORER ----------------
1645
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as compiler-explorer
1746
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
1847

48+
ARG NODE_VERSION
1949
ARG IMPL_ARTIFACTS_DIR
2050

21-
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
51+
COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
52+
COPY --link --from=git ["${IMPL_ARTIFACTS_DIR}", "C:/Git"]
53+
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"
54+
55+
ARG GODBOLT_REMOTE
56+
ARG GODBOLT_SHA
57+
58+
RUN Write-Host "Installing Compiler Explorer" ; Write-Host "Remote $env:GODBOLT_REMOTE" ; Write-Host "SHA $env:GODBOLT_SHA" ; `
59+
New-Item -ItemType Directory -Force -Path $env:IMPL_ARTIFACTS_DIR ; `
60+
git config --system --add safe.directory * ; `
61+
git -C "$env:IMPL_ARTIFACTS_DIR" init ; `
62+
git -C "$env:IMPL_ARTIFACTS_DIR" remote add origin $env:GODBOLT_REMOTE ; `
63+
git -C "$env:IMPL_ARTIFACTS_DIR" fetch --depth=1 -- origin $env:GODBOLT_SHA ; `
64+
git -C "$env:IMPL_ARTIFACTS_DIR" checkout $env:GODBOLT_SHA
65+
66+
COPY scripts/build-win.ps1 ${IMPL_ARTIFACTS_DIR}/build-win.ps1
67+
WORKDIR ${IMPL_ARTIFACTS_DIR}
68+
ENV NODE_OPTIONS="--max-old-space-size=69000"
69+
RUN cd $env:IMPL_ARTIFACTS_DIR ; `
70+
Write-Host "Building Compiler Explorer" ; `
71+
pwsh -File build-win.ps1 -CEWD "$env:IMPL_ARTIFACTS_DIR"
2272

23-
# final image
73+
# ---------------- FINAL IMAGE ----------------
2474
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
25-
SHELL ["cmd.exe", "/C"]
2675

2776
ARG IMPL_ARTIFACTS_DIR
2877
ARG NODE_VERSION
2978

79+
USER ContainerAdministrator
80+
3081
COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
31-
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/compiler-explorer-main", "C:/Compiler-Explorer"]
82+
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/dist", "C:/Compiler-Explorer"]
83+
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/dist-bin/dist", "C:/Compiler-Explorer"]
84+
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/webpack/static", "C:/Compiler-Explorer/static"]
3285

33-
USER ContainerAdministrator
34-
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"
86+
ENV NODE_VERSION=${NODE_VERSION} NODE_ENV=production `
87+
PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Node"
3588

3689
EXPOSE 10240
3790
WORKDIR C:\\Compiler-Explorer
38-
39-
RUN npm install && npm run webpack
40-
4191
ENTRYPOINT ["cmd.exe", "/C"]
42-
CMD ["npm", "run", "start"]
92+
CMD ["node", "--import=tsx", "./app.js"]
93+
# <...> --language HLSL, for instance

scripts/build-win.ps1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
param(
2+
[string]$CEWD
3+
)
4+
5+
$ErrorActionPreference = 'Stop'
6+
7+
Set-Location -Path $CEWD
8+
$ROOT = Get-Location
9+
10+
$HASH = (git rev-parse HEAD) -join [Environment]::NewLine
11+
$RELEASE_FILE_NAME = $HASH
12+
$RELEASE_NAME = $HASH
13+
$BRANCH = $HASH
14+
15+
Write-Host "RELEASE_FILE_NAME: $RELEASE_FILE_NAME"
16+
Write-Host "RELEASE_NAME: $RELEASE_NAME"
17+
Write-Host "HASH: $HASH"
18+
Write-Host "BRANCH: $BRANCH"
19+
20+
Remove-Item -Path "out" -Recurse -Force -ErrorAction Ignore
21+
New-Item -Path . -Name "out/dist" -Force -ItemType "directory"
22+
23+
Set-Location -Path "./out/dist"
24+
25+
New-Item -Name "git_hash"
26+
Set-Content -Path "git_hash" -Value "$HASH"
27+
28+
New-Item -Name "release_build"
29+
Set-Content -Path "release_build" -Value "$RELEASE_NAME"
30+
31+
Copy-Item -Path "$ROOT/etc" -Destination . -Recurse
32+
Copy-Item -Path "$ROOT/examples" -Destination . -Recurse
33+
Copy-Item -Path "$ROOT/views" -Destination . -Recurse
34+
Copy-Item -Path "$ROOT/types" -Destination . -Recurse
35+
Copy-Item -Path "$ROOT/package*.json" -Destination . -Recurse
36+
37+
Remove-Item -Path "$ROOT/lib/storage/data" -Force -Recurse -ErrorAction Ignore
38+
39+
Set-Location -Path $ROOT
40+
41+
npm install --no-audit
42+
if ($LASTEXITCODE -ne 0) {
43+
throw "npm install exited with error $LASTEXITCODE"
44+
}
45+
46+
npm run webpack
47+
if ($LASTEXITCODE -ne 0) {
48+
throw "npm run webpack exited with error $LASTEXITCODE"
49+
}
50+
51+
npm run ts-compile
52+
if ($LASTEXITCODE -ne 0) {
53+
throw "npm run ts-compile exited with error $LASTEXITCODE"
54+
}
55+
56+
Set-Location -Path "./out/dist"
57+
npm install --no-audit --ignore-scripts --production
58+
if ($LASTEXITCODE -ne 0) {
59+
throw "npm install (prod) exited with error $LASTEXITCODE"
60+
}
61+
62+
Remove-Item -Path "node_modules/.cache" -Force -Recurse -ErrorAction Ignore
63+
Remove-Item -Path "node_modules/monaco-editor" -Force -Recurse -ErrorAction Ignore
64+
Remove-Item -Path "node_modules" -Include "*.ts" -Force -Recurse -ErrorAction Ignore
65+
66+
node --import=tsx --no-warnings=ExperimentalWarning ./app.js --version --dist
67+
if ($LASTEXITCODE -ne 0) {
68+
throw "node exited with error $LASTEXITCODE"
69+
}
70+
71+
$DIST_DIR = "$ROOT/out/dist-bin/dist"
72+
Remove-Item -Path $DIST_DIR -Recurse -Force -ErrorAction Ignore
73+
New-Item -ItemType Directory -Force -Path $DIST_DIR
74+
Set-Content -Path "$DIST_DIR/$HASH.txt" -Value "$HASH"
75+
76+
Set-Location -Path $ROOT

0 commit comments

Comments
 (0)