Skip to content

Commit 019f823

Browse files
authored
Merge pull request #1 from Devsh-Graphics-Programming/yas_newDockerFile
new dockerfile based on windows nanoserver
2 parents e7d3e6c + 09ce2f4 commit 019f823

File tree

3 files changed

+163
-94
lines changed

3 files changed

+163
-94
lines changed

Dockerfile

Lines changed: 86 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,88 @@
1+
# syntax=docker/dockerfile:1
12
# escape=`
23

3-
ARG BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022-amd64
4-
5-
FROM ${BASE_IMAGE}
6-
7-
SHELL ["cmd", "/S", "/C"]
8-
9-
ENV GIT_VERSION=2.47.1
10-
11-
RUN `
12-
# Download Git
13-
`
14-
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 `
15-
`
16-
&& mkdir "C:\\git" `
17-
`
18-
&& tar -xf git.zip -C "C:\\git" `
19-
`
20-
&& setx PATH "%PATH%;C:\\git\\cmd" /M `
21-
`
22-
&& del /q git.zip
23-
24-
RUN `
25-
# Post git configuration
26-
`
27-
git config --system --add safe.directory *
28-
29-
ENV PYTHON_VERSION=3.11.0
30-
31-
RUN `
32-
# Download Python
33-
`
34-
curl -SL --output python.zip https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-embed-amd64.zip `
35-
`
36-
&& mkdir "C:\\python" `
37-
`
38-
&& tar -xf python.zip -C "C:\\python" `
39-
`
40-
&& setx PATH "%PATH%;C:\\python" /M `
41-
`
42-
&& del /q python.zip
43-
44-
ENV NODEJS_MSI=https://nodejs.org/dist/v18.19.0/node-v18.19.0-x64.msi
45-
46-
RUN `
47-
# Install Node LTS
48-
`
49-
curl -SL --output nodejs.msi %NODEJS_MSI% `
50-
`
51-
&& msiexec /i nodejs.msi /qn `
52-
`
53-
&& del /q nodejs.msi
54-
55-
ENV GIT_GODBOLT_REPOSITORY_PATH=C:\compiler-explorer
56-
ENV CE_URL=https://github.com/Devsh-Graphics-Programming/compiler-explorer.git
57-
ENV CE_SHA=ce980aded514ae6a0a1b1f63e7fb358e57c9ed57
58-
59-
RUN `
60-
# Checkout Compiler-Explorer
61-
`
62-
mkdir %GIT_GODBOLT_REPOSITORY_PATH% `
63-
`
64-
&& git -C %GIT_GODBOLT_REPOSITORY_PATH% init `
65-
`
66-
&& git -C %GIT_GODBOLT_REPOSITORY_PATH% remote add origin %CE_URL% `
67-
`
68-
&& git -C %GIT_GODBOLT_REPOSITORY_PATH% fetch --depth=1 -- origin %CE_SHA% `
69-
`
70-
&& git -C %GIT_GODBOLT_REPOSITORY_PATH% checkout %CE_SHA% `
71-
`
72-
&& setx GIT_GODBOLT_REPOSITORY_PATH %GIT_GODBOLT_REPOSITORY_PATH% /M
73-
74-
ENV NODE_OPTIONS="--max-old-space-size=4096"
75-
76-
RUN `
77-
# Install Node.js dependencies & precompile production
78-
`
79-
cd %GIT_GODBOLT_REPOSITORY_PATH% `
80-
`
81-
&& npm ci `
82-
`
83-
&& npm run webpack
84-
85-
RUN `
86-
# Post registry configuration
87-
`
88-
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v "LongPathsEnabled" /t REG_DWORD /d 1 /f
89-
90-
COPY ce_healthy_check.py /ce_healthy_check.py
91-
92-
SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]
93-
ENTRYPOINT ["powershell.exe", "-ExecutionPolicy", "Bypass"]
94-
CMD ["-NoExit"]
4+
# ---------------- GLOBAL VARS ----------------
5+
ARG NODE_VERSION=23.10.0
6+
7+
ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git
8+
ARG GODBOLT_SHA=fc1b97ef9325eacbb8100d280aee0b0158a5adca
9+
10+
ARG IMPL_NANO_BASE=mcr.microsoft.com/powershell
11+
ARG IMPL_NANO_TAG=lts-nanoserver-ltsc2022
12+
ARG IMPL_GIT_VERSION=2.48.1
13+
ARG IMPL_ARTIFACTS_DIR="C:\artifacts"
14+
15+
# ---------------- NODE JS ----------------
16+
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as node
17+
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
18+
19+
ARG NODE_VERSION
20+
ARG IMPL_ARTIFACTS_DIR
21+
22+
RUN Write-Host "Installing NodeJS $env:NODE_VERSION" ; `
23+
New-Item -ItemType Directory -Force -Path "C:\Temp", $env:IMPL_ARTIFACTS_DIR ; `
24+
Invoke-WebRequest -Uri https://nodejs.org/download/release/latest/node-v$env:NODE_VERSION-win-x64.zip -OutFile C:\Temp\nodejs.zip ; `
25+
tar -xf C:\Temp\nodejs.zip -C $env:IMPL_ARTIFACTS_DIR ; Remove-Item C:\Temp\nodejs.zip
26+
27+
# ---------------- GIT ----------------
28+
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as git
29+
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
30+
31+
ARG IMPL_GIT_VERSION
32+
ARG IMPL_ARTIFACTS_DIR
33+
34+
RUN Write-Host "Installing Git $env:IMPL_GIT_VERSION" ; `
35+
New-Item -ItemType Directory -Force -Path C:\Temp, $env:IMPL_ARTIFACTS_DIR ; `
36+
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 ; `
37+
tar -xf C:\Temp\git.zip -C $env:IMPL_ARTIFACTS_DIR ; Remove-Item C:\Temp\git.zip
38+
39+
# ---------------- COMPILER EXPLORER ----------------
40+
FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as compiler-explorer
41+
SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]
42+
43+
ARG NODE_VERSION
44+
ARG IMPL_ARTIFACTS_DIR
45+
46+
COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
47+
COPY --link --from=git ["${IMPL_ARTIFACTS_DIR}", "C:/Git"]
48+
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"
49+
50+
ARG GODBOLT_REMOTE
51+
ARG GODBOLT_SHA
52+
53+
RUN Write-Host "Installing Compiler Explorer" ; Write-Host "Remote $env:GODBOLT_REMOTE" ; Write-Host "SHA $env:GODBOLT_SHA" ; `
54+
New-Item -ItemType Directory -Force -Path $env:IMPL_ARTIFACTS_DIR ; `
55+
git config --system --add safe.directory * ; `
56+
git -C "$env:IMPL_ARTIFACTS_DIR" init ; `
57+
git -C "$env:IMPL_ARTIFACTS_DIR" remote add origin $env:GODBOLT_REMOTE ; `
58+
git -C "$env:IMPL_ARTIFACTS_DIR" fetch --depth=1 -- origin $env:GODBOLT_SHA ; `
59+
git -C "$env:IMPL_ARTIFACTS_DIR" checkout $env:GODBOLT_SHA
60+
61+
COPY scripts/build-win.ps1 ${IMPL_ARTIFACTS_DIR}/build-win.ps1
62+
WORKDIR ${IMPL_ARTIFACTS_DIR}
63+
ENV NODE_OPTIONS="--max-old-space-size=69000"
64+
RUN cd $env:IMPL_ARTIFACTS_DIR ; `
65+
Write-Host "Building Compiler Explorer" ; `
66+
pwsh -File build-win.ps1 -CEWD "$env:IMPL_ARTIFACTS_DIR"
67+
68+
# ---------------- FINAL IMAGE ----------------
69+
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
70+
71+
ARG IMPL_ARTIFACTS_DIR
72+
ARG NODE_VERSION
73+
74+
USER ContainerAdministrator
75+
76+
COPY --link --from=node ["${IMPL_ARTIFACTS_DIR}/node-v${NODE_VERSION}-win-x64", "C:/Node"]
77+
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/dist", "C:/Compiler-Explorer"]
78+
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/dist-bin/dist", "C:/Compiler-Explorer"]
79+
COPY --link --from=compiler-explorer ["${IMPL_ARTIFACTS_DIR}/out/webpack/static", "C:/Compiler-Explorer/static"]
80+
81+
ENV NODE_VERSION=${NODE_VERSION} NODE_ENV=production `
82+
PATH="C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell;C:\Node"
83+
84+
EXPOSE 10240
85+
WORKDIR C:\\Compiler-Explorer
86+
ENTRYPOINT ["cmd.exe", "/C"]
87+
CMD ["node", "--no-warnings", "--no-deprecation", "--import=tsx", "./app.js", "--language", "python"]
88+
# for instance, <...> --language HLSL; note we are running without any compilers in this example, one have to provide them

compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ services:
55
dockerfile: Dockerfile
66
image: dr.devsh.eu/compiler-explorer/windows:latest
77
container_name: dev.ce.base
8-
entrypoint: ["cmd", "/c", "npm --prefix %GIT_GODBOLT_REPOSITORY_PATH% run dev"]
98
networks:
109
docker_default:
1110
deploy:
@@ -18,4 +17,4 @@ services:
1817

1918
networks:
2019
docker_default:
21-
external: true
20+
external: true

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)