Skip to content

Commit 4e88d64

Browse files
committed
Added docker build for windows node 22
1 parent 304b70f commit 4e88d64

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: build-test
2+
3+
on:
4+
push:
5+
paths:
6+
- "**/Dockerfile"
7+
- "**/docker-entrypoint.sh"
8+
- genMatrix.js
9+
- ".github/workflows/build-test.yml"
10+
11+
pull_request:
12+
paths:
13+
- "**/Dockerfile"
14+
- "**/docker-entrypoint.sh"
15+
- genMatrix.js
16+
- ".github/workflows/build-test.yml"
17+
18+
jobs:
19+
build:
20+
name: build
21+
runs-on: windows-latest
22+
timeout-minutes: 60
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
version: [ 22 ]
27+
variant: [ "windows" ]
28+
29+
steps:
30+
- name: Get short node version
31+
uses: actions/github-script@v7
32+
id: short-version
33+
with:
34+
result-encoding: string
35+
script: return "${{ matrix.version }}".split('.')[0]
36+
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Build image
41+
uses: docker/build-push-action@v6
42+
with:
43+
push: false
44+
load: true
45+
context: .
46+
file: ./${{ steps.short-version.outputs.result }}/${{ matrix.variant }}/Dockerfile
47+
tags: node:${{ matrix.version }}-${{ matrix.variant }}
48+
49+
- name: Test for node version
50+
run: |
51+
image_node_version=$(docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} node --print "process.versions.node")
52+
echo "Expected: \"${{ matrix.version }}\", Got: \"${image_node_version}\""
53+
[ "${image_node_version}" == "${{ matrix.version }}" ]
54+
55+
- name: Verify entrypoint runs regular, non-executable files with node
56+
run: |
57+
tmp_file=$(mktemp)
58+
echo 'console.log("success")' > "${tmp_file}"
59+
output=$(docker run --rm -v "${tmp_file}:/app/index.js" node:${{ matrix.version }}-${{ matrix.variant }} app/index.js)
60+
[ "${output}" = 'success' ]
61+
62+
- name: Test for npm
63+
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} npm --version
64+
65+
- name: Test for yarn
66+
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} yarn --version

22/windows/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM mcr.microsoft.com/windows/servercore:ltsc2019
2+
3+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
4+
5+
# PATH isn't actually set in the Docker image, so we have to set it from within the container
6+
RUN $newPath = ('C:\nodejs;{0}\Yarn\bin;{1}' -f $env:LOCALAPPDATA, $env:PATH); \
7+
Write-Host ('Updating PATH: {0}' -f $newPath); \
8+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
9+
# doing this first to share cache across versions more aggressively
10+
11+
ENV NODE_VERSION 22.7.0
12+
ENV NODE_SHA256 3fc638727974262b4f65a6b1b43c22fb2d80671cdcb50e1237e0b05d1330aaf7
13+
14+
RUN $url = ('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION); \
15+
Write-Host ('Downloading {0} ...' -f $url); \
16+
Invoke-WebRequest -Uri $url -OutFile 'node.zip'; \
17+
\
18+
Write-Host ('Verifying sha256 ({0}) ...' -f $env:NODE_SHA256); \
19+
if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $env:NODE_SHA256) { throw 'SHA256 mismatch' }; \
20+
\
21+
Write-Host 'Expanding ...'; \
22+
Expand-Archive node.zip -DestinationPath C:\; \
23+
\
24+
Write-Host 'Renaming ...'; \
25+
Rename-Item -Path ('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'; \
26+
\
27+
Write-Host 'Removing ...'; \
28+
Remove-Item node.zip -Force; \
29+
\
30+
Write-Host 'Verifying ("node --version") ...'; \
31+
node --version; \
32+
Write-Host 'Verifying ("npm --version") ...'; \
33+
npm --version; \
34+
\
35+
Write-Host 'Complete.'
36+
37+
ENV YARN_VERSION 1.22.17
38+
39+
# "It is recommended to install Yarn through the npm package manager" (https://classic.yarnpkg.com/en/docs/install)
40+
RUN Write-Host 'Installing "yarn" ...'; \
41+
npm install --global ('yarn@{0}' -f $env:YARN_VERSION); \
42+
\
43+
Write-Host 'Verifying ("yarn --version") ...'; \
44+
yarn --version; \
45+
\
46+
Write-Host 'Complete.'
47+
48+
CMD [ "node" ]

0 commit comments

Comments
 (0)