Using Windows nanoserver image instead of old Powershell image

This commit is contained in:
Alexey Pustovalov 2025-05-25 12:05:02 +00:00
parent 150a7c7d27
commit 136ba9a5ed
2 changed files with 34 additions and 4 deletions

View File

@ -29,15 +29,18 @@ LABEL org.opencontainers.image.title="Zabbix agent" `
org.opencontainers.image.version="${ZBX_VERSION}" `
org.opencontainers.image.source="${ZBX_SOURCES}"
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';"]
COPY --from=builder ["C:\\zabbix-${ZBX_VERSION}-output", "C:\\zabbix"]
COPY --from=builder ["C:\\pwsh", "C:\\Program Files\\PowerShell"]
COPY [".\\docker-entrypoint.ps1", "C:\\zabbix"]
WORKDIR C:\zabbix\
COPY --from=builder ["C:\\zabbix-${ZBX_VERSION}-output", "C:\\zabbix"]
COPY [".\\docker-entrypoint.ps1", "C:\\zabbix"]
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell"
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN $env:PATH = [string]::Format('{0}\zabbix\sbin;{0}\zabbix\bin;', $env:SystemDrive) + $env:PATH; `
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); `
`

View File

@ -6,6 +6,7 @@ FROM ${OS_BASE_IMAGE}
ARG GIT_VERSION=2.47.1
ARG NASM_VERSION=2.16.03
ARG VS_BUILDTOOLS_VERSION=17
ARG PWSH_VERSION=7.5.1
ARG PCRE2_VERSION=10.44
ARG OPENSSL_VERSION=3.4.1
@ -30,6 +31,8 @@ ARG LIBMODBUS_URL=https://github.com/stephane/libmodbus/archive/refs/tags/v$LIBM
ARG ZLIB_URL=https://zlib.net/zlib-$ZLIB_VERSION.tar.gz
ARG CURL_URL=https://curl.se/download/curl-$CURL_VERSION.tar.gz
ARG PWSH_URL=https://github.com/PowerShell/PowerShell/releases/download/v$PWSH_VERSION/PowerShell-$PWSH_VERSION-win-x64.zip
ENV ZBX_VERSION=$ZBX_VERSION `
BUILD_ARCH=$BUILD_ARCH `
GIT_URL=$GIT_URL PERL_URL=$PERL_URL NASM_URL=$NASM_URL `
@ -71,6 +74,17 @@ RUN Set-Location -Path $env:SystemDrive\.; `
New-Item -ItemType directory -Path $env:BUILD_OUTPUT -Force | Out-Null; `
New-Item -ItemType directory -Path $env:BUILD_SRC -Force | Out-Null; `
`
Write-Host ('Downloading {0} ...' -f $env:PWSH_URL); `
Invoke-WebRequest -OutFile $env:TEMP\pwsh.zip -Uri $env:PWSH_URL; `
`
$sha256 = '4d3028da81170f8d1cd226614582f0a95d3dd5592127cf87a09e3a3568e51a08'; `
$d_sha256 = (Get-FileHash $env:TEMP\pwsh.zip -Algorithm sha256).Hash; `
Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); `
if ((Get-FileHash $env:TEMP\pwsh.zip -Algorithm sha256).Hash -ne $sha256) { `
Write-Host ('Checksum PowerShell ({0}) failed!' -f $d_sha256); `
exit 1; `
}; `
`
Write-Host ('Downloading {0} ...' -f $env:GIT_URL); `
Invoke-WebRequest -OutFile $env:TEMP\git.zip -Uri $env:GIT_URL; `
`
@ -107,6 +121,19 @@ RUN Set-Location -Path $env:SystemDrive\.; `
Write-Host ('Downloading {0} ...' -f $env:VS_BUILDTOOLS_URL); `
Invoke-WebRequest -OutFile $env:TEMP\vs_buildtools.exe $env:VS_BUILDTOOLS_URL; `
`
Write-Host 'Installing PowerShell...'; `
Expand-Archive `
-Path $env:TEMP\pwsh.zip `
-DestinationPath $env:SystemDrive\pwsh\.; `
`
Get-ChildItem -Path $env:SystemDrive\pwsh -Directory | Where-Object { `
$_.Name -match '^(cs|de|es|fr|it|ja|ko|pl|pt-BR|ru|tr|zh-Hans|zh-Hant)$' `
} | Remove-Item -Recurse -Force; `
Get-ChildItem -Path $env:SystemDrive\pwsh -Recurse -Include '*.xml' | Where-Object { $_.FullName -notmatch '\\en-US\\' } | Remove-Item -Force; `
Get-ChildItem -Path $env:SystemDrive\pwsh -Recurse -Include '*.resources.dll' | Where-Object { $_.FullName -notmatch '\\en-US\\' } | Remove-Item -Force; `
Write-Host 'Verifying install ("pwsh -V") ...'; `
& $env:SystemDrive\pwsh\pwsh.exe -V; `
`
Write-Host 'Installing GIT...'; `
Expand-Archive `
-Path $env:TEMP\git.zip `