-
Notifications
You must be signed in to change notification settings - Fork 2k
Add Official Support for Windows Docker Images #2136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d5e9215
c77f154
880fca8
788df2f
47843c9
537bc56
0547704
b98f859
48e25c2
d5532b8
a8724fb
dbe54a6
e3485a7
79bf2fe
41d4d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: build-test-windows | ||
|
||
on: | ||
push: | ||
paths: | ||
- "**/windowsservercore-ltsc2019/**" | ||
- "**/windowsservercore-ltsc2022/**" | ||
- ".github/workflows/build-test-windows.yml" | ||
|
||
pull_request: | ||
paths: | ||
- "**/windowsservercore-ltsc2019/**" | ||
- "**/windowsservercore-ltsc2022/**" | ||
- ".github/workflows/build-test-windows.yml" | ||
|
||
jobs: | ||
build-windows-2019: | ||
name: build-windows-2019 | ||
runs-on: windows-2019 | ||
timeout-minutes: 60 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: [ "22.9.0" ] | ||
variant: [ "windowsservercore-ltsc2019" ] | ||
|
||
steps: | ||
- name: Get short node version | ||
uses: actions/github-script@v7 | ||
id: short-version | ||
with: | ||
result-encoding: string | ||
script: return "${{ matrix.version }}".split('.')[0] | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
# We cannot use docker/build-push-action here because it requires buildx, which is not available on Windows | ||
- name: Build image | ||
run: | | ||
docker build --tag node:${{ matrix.version }}-${{ matrix.variant }} ./${{ steps.short-version.outputs.result }}/${{ matrix.variant }} | ||
|
||
- name: Test for node version | ||
shell: pwsh | ||
run: | | ||
$image_node_version = (docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} node --print "process.versions.node").Trim() | ||
Write-Host "Expected: '${{ matrix.version }}', Got: '$image_node_version'" | ||
if ($image_node_version -ne "${{ matrix.version }}") { | ||
exit 1 | ||
} | ||
|
||
- name: Verify node runs regular files | ||
shell: pwsh | ||
run: | | ||
$tempDir = New-Item -ItemType Directory -Path $env:TEMP -Name "tempNodeApp" | ||
$tmp_file = Join-Path $tempDir "index.js" | ||
"console.log('success')" | Out-File -FilePath $tmp_file -Encoding utf8 | ||
$output = (docker run --rm -w /app --mount "type=bind,src=$tempDir,target=c:\app" node:${{ matrix.version }}-${{ matrix.variant }} node C:/app/index.js) | ||
if ($output -ne 'success') { | ||
exit 1 | ||
} | ||
|
||
- name: Test for npm | ||
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} powershell.exe npm --version | ||
|
||
build-windows-2022: | ||
name: build-windows-2022 | ||
runs-on: windows-2022 | ||
timeout-minutes: 60 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: [ "22.9.0" ] | ||
variant: [ "windowsservercore-ltsc2022" ] | ||
|
||
steps: | ||
- name: Get short node version | ||
uses: actions/github-script@v7 | ||
id: short-version | ||
with: | ||
result-encoding: string | ||
script: return "${{ matrix.version }}".split('.')[0] | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
# We cannot use docker/build-push-action here because it requires buildx, which is not available on Windows | ||
- name: Build image | ||
run: | | ||
docker build --tag node:${{ matrix.version }}-${{ matrix.variant }} ./${{ steps.short-version.outputs.result }}/${{ matrix.variant }} | ||
|
||
- name: Test for node version | ||
shell: pwsh | ||
run: | | ||
$image_node_version = (docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} node --print "process.versions.node").Trim() | ||
Write-Host "Expected: '${{ matrix.version }}', Got: '$image_node_version'" | ||
if ($image_node_version -ne "${{ matrix.version }}") { | ||
exit 1 | ||
} | ||
|
||
- name: Verify node runs regular files | ||
shell: pwsh | ||
run: | | ||
$tempDir = New-Item -ItemType Directory -Path $env:TEMP -Name "tempNodeApp" | ||
$tmp_file = Join-Path $tempDir "index.js" | ||
"console.log('success')" | Out-File -FilePath $tmp_file -Encoding utf8 | ||
$output = (docker run --rm -w /app --mount "type=bind,src=$tempDir,target=c:\app" node:${{ matrix.version }}-${{ matrix.variant }} node C:/app/index.js) | ||
if ($output -ne 'success') { | ||
exit 1 | ||
} | ||
|
||
- name: Test for npm | ||
# We need to use powershell.exe to run npm because docker needs to attach to process and npm is a batch file/powershell script | ||
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} powershell.exe npm --version |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM mcr.microsoft.com/windows/servercore:ltsc2019 | ||
|
||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
# PATH isn't actually set in the Docker image, so we have to set it from within the container | ||
RUN $newPath = ('C:\nodejs;{0};{0}' -f $env:PATH); \ | ||
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine) | ||
# doing this first to share cache across versions more aggressively | ||
|
||
ENV NODE_VERSION 22.9.0 | ||
ENV NODE_CHECKSUM 8af226c0aa71fefe5228e881f4b5c5d90a8b41c290b96f44f56990d8dc3fac1c | ||
|
||
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; \ | ||
Invoke-WebRequest $('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION) -OutFile 'node.zip' -UseBasicParsing ; \ | ||
if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $env:NODE_CHECKSUM) { Write-Error 'SHA256 mismatch' } ; \ | ||
Expand-Archive node.zip -DestinationPath C:\ ; \ | ||
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs' ; \ | ||
Remove-Item node.zip -Force ; \ | ||
node --version; \ | ||
npm --version; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM mcr.microsoft.com/windows/servercore:ltsc2022 | ||
|
||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
# PATH isn't actually set in the Docker image, so we have to set it from within the container | ||
RUN $newPath = ('C:\nodejs;{0};{0}' -f $env:PATH); \ | ||
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine) | ||
# doing this first to share cache across versions more aggressively | ||
|
||
ENV NODE_VERSION 22.9.0 | ||
ENV NODE_CHECKSUM 8af226c0aa71fefe5228e881f4b5c5d90a8b41c290b96f44f56990d8dc3fac1c | ||
|
||
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; \ | ||
Invoke-WebRequest $('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION) -OutFile 'node.zip' -UseBasicParsing ; \ | ||
if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $env:NODE_CHECKSUM) { Write-Error 'SHA256 mismatch' } ; \ | ||
Expand-Archive node.zip -DestinationPath C:\ ; \ | ||
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs' ; \ | ||
Remove-Item node.zip -Force ; \ | ||
node --version; \ | ||
npm --version; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM mcr.microsoft.com/windows/servercore:version | ||
|
||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
# PATH isn't actually set in the Docker image, so we have to set it from within the container | ||
RUN $newPath = ('C:\nodejs;{0};{0}' -f $env:PATH); \ | ||
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine) | ||
# doing this first to share cache across versions more aggressively | ||
|
||
ENV NODE_VERSION 0.0.0 | ||
ENV NODE_CHECKSUM CHECKSUM_x64 | ||
|
||
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; \ | ||
Invoke-WebRequest $('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION) -OutFile 'node.zip' -UseBasicParsing ; \ | ||
if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $env:NODE_CHECKSUM) { Write-Error 'SHA256 mismatch' } ; \ | ||
Expand-Archive node.zip -DestinationPath C:\ ; \ | ||
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs' ; \ | ||
Remove-Item node.zip -Force ; \ | ||
node --version; \ | ||
npm --version; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,23 +8,25 @@ const testFiles = [ | |||||
]; | ||||||
|
||||||
const nodeDirRegex = /^\d+$/; | ||||||
// Directories starting with 'windowsservercore-' are excluded from the matrix windows-2019 are excluded for example | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The phrase 'windows-2019 are excluded for example' seems to be a typo and should be rephrased for clarity.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
const windowsDirRegex = /^windowsservercore-/; | ||||||
|
||||||
const areTestFilesChanged = (changedFiles) => changedFiles | ||||||
.some((file) => testFiles.includes(file)); | ||||||
|
||||||
// Returns a list of the child directories in the given path | ||||||
// Returns a list of the child directories in the given path, excluding those starting with 'windows-' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The comment should be 'excluding those starting with 'windowsservercore-'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
const getChildDirectories = (parent) => fs.readdirSync(parent, { withFileTypes: true }) | ||||||
.filter((dirent) => dirent.isDirectory()) | ||||||
.filter((directory) => directory.isDirectory()) | ||||||
.map(({ name }) => path.resolve(parent, name)); | ||||||
|
||||||
const getNodeVerionDirs = (base) => getChildDirectories(base) | ||||||
const getNodeVersionDirs = (base) => getChildDirectories(base) | ||||||
.filter((childPath) => nodeDirRegex.test(path.basename(childPath))); | ||||||
|
||||||
// Returns the paths of Dockerfiles that are at: base/*/Dockerfile | ||||||
const getDockerfilesInChildDirs = (base) => getChildDirectories(base) | ||||||
.map((childDir) => path.resolve(childDir, 'Dockerfile')); | ||||||
|
||||||
const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs); | ||||||
const getAllDockerfiles = (base) => getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs); | ||||||
|
||||||
const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => { | ||||||
const files = [ | ||||||
|
@@ -69,7 +71,8 @@ const getDockerfileMatrixEntry = (file) => { | |||||
const generateBuildMatrix = (filesAdded, filesModified, filesRenamed) => { | ||||||
const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))]; | ||||||
|
||||||
const entries = dockerfiles.map(getDockerfileMatrixEntry); | ||||||
let entries = dockerfiles.map(getDockerfileMatrixEntry); | ||||||
entries = entries.filter((entry) => !windowsDirRegex.test(entry.variant)); | ||||||
|
||||||
// Return null if there are no entries so we can skip the matrix step | ||||||
return entries.length | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.