From 0cf3bf8f4ecdd55ad0517b94d0ea7397225d2561 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Mon, 26 May 2025 13:34:43 +0900 Subject: [PATCH] Using plain Windows nanoserver image for agent and agent2 images --- .github/workflows/images_build_windows.yml | 10 ++--- Dockerfiles/agent/windows/Dockerfile | 13 ++++--- Dockerfiles/agent2/windows/Dockerfile | 13 ++++--- .../build-base/windows/Dockerfile.agent | 26 +++++++++++++ .../build-base/windows/Dockerfile.agent2 | 38 ++++++++++++++++--- 5 files changed, 78 insertions(+), 22 deletions(-) diff --git a/.github/workflows/images_build_windows.yml b/.github/workflows/images_build_windows.yml index 45b70c0ba..bcc0d2e09 100644 --- a/.github/workflows/images_build_windows.yml +++ b/.github/workflows/images_build_windows.yml @@ -35,8 +35,7 @@ env: IMAGES_PREFIX: "zabbix-" MSFT_BASE_BUILD_IMAGE: "mcr.microsoft.com/windows/servercore" - PWSH_BASE_IMAGE_NAME: "mcr.microsoft.com/powershell" - PWSH_BASE_IMAGE_PREFIX: "lts-nanoserver-" + OS_BASE_IMAGE_NAME: "mcr.microsoft.com/windows/nanoserver" BASE_IMAGE_NAME: "build-base" BASE_BUILD_IMAGE_NAME: "build-mysql" @@ -675,8 +674,7 @@ jobs: BASE_BUILD_OS_TAG: ${{ steps.base_os_tag.outputs.os_tag }} LABEL_REVISION: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} LABEL_CREATED: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} - PWSH_BASE_IMAGE_NAME: ${{ env.PWSH_BASE_IMAGE_NAME }} - PWSH_BASE_IMAGE_PREFIX: ${{ env.PWSH_BASE_IMAGE_PREFIX }} + OS_BASE_IMAGE_NAME: ${{ env.OS_BASE_IMAGE_NAME }} AUTO_PUSH_IMAGES: ${{ env.AUTO_PUSH_IMAGES }} run: | echo "::group::Docker version" @@ -697,8 +695,8 @@ jobs: # PowerShell images based on LTSC 2019 and LTSC 2016 do not have "ltsc" prefix $os_tag_suffix=$Env:BASE_BUILD_OS_TAG - $os_tag_suffix=$os_tag_suffix -replace "ltsc2019",'1809' - $base_image=$Env:PWSH_BASE_IMAGE_NAME + ':' + $Env:PWSH_BASE_IMAGE_PREFIX + $os_tag_suffix + # $os_tag_suffix=$os_tag_suffix -replace "ltsc2019",'1809' + $base_image=$Env:OS_BASE_IMAGE_NAME + ':' + $os_tag_suffix echo "::group::Image tags" echo "$Env:TAGS" diff --git a/Dockerfiles/agent/windows/Dockerfile b/Dockerfiles/agent/windows/Dockerfile index dd3538b4c..e02142c6c 100644 --- a/Dockerfiles/agent/windows/Dockerfile +++ b/Dockerfiles/agent/windows/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # escape=` -ARG OS_BASE_IMAGE=mcr.microsoft.com/powershell:lts-nanoserver-ltsc2022 +ARG OS_BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2022 ARG MAJOR_VERSION=6.0 ARG ZBX_VERSION=${MAJOR_VERSION}.40 @@ -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); ` ` diff --git a/Dockerfiles/agent2/windows/Dockerfile b/Dockerfiles/agent2/windows/Dockerfile index d5a0e1ca4..3818c4f9c 100644 --- a/Dockerfiles/agent2/windows/Dockerfile +++ b/Dockerfiles/agent2/windows/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # escape=` -ARG OS_BASE_IMAGE=mcr.microsoft.com/powershell:lts-nanoserver-ltsc2022 +ARG OS_BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:ltsc2022 ARG MAJOR_VERSION=6.0 ARG ZBX_VERSION=${MAJOR_VERSION}.40 @@ -30,15 +30,18 @@ LABEL org.opencontainers.image.title="Zabbix agent 2" ` 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); ` ` diff --git a/Dockerfiles/build-base/windows/Dockerfile.agent b/Dockerfiles/build-base/windows/Dockerfile.agent index 2c0d090a4..2c5569060 100644 --- a/Dockerfiles/build-base/windows/Dockerfile.agent +++ b/Dockerfiles/build-base/windows/Dockerfile.agent @@ -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.1.5 @@ -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,18 @@ 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 ` diff --git a/Dockerfiles/build-base/windows/Dockerfile.agent2 b/Dockerfiles/build-base/windows/Dockerfile.agent2 index 6b54e15fa..d2aad0b63 100644 --- a/Dockerfiles/build-base/windows/Dockerfile.agent2 +++ b/Dockerfiles/build-base/windows/Dockerfile.agent2 @@ -3,10 +3,11 @@ ARG OS_BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022 FROM ${OS_BASE_IMAGE} -ARG PCRE2_VERSION=10.44 -ARG OPENSSL_VERSION=3.1.5 -ARG GOLANG_VERSION=1.23.2 +ARG PCRE2_VERSION=10.45 +ARG OPENSSL_VERSION=3.4.1 +ARG GOLANG_VERSION=1.24.3 ARG VS_BUILDTOOLS_VERSION=17 +ARG PWSH_VERSION=7.5.1 ARG MSYSTEM=MINGW64 @@ -23,6 +24,8 @@ ARG MSYS2_URL=https://api.github.com/repos/msys2/msys2-installer/releases/latest ARG PCRE2_URL=https://github.com/PhilipHazel/pcre2/releases/download/pcre2-$PCRE2_VERSION/pcre2-$PCRE2_VERSION.zip ARG OPENSSL_URL=https://github.com/openssl/openssl/releases/download/openssl-$OPENSSL_VERSION/openssl-$OPENSSL_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 ` MINGW_URL=$MINGW_URL VS_BUILDTOOLS_URL=$VS_BUILDTOOLS_URL VS_BUILDTOOLS_VERSION=$VS_BUILDTOOLS_VERSION GOLANG_VERSION=$GOLANG_VERSION MSYS2_URL=$MSYS2_URL ` @@ -39,8 +42,8 @@ LABEL org.opencontainers.image.title="Zabbix agent 2 build base for Windows" ` org.opencontainers.image.documentation="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" ` org.opencontainers.image.version="${ZBX_VERSION}" -ADD --checksum=sha256:21c6f0523abfd37a2f5cc85879d0ff32723ab496347f0d20793df888ecec3957 $PCRE2_URL C:\pcre2.zip -ADD --checksum=sha256:6ae015467dabf0469b139ada93319327be24b98251ffaeceda0221848dc09262 $OPENSSL_URL C:\openssl.tar.gz +ADD --checksum=sha256:0e138387df7835d7403b8351e2226c1377da804e0737db0e071b48f07c9d12ee $PCRE2_URL C:\pcre2.zip +ADD --checksum=sha256:002a2d6b30b58bf4bea46c43bdd96365aaf8daa6c428782aa4feee06da197df3 $OPENSSL_URL C:\openssl.tar.gz SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] @@ -58,10 +61,21 @@ 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:GOLANG_URL); ` Invoke-WebRequest -OutFile $env:TEMP\go_lang.zip -Uri $env:GOLANG_URL; ` ` - $sha256 = 'bc28fe3002cd65cec65d0e4f6000584dacb8c71bfaff8801dfb532855ca42513'; ` + $sha256 = 'be9787cb08998b1860fe3513e48a5fe5b96302d358a321b58e651184fa9638b3'; ` $d_sha256 = (Get-FileHash $env:TEMP\go_lang.zip -Algorithm sha256).Hash; ` Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); ` if ($d_sha256 -ne $sha256) { ` @@ -97,6 +111,18 @@ 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 Go Lang...'; ` Expand-Archive -Path $env:TEMP\go_lang.zip -DestinationPath $env:SystemDrive\; ` `