Skip to content

Commit fb9a759

Browse files
committed
Added multistage build
1 parent 4c7533a commit fb9a759

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

22/windows-2019/Dockerfile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/windows/servercore:ltsc2019
1+
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as installer
22

33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
44

55
# 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;C:\Program Files (x86)\GnuPG\bin;{1}' -f $env:LOCALAPPDATA, $env:PATH); \
6+
RUN $newPath = ('C:\Program Files (x86)\GnuPG\bin;{0}' -f $env:PATH); \
77
Write-Host ('Updating PATH: {0}' -f $newPath); \
88
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
99
# doing this first to share cache across versions more aggressively
@@ -15,7 +15,6 @@ ENV GPG_VERSION 2.4.5_20240307
1515

1616
RUN Invoke-WebRequest $('https://www.gnupg.org/ftp/gcrypt/binary/gnupg-w32-{0}.exe' -f $env:GPG_VERSION) -OutFile 'gpg-installer.exe'; \
1717
Start-Process -FilePath 'gpg-installer.exe' -ArgumentList '/S' -Wait; \
18-
Remove-Item gpg-installer.exe -Force; \
1918
gpg --version;
2019

2120
RUN @( \
@@ -43,7 +42,21 @@ RUN @( \
4342
Expand-Archive node.zip -DestinationPath C:\ ; \
4443
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'
4544

45+
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as runner
46+
47+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
48+
49+
RUN $newPath = ('C:\nodejs;{0}' -f $env:PATH); \
50+
Write-Host ('Updating PATH: {0}' -f $newPath); \
51+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
52+
53+
COPY --from=installer C:/nodejs C:/nodejs
54+
4655
COPY docker-entrypoint.ps1 C:/docker-entrypoint.ps1
4756
ENTRYPOINT [ "powershell.exe" , "C:/docker-entrypoint.ps1" ]
57+
58+
# Smoke test
59+
RUN node --version; \
60+
npm --version;
4861

4962
CMD [ "node.exe" ]

22/windows-2022/Dockerfile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/windows/servercore:ltsc2022
1+
FROM mcr.microsoft.com/windows/servercore:ltsc2022 as installer
22

33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
44

55
# 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;C:\Program Files (x86)\GnuPG\bin;{1}' -f $env:LOCALAPPDATA, $env:PATH); \
6+
RUN $newPath = ('C:\Program Files (x86)\GnuPG\bin;{0}' -f $env:PATH); \
77
Write-Host ('Updating PATH: {0}' -f $newPath); \
88
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
99
# doing this first to share cache across versions more aggressively
@@ -15,7 +15,6 @@ ENV GPG_VERSION 2.4.5_20240307
1515

1616
RUN Invoke-WebRequest $('https://www.gnupg.org/ftp/gcrypt/binary/gnupg-w32-{0}.exe' -f $env:GPG_VERSION) -OutFile 'gpg-installer.exe'; \
1717
Start-Process -FilePath 'gpg-installer.exe' -ArgumentList '/S' -Wait; \
18-
Remove-Item gpg-installer.exe -Force; \
1918
gpg --version;
2019

2120
RUN @( \
@@ -43,7 +42,21 @@ RUN @( \
4342
Expand-Archive node.zip -DestinationPath C:\ ; \
4443
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'
4544

45+
FROM mcr.microsoft.com/windows/servercore:ltsc2022 as runner
46+
47+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
48+
49+
RUN $newPath = ('C:\nodejs;{0}' -f $env:PATH); \
50+
Write-Host ('Updating PATH: {0}' -f $newPath); \
51+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
52+
53+
COPY --from=installer C:/nodejs C:/nodejs
54+
4655
COPY docker-entrypoint.ps1 C:/docker-entrypoint.ps1
4756
ENTRYPOINT [ "powershell.exe" , "C:/docker-entrypoint.ps1" ]
57+
58+
# Smoke test
59+
RUN node --version; \
60+
npm --version;
4861

4962
CMD [ "node.exe" ]

Dockerfile-windows.template

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/windows/servercore:version
1+
FROM mcr.microsoft.com/windows/servercore:version as installer
22

33
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
44

55
# 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;C:\Program Files (x86)\GnuPG\bin;{1}' -f $env:LOCALAPPDATA, $env:PATH); \
6+
RUN $newPath = ('C:\Program Files (x86)\GnuPG\bin;{0}' -f $env:PATH); \
77
Write-Host ('Updating PATH: {0}' -f $newPath); \
88
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
99
# doing this first to share cache across versions more aggressively
@@ -15,7 +15,6 @@ ENV GPG_VERSION 2.4.5_20240307
1515

1616
RUN Invoke-WebRequest $('https://www.gnupg.org/ftp/gcrypt/binary/gnupg-w32-{0}.exe' -f $env:GPG_VERSION) -OutFile 'gpg-installer.exe'; \
1717
Start-Process -FilePath 'gpg-installer.exe' -ArgumentList '/S' -Wait; \
18-
Remove-Item gpg-installer.exe -Force; \
1918
gpg --version;
2019

2120
RUN @( \
@@ -32,7 +31,21 @@ RUN @( \
3231
Expand-Archive node.zip -DestinationPath C:\ ; \
3332
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'
3433

34+
FROM mcr.microsoft.com/windows/servercore:version as runner
35+
36+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
37+
38+
RUN $newPath = ('C:\nodejs;{0}' -f $env:PATH); \
39+
Write-Host ('Updating PATH: {0}' -f $newPath); \
40+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)
41+
42+
COPY --from=installer C:/nodejs C:/nodejs
43+
3544
COPY docker-entrypoint.ps1 C:/docker-entrypoint.ps1
3645
ENTRYPOINT [ "powershell.exe" , "C:/docker-entrypoint.ps1" ]
46+
47+
# Smoke test
48+
RUN node --version; \
49+
npm --version;
3750

3851
CMD [ "node.exe" ]

update.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function update_node_version() {
193193
fatal "Failed to fetch checksum for version ${nodeVersion}"
194194
fi
195195
sed -Ei -e "s/mcr\.microsoft\.com\/windows\/servercore:version/mcr\.microsoft\.com\/windows\/servercore:ltsc${windows_version}/" "${dockerfile}-tmp"
196+
sed -Ei -e "s/mcr\.microsoft\.com\/windows\/nanoserver:version/mcr\.microsoft\.com\/windows\/nanoserver:ltsc${windows_version}/" "${dockerfile}-tmp"
196197
sed -Ei -e 's/^(ENV NODE_CHECKSUM ).*/\1'"${checksum}"'/' "${dockerfile}-tmp"
197198
fi
198199

@@ -228,8 +229,6 @@ for version in "${versions[@]}"; do
228229
# See details in function.sh
229230
IFS=' ' read -ra variants <<< "$(get_variants "${parentpath}")"
230231

231-
echo "Supported variants for ${parentpath}: ${variants[@]}"
232-
233232
pids=()
234233

235234
if [ -f "${version}/Dockerfile" ]; then

0 commit comments

Comments
 (0)