Skip to content

Commit

Permalink
Added multistage build
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Sep 3, 2024
1 parent 4c7533a commit fb9a759
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
19 changes: 16 additions & 3 deletions 22/windows-2019/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM mcr.microsoft.com/windows/servercore:ltsc2019
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as installer

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

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

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

FROM mcr.microsoft.com/windows/servercore:ltsc2019 as runner

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

RUN $newPath = ('C:\nodejs;{0}' -f $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)

COPY --from=installer C:/nodejs C:/nodejs

COPY docker-entrypoint.ps1 C:/docker-entrypoint.ps1
ENTRYPOINT [ "powershell.exe" , "C:/docker-entrypoint.ps1" ]

# Smoke test
RUN node --version; \
npm --version;

CMD [ "node.exe" ]
19 changes: 16 additions & 3 deletions 22/windows-2022/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM mcr.microsoft.com/windows/servercore:ltsc2022
FROM mcr.microsoft.com/windows/servercore:ltsc2022 as installer

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

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

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

FROM mcr.microsoft.com/windows/servercore:ltsc2022 as runner

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

RUN $newPath = ('C:\nodejs;{0}' -f $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)

COPY --from=installer C:/nodejs C:/nodejs

COPY docker-entrypoint.ps1 C:/docker-entrypoint.ps1
ENTRYPOINT [ "powershell.exe" , "C:/docker-entrypoint.ps1" ]

# Smoke test
RUN node --version; \
npm --version;

CMD [ "node.exe" ]
19 changes: 16 additions & 3 deletions Dockerfile-windows.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM mcr.microsoft.com/windows/servercore:version
FROM mcr.microsoft.com/windows/servercore:version as installer

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

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

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

FROM mcr.microsoft.com/windows/servercore:version as runner

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

RUN $newPath = ('C:\nodejs;{0}' -f $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine)

COPY --from=installer C:/nodejs C:/nodejs

COPY docker-entrypoint.ps1 C:/docker-entrypoint.ps1
ENTRYPOINT [ "powershell.exe" , "C:/docker-entrypoint.ps1" ]

# Smoke test
RUN node --version; \
npm --version;

CMD [ "node.exe" ]
3 changes: 1 addition & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function update_node_version() {
fatal "Failed to fetch checksum for version ${nodeVersion}"
fi
sed -Ei -e "s/mcr\.microsoft\.com\/windows\/servercore:version/mcr\.microsoft\.com\/windows\/servercore:ltsc${windows_version}/" "${dockerfile}-tmp"
sed -Ei -e "s/mcr\.microsoft\.com\/windows\/nanoserver:version/mcr\.microsoft\.com\/windows\/nanoserver:ltsc${windows_version}/" "${dockerfile}-tmp"
sed -Ei -e 's/^(ENV NODE_CHECKSUM ).*/\1'"${checksum}"'/' "${dockerfile}-tmp"
fi

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

echo "Supported variants for ${parentpath}: ${variants[@]}"

pids=()

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

0 comments on commit fb9a759

Please sign in to comment.