From 9a0f5773e3f1c4a981a296be9e0d8f4ee130cb50 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Mon, 26 May 2025 11:29:59 +0900 Subject: [PATCH] Using plain Windows nanoserver image for agent and agent2 images --- .github/workflows/images_build_windows.yml | 2 +- Dockerfiles/agent2/windows/Dockerfile | 13 ++++++---- .../build-base/windows/Dockerfile.agent | 1 - .../build-base/windows/Dockerfile.agent2 | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/.github/workflows/images_build_windows.yml b/.github/workflows/images_build_windows.yml index 9ac178483..bcc0d2e09 100644 --- a/.github/workflows/images_build_windows.yml +++ b/.github/workflows/images_build_windows.yml @@ -695,7 +695,7 @@ 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' + # $os_tag_suffix=$os_tag_suffix -replace "ltsc2019",'1809' $base_image=$Env:OS_BASE_IMAGE_NAME + ':' + $os_tag_suffix echo "::group::Image tags" diff --git a/Dockerfiles/agent2/windows/Dockerfile b/Dockerfiles/agent2/windows/Dockerfile index 818e52496..f2490286f 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=7.4 ARG ZBX_VERSION=${MAJOR_VERSION} @@ -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 3bfa4de04..7624baef6 100644 --- a/Dockerfiles/build-base/windows/Dockerfile.agent +++ b/Dockerfiles/build-base/windows/Dockerfile.agent @@ -125,7 +125,6 @@ RUN Set-Location -Path $env:SystemDrive\.; ` 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; ` diff --git a/Dockerfiles/build-base/windows/Dockerfile.agent2 b/Dockerfiles/build-base/windows/Dockerfile.agent2 index 81a5ade00..2d8fab31c 100644 --- a/Dockerfiles/build-base/windows/Dockerfile.agent2 +++ b/Dockerfiles/build-base/windows/Dockerfile.agent2 @@ -7,6 +7,7 @@ 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=UCRT64 @@ -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 ` @@ -58,6 +61,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:GOLANG_URL); ` Invoke-WebRequest -OutFile $env:TEMP\go_lang.zip -Uri $env:GOLANG_URL; ` ` @@ -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\; ` `