diff --git a/Dockerfile b/Dockerfile index fee715b..ea6a1a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,94 +1,88 @@ +# syntax=docker/dockerfile:1 # escape=` -ARG BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022-amd64 - -FROM ${BASE_IMAGE} - -SHELL ["cmd", "/S", "/C"] - -ENV GIT_VERSION=2.47.1 - -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 * - -ENV PYTHON_VERSION=3.11.0 - -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 - -ENV NODEJS_MSI=https://nodejs.org/dist/v18.19.0/node-v18.19.0-x64.msi - -RUN ` - # Install Node LTS - ` - curl -SL --output nodejs.msi %NODEJS_MSI% ` - ` - && msiexec /i nodejs.msi /qn ` - ` - && del /q nodejs.msi - -ENV GIT_GODBOLT_REPOSITORY_PATH=C:\compiler-explorer -ENV CE_URL=https://github.com/Devsh-Graphics-Programming/compiler-explorer.git -ENV CE_SHA=ce980aded514ae6a0a1b1f63e7fb358e57c9ed57 - -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 - -ENV NODE_OPTIONS="--max-old-space-size=4096" - -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 +# ---------------- GLOBAL VARS ---------------- +ARG NODE_VERSION=23.10.0 + +ARG GODBOLT_REMOTE=https://github.com/compiler-explorer/compiler-explorer.git +ARG GODBOLT_SHA=fc1b97ef9325eacbb8100d280aee0b0158a5adca + +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" + +# ---------------- 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 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 ---------------- +FROM ${IMPL_NANO_BASE}:${IMPL_NANO_TAG} as compiler-explorer +SHELL ["pwsh", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"] + +ARG NODE_VERSION +ARG IMPL_ARTIFACTS_DIR + +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 ---------------- +FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 + +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}/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"] + +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 +ENTRYPOINT ["cmd.exe", "/C"] +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 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 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