diff --git a/Dockerfiles/build-base/windows/Dockerfile.agent b/Dockerfiles/build-base/windows/Dockerfile.agent index 6dc60555d..29e13c1db 100644 --- a/Dockerfiles/build-base/windows/Dockerfile.agent +++ b/Dockerfiles/build-base/windows/Dockerfile.agent @@ -1,7 +1,6 @@ # syntax=docker/dockerfile:1 # escape=` ARG OS_BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022 -FROM ${OS_BASE_IMAGE} ARG GIT_VERSION=2.47.1 ARG NASM_VERSION=2.16.03 @@ -19,11 +18,26 @@ ARG BUILD_ARCH=x64 ARG MAJOR_VERSION=7.0 ARG ZBX_VERSION=${MAJOR_VERSION}.13 +FROM ${OS_BASE_IMAGE} AS src + +ARG GIT_VERSION +ARG NASM_VERSION +ARG VS_BUILDTOOLS_VERSION +ARG PWSH_VERSION + +ARG PCRE2_VERSION +ARG OPENSSL_VERSION +ARG LIBMODBUS_VERSION +ARG ZLIB_VERSION +ARG CURL_VERSION + +ARG BUILD_ARCH + ARG GIT_URL=https://github.com/git-for-windows/git/releases/download/v$GIT_VERSION.windows.1/MinGit-$GIT_VERSION-64-bit.zip ARG PERL_URL=https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/download/SP_54001_64bit_UCRT/strawberry-perl-5.40.0.1-64bit-portable.zip ARG VS_BUILDTOOLS_URL=https://aka.ms/vs/$VS_BUILDTOOLS_VERSION/release/vs_buildtools.exe -ARG NASM_URL=https://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/win64/nasm-$NASM_VERSION-installer-x64.exe +ARG NASM_URL=https://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/win64/nasm-$NASM_VERSION-win64.zip 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 @@ -33,6 +47,101 @@ 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 +ADD --checksum=sha256:21c6f0523abfd37a2f5cc85879d0ff32723ab496347f0d20793df888ecec3957 $PCRE2_URL build_src\pcre2.zip +ADD --checksum=sha256:002a2d6b30b58bf4bea46c43bdd96365aaf8daa6c428782aa4feee06da197df3 $OPENSSL_URL build_src\openssl.tar.gz +ADD --checksum=sha256:15b4b2e0f68122c2da9b195de5c330489a9c97d40b4a95d2822378dc14d780e7 $LIBMODBUS_URL build_src\libmodbus.tar.gz +ADD --checksum=sha256:9A93B2B7DFDAC77CEBA5A558A580E74667DD6FEDE4585B91EEFB60F03B72DF23 $ZLIB_URL build_src\zlib.tar.gz +ADD --checksum=sha256:a889ac9dbba3644271bd9d1302b5c22a088893719b72be3487bc3d401e5c4e80 $CURL_URL build_src\curl.tar.gz + +ADD --checksum=sha256:4d3028da81170f8d1cd226614582f0a95d3dd5592127cf87a09e3a3568e51a08 $PWSH_URL build_deps\pwsh.zip +ADD --checksum=sha256:50b04b55425b5c465d076cdb184f63a0cd0f86f6ec8bb4d5860114a713d2c29a $GIT_URL build_deps\git.zip +ADD --checksum=sha256:754f3e2a8e473dc68d1540c7802fb166a025f35ef18960c4564a31f8b5933907 $PERL_URL build_deps\perl.zip +ADD --checksum=sha256:3ee4782247bcb874378d02f7eab4e294a84d3d15f3f6ee2de2f47a46aa7226e6 $NASM_URL build_deps\nasm.zip +ADD $VS_BUILDTOOLS_URL build_deps\vs_buildtools.exe + +COPY modbus.vs16.* build_src\libmodbus_project\ + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN $env:BUILD_SRC = [string]::Format('{0}\build_src', $env:SystemDrive); ` + [Environment]::SetEnvironmentVariable('BUILD_SRC', $env:BUILD_SRC, [EnvironmentVariableTarget]::Machine); ` + $env:BUILD_DEPS = [string]::Format('{0}\build_deps', $env:SystemDrive); ` + [Environment]::SetEnvironmentVariable('BUILD_DEPS', $env:BUILD_DEPS, [EnvironmentVariableTarget]::Machine); ` + ` + Set-Location -Path $env:BUILD_DEPS; ` + Write-Host 'Installing PowerShell...'; ` + Expand-Archive ` + -Path $env:BUILD_DEPS\pwsh.zip ` + -DestinationPath $env:BUILD_DEPS\pwsh\.; ` + Get-ChildItem -Path $env:BUILD_DEPS\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:BUILD_DEPS\pwsh -Recurse -Include '*.xml' | Where-Object { $_.FullName -notmatch '\\en-US\\' } | Remove-Item -Force; ` + Get-ChildItem -Path $env:BUILD_DEPS\pwsh -Recurse -Include '*.resources.dll' | Where-Object { $_.FullName -notmatch '\\en-US\\' } | Remove-Item -Force; ` + ` + Write-Host 'Installing NASM...'; ` + Expand-Archive ` + -Path $env:BUILD_DEPS\nasm.zip ` + -DestinationPath $env:BUILD_DEPS\.; ` + Rename-Item -Path $env:BUILD_DEPS\nasm-$env:NASM_VERSION -NewName $env:BUILD_DEPS\nasm; ` + ` + Write-Host 'Installing GIT...'; ` + Expand-Archive ` + -Path $env:BUILD_DEPS\git.zip ` + -DestinationPath $env:BUILD_DEPS\git\.; ` + ` + Write-Host 'Installing Perl...'; ` + Expand-Archive -Path $env:BUILD_DEPS\perl.zip -DestinationPath $env:BUILD_DEPS\perl\; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\perl\c\; ` + ` + Set-Location -Path $env:BUILD_SRC; ` + ` + Write-Host 'Extracting PCRE2 archive ...'; ` + Expand-Archive -Path $env:BUILD_SRC\pcre2.zip -DestinationPath $env:BUILD_SRC; ` + Rename-Item -Path $env:BUILD_SRC\pcre2-$env:PCRE2_VERSION -NewName $env:BUILD_SRC\pcre2; ` + New-Item -ItemType directory -Path "$env:BUILD_SRC\pcre2\build" | Out-Null; ` + ` + Write-Host 'Extracting OpenSSL archive ...'; ` + tar -zxf $env:BUILD_SRC\openssl.tar.gz; ` + Rename-Item -Path $env:BUILD_SRC\openssl-$env:OPENSSL_VERSION -NewName $env:BUILD_SRC\openssl; ` + ` + Write-Host 'Extracting Libmodbus archive ...'; ` + tar -zxf $env:BUILD_SRC\libmodbus.tar.gz; ` + Move-Item -Path $env:BUILD_SRC\libmodbus-$env:LIBMODBUS_VERSION\ -Destination $env:BUILD_SRC\libmodbus; ` + Move-Item -Path $env:BUILD_SRC\libmodbus_project\* -Destination $env:BUILD_SRC\libmodbus\src\win32; ` + Remove-Item -Force -Recurse $env:BUILD_SRC\libmodbus_project\; ` + ` + Write-Host 'Extracting Zlib archive ...'; ` + tar -zxf $env:BUILD_SRC\zlib.tar.gz; ` + Move-Item -Path $env:BUILD_SRC\zlib-$env:ZLIB_VERSION\ -Destination $env:BUILD_SRC\zlib; ` + ` + Write-Host 'Extracting CURL archive ...'; ` + tar -zxf $env:BUILD_SRC\curl.tar.gz; ` + Move-Item -Path $env:BUILD_SRC\curl-$env:CURL_VERSION\ -Destination $env:BUILD_SRC\curl; ` + ` + Write-Host 'Removing downloaded...'; ` + Remove-Item -Force -Recurse $env:BUILD_SRC\*.tar.gz; ` + Remove-Item -Force -Recurse $env:BUILD_SRC\*.zip; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\*.tar.gz; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\*.zip; + +FROM ${OS_BASE_IMAGE} + +ARG GIT_VERSION +ARG NASM_VERSION +ARG VS_BUILDTOOLS_VERSION + +ARG PCRE2_VERSION +ARG OPENSSL_VERSION +ARG LIBMODBUS_VERSION +ARG ZLIB_VERSION +ARG CURL_VERSION + +ARG BUILD_ARCH + +ARG MAJOR_VERSION +ARG ZBX_VERSION + ENV ZBX_VERSION=$ZBX_VERSION ` BUILD_ARCH=$BUILD_ARCH ` GIT_URL=$GIT_URL PERL_URL=$PERL_URL NASM_URL=$NASM_URL ` @@ -50,113 +159,37 @@ LABEL org.opencontainers.image.title="Zabbix agent 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:002a2d6b30b58bf4bea46c43bdd96365aaf8daa6c428782aa4feee06da197df3 $OPENSSL_URL C:\openssl.tar.gz -ADD --checksum=sha256:15b4b2e0f68122c2da9b195de5c330489a9c97d40b4a95d2822378dc14d780e7 $LIBMODBUS_URL C:\libmodbus.tar.gz -ADD --checksum=sha256:9A93B2B7DFDAC77CEBA5A558A580E74667DD6FEDE4585B91EEFB60F03B72DF23 $ZLIB_URL C:\zlib.tar.gz -ADD --checksum=sha256:a889ac9dbba3644271bd9d1302b5c22a088893719b72be3487bc3d401e5c4e80 $CURL_URL C:\curl.tar.gz - -COPY modbus.vs16.* C:\build_src\libmodbus_project\ +COPY --from=src build_src build_src +COPY --from=src build_deps build_deps SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-Location -Path $env:SystemDrive\.; ` [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ` ` - $env:PATH = [string]::Format('{0}\perl\perl\bin;{1}\NASM;{0}\git\cmd;{0}\git\mingw64\bin;{0}\git\usr\bin;', $env:SystemDrive, ${env:ProgramFiles}) + $env:PATH; ` - [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); ` - ` $env:BUILD_OUTPUT = [string]::Format('{0}\build_output', $env:SystemDrive); ` [Environment]::SetEnvironmentVariable('BUILD_OUTPUT', $env:BUILD_OUTPUT, [EnvironmentVariableTarget]::Machine); ` $env:BUILD_SRC = [string]::Format('{0}\build_src', $env:SystemDrive); ` [Environment]::SetEnvironmentVariable('BUILD_SRC', $env:BUILD_SRC, [EnvironmentVariableTarget]::Machine); ` + $env:BUILD_DEPS = [string]::Format('{0}\build_deps', $env:SystemDrive); ` + [Environment]::SetEnvironmentVariable('BUILD_DEPS', $env:BUILD_DEPS, [EnvironmentVariableTarget]::Machine); ` + ` + $env:PATH = [string]::Format('{0}\perl\perl\bin;{0}\NASM;{0}\git\cmd;{0}\git\mingw64\bin;{0}\git\usr\bin;', $env:BUILD_DEPS) + $env:PATH; ` + [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); ` ` 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; ` - ` - $sha256 = '50b04b55425b5c465d076cdb184f63a0cd0f86f6ec8bb4d5860114a713d2c29a'; ` - $d_sha256 = (Get-FileHash $env:TEMP\git.zip -Algorithm sha256).Hash; ` - Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); ` - if ($d_sha256 -ne $sha256) { ` - Write-Host ('Checksum GIT for Windows ({0}) failed!' -f $d_sha256); ` - exit 1; ` - }; ` - ` - Write-Host ('Downloading {0} ...' -f $env:NASM_URL); ` - Invoke-WebRequest -OutFile $env:TEMP\nasm_installer.exe -Uri $env:NASM_URL; ` - ` - $sha256 = '657E1252676CFB26A008835C20A760F731C8E0414469A4ED0F83F0FB059CDD35'; ` - $d_sha256 = (Get-FileHash $env:TEMP\nasm_installer.exe -Algorithm sha256).Hash; ` - Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); ` - if ((Get-FileHash $env:TEMP\nasm_installer.exe -Algorithm sha256).Hash -ne $sha256) { ` - Write-Host ('Checksum NASM ({0}) failed!' -f $d_sha256); ` - exit 1; ` - }; ` - ` - Write-Host ('Downloading {0} ...' -f $env:PERL_URL); ` - Invoke-WebRequest -OutFile $env:TEMP\perl.zip -Uri $env:PERL_URL; ` - ` - $sha256 = '754f3e2a8e473dc68d1540c7802fb166a025f35ef18960c4564a31f8b5933907'; ` - $d_sha256 = (Get-FileHash $env:TEMP\perl.zip -Algorithm sha256).Hash; ` - Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); ` - if ($d_sha256 -ne $sha256) { ` - Write-Host ('Checksum Strawberry Perl ({0}) failed!' -f $d_sha256); ` - exit 1; ` - }; ` - ` - 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 ` - -DestinationPath $env:SystemDrive\git\.; ` - ` - Write-Host 'Verifying install ("git version") ...'; ` + Write-Host 'Verifying install ("git version") ...'; ` + Write-Host $env:VS_BUILDTOOLS_VERSION; ` git version; ` - Write-Host 'Installing NASM...'; ` - Start-Process ` - -FilePath $env:TEMP\nasm_installer.exe ` - -ArgumentList '/S' -Wait; ` ` Write-Host 'Verifying install ("nasm -v") ...'; ` nasm -v; ` - ` - Write-Host 'Installing Perl...'; ` - Expand-Archive -Path $env:TEMP\perl.zip -DestinationPath $env:SystemDrive\perl\; ` - Remove-Item -Force -Recurse $env:SystemDrive\perl\c\; ` - ` - Write-Host 'Verifying install ("perl -V") ...'; ` - perl -V; ` - ` + ` + Write-Host 'Verifying install ("perl -v") ...'; ` + perl -v; ` + ` Write-Host ('{0} - Visual Studio components installing...' -f $(Get-Date -format 'u')); ` - cmd /C start /w $env:TEMP\vs_buildtools.exe ` + cmd /C start /w $env:BUILD_DEPS\vs_buildtools.exe ` --quiet ` --wait ` --norestart ` @@ -181,32 +214,7 @@ RUN Set-Location -Path $env:SystemDrive\.; ` Get-ChildItem -Path """${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer""" -Directory -Recurse | Remove-Item -Force -Recurse; ` ` Write-Host 'Build environment is ready...'; ` - ` - Set-Location -Path $env:BUILD_SRC; ` - ` - Write-Host 'Extracting PCRE2 archive ...'; ` - Expand-Archive -Path $env:SystemDrive\pcre2.zip -DestinationPath $env:BUILD_SRC; ` - Rename-Item -Path $env:BUILD_SRC\pcre2-$env:PCRE2_VERSION -NewName $env:BUILD_SRC\pcre2; ` - New-Item -ItemType directory -Path "$env:BUILD_SRC\pcre2\build" | Out-Null; ` - ` - Write-Host 'Extracting OpenSSL archive ...'; ` - tar -zxf $env:SystemDrive\openssl.tar.gz; ` - Rename-Item -Path $env:BUILD_SRC\openssl-$env:OPENSSL_VERSION -NewName $env:BUILD_SRC\openssl; ` - ` - Write-Host 'Extracting Libmodbus archive ...'; ` - tar -zxf $env:SystemDrive\libmodbus.tar.gz; ` - Move-Item -Path $env:BUILD_SRC\libmodbus-$env:LIBMODBUS_VERSION\ -Destination $env:BUILD_SRC\libmodbus; ` - Move-Item -Path $env:BUILD_SRC\libmodbus_project\* -Destination $env:BUILD_SRC\libmodbus\src\win32; ` - ` - Write-Host 'Extracting Zlib archive ...'; ` - tar -zxf $env:SystemDrive\zlib.tar.gz; ` - Move-Item -Path $env:BUILD_SRC\zlib-$env:ZLIB_VERSION\ -Destination $env:BUILD_SRC\zlib; ` - ` - Write-Host 'Extracting CURL archive ...'; ` - tar -zxf $env:SystemDrive\curl.tar.gz; ` - Move-Item -Path $env:BUILD_SRC\curl-$env:CURL_VERSION\ -Destination $env:BUILD_SRC\curl; ` - ` - Set-Location -Path $env:SystemDrive\.; ` + Set-Location -Path $env:SystemDrive\.; ` ` Import-Module (Get-ChildItem $env:VS_PATH -Recurse -File -Filter Microsoft.VisualStudio.DevShell.dll).FullName; ` Enter-VsDevShell -VsInstallPath $env:VS_PATH -SkipAutomaticLocation -DevCmdArguments """-arch=$env:BUILD_ARCH"""; ` @@ -307,7 +315,4 @@ RUN Set-Location -Path $env:SystemDrive\.; ` ` Move-Item -Path $env:BUILD_SRC\curl\builds\libcurl-vc$env:VS_BUILDTOOLS_VERSION-$env:BUILD_ARCH-release-static-ssl-static-zlib-static-sspi\ -Destination $env:BUILD_OUTPUT\curl; ` Remove-Item -Path $env:BUILD_SRC\curl\builds\* -Force -Recurse; ` - Write-Host 'Curl is ready...'; ` - ` - Write-Host 'Removing downloaded...'; ` - Remove-Item -Force -Recurse $env:TEMP\*; + Write-Host 'Curl is ready...'; diff --git a/Dockerfiles/build-base/windows/Dockerfile.agent2 b/Dockerfiles/build-base/windows/Dockerfile.agent2 index c14b8cc97..36e982687 100644 --- a/Dockerfiles/build-base/windows/Dockerfile.agent2 +++ b/Dockerfiles/build-base/windows/Dockerfile.agent2 @@ -1,7 +1,6 @@ # syntax=docker/dockerfile:1 # escape=` ARG OS_BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022 -FROM ${OS_BASE_IMAGE} ARG PCRE2_VERSION=10.45 ARG OPENSSL_VERSION=3.4.1 @@ -16,16 +15,109 @@ ARG BUILD_ARCH=x64 ARG MAJOR_VERSION=7.0 ARG ZBX_VERSION=${MAJOR_VERSION}.13 +FROM ${OS_BASE_IMAGE} as src + +ARG PCRE2_VERSION +ARG OPENSSL_VERSION +ARG GOLANG_VERSION +ARG VS_BUILDTOOLS_VERSION +ARG PWSH_VERSION + +ARG MSYSTEM + ARG MINGW_URL=https://github.com/niXman/mingw-builds-binaries/releases/download/14.2.0-rt_v12-rev0/x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0.7z ARG VS_BUILDTOOLS_URL=https://aka.ms/vs/$VS_BUILDTOOLS_VERSION/release/vs_buildtools.exe ARG GOLANG_URL=https://go.dev/dl/go$GOLANG_VERSION.windows-amd64.zip -ARG MSYS2_URL=https://api.github.com/repos/msys2/msys2-installer/releases/latest +ARG MSYS2_URL=https://github.com/msys2/msys2-installer/releases/download/2025-02-21/msys2-base-x86_64-20250221.sfx.exe 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 +ADD --checksum=sha256:4d3028da81170f8d1cd226614582f0a95d3dd5592127cf87a09e3a3568e51a08 $PWSH_URL build_deps\pwsh.zip +ADD --checksum=sha256:be9787cb08998b1860fe3513e48a5fe5b96302d358a321b58e651184fa9638b3 $GOLANG_URL build_deps\go_lang.zip +ADD --checksum=sha256:d7270f76483aefe0c88f45284b374e27648dec59fb6f89ee2f5cb62f6a060082 $MINGW_URL build_deps\mingw.7z +ADD --checksum=sha256:6d4952fd65d1924c56620355c3c7d5a1b40e3c7d7be358f6eb1017363d2dbbb1 $MSYS2_URL build_deps\msys2.sfx.exe +ADD $VS_BUILDTOOLS_URL build_deps\vs_buildtools.exe + +ADD --checksum=sha256:0e138387df7835d7403b8351e2226c1377da804e0737db0e071b48f07c9d12ee $PCRE2_URL build_src\pcre2.zip +ADD --checksum=sha256:002a2d6b30b58bf4bea46c43bdd96365aaf8daa6c428782aa4feee06da197df3 $OPENSSL_URL build_src\openssl.tar.gz + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN $env:BUILD_SRC = [string]::Format('{0}\build_src', $env:SystemDrive); ` + [Environment]::SetEnvironmentVariable('BUILD_SRC', $env:BUILD_SRC, [EnvironmentVariableTarget]::Machine); ` + $env:BUILD_DEPS = [string]::Format('{0}\build_deps', $env:SystemDrive); ` + [Environment]::SetEnvironmentVariable('BUILD_DEPS', $env:BUILD_DEPS, [EnvironmentVariableTarget]::Machine); ` + ` + $env:PATH = $env:PATH + [string]::Format(';{0}\mingw64\bin;{0}\go\bin;{0}\msys64\usr\bin;{0}\msys64\{1}\bin', $env:BUILD_DEPS, $env:MSYSTEM.ToLower()); ` + [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); ` + ` + Set-Location -Path $env:BUILD_DEPS; ` + Write-Host 'Installing PowerShell...'; ` + Expand-Archive ` + -Path $env:BUILD_DEPS\pwsh.zip ` + -DestinationPath $env:BUILD_DEPS\pwsh\.; ` + Get-ChildItem -Path $env:BUILD_DEPS\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:BUILD_DEPS\pwsh -Recurse -Include '*.xml' | Where-Object { $_.FullName -notmatch '\\en-US\\' } | Remove-Item -Force; ` + Get-ChildItem -Path $env:BUILD_DEPS\pwsh -Recurse -Include '*.resources.dll' | Where-Object { $_.FullName -notmatch '\\en-US\\' } | Remove-Item -Force; ` + ` + Write-Host 'Installing MSYS2...'; ` + & $env:BUILD_DEPS\msys2.sfx.exe -y -o"""$env:BUILD_DEPS\""" | Out-Null; ` + bash -lc 'pacman --noprogressbar --noconfirm -Syuu'; ` + bash -lc 'pacman --noprogressbar --noconfirm -Syuu'; ` + bash -lc 'pacman --noprogressbar --sync --quiet --noconfirm mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-7zip git'; ` + bash -lc 'pacman --noprogressbar --noconfirm -Scc'; ` + bash -lc 'rm -rf /usr/share/man/* /usr/share/doc/* /usr/share/locale/*'; ` + bash -lc 'rm -rf /$MSYSTEM/usr/share/man/* /$MSYSTEM/usr/share/doc/* /$MSYSTEM/usr/share/locale/*'; ` + bash -lc 'rm -rf /$MSYSTEM/share/man/* /$MSYSTEM/share/doc/* /$MSYSTEM/share/locale/*'; ` + bash -lc 'rm -rf /var/cache/pacman/pkg/*'; ` + taskkill /F /FI 'MODULES eq msys-2.0.dll' | Out-Null; ` + compact /c /i /s:$env:BUILD_DEPS\msys64 | Out-Null; ` + ` + Write-Host 'Installing Mingw-w64...'; ` + 7z x $env:BUILD_DEPS\mingw.7z; ` + compact /c /i /s:$env:BUILD_DEPS\mingw64 | Out-Null; ` + ` + Write-Host 'Installing Go Lang...'; ` + Expand-Archive -Path $env:BUILD_DEPS\go_lang.zip -DestinationPath $env:BUILD_DEPS; ` + ` + Set-Location -Path $env:BUILD_SRC; ` + ` + Write-Host 'Extracting PCRE2 archive ...'; ` + Expand-Archive -Path $env:BUILD_SRC\pcre2.zip -DestinationPath $env:BUILD_SRC; ` + Rename-Item -Path $env:BUILD_SRC\pcre2-$env:PCRE2_VERSION -NewName $env:BUILD_SRC\pcre2; ` + ` + Write-Host 'Extracting OpenSSL archive ...'; ` + $env:SystemDirectory = [Environment]::SystemDirectory; ` + tar -zxf "$env:BUILD_SRC\openssl.tar.gz"; ` + Rename-Item -Path $env:BUILD_SRC\openssl-$env:OPENSSL_VERSION -NewName $env:BUILD_SRC\openssl; ` + ` + Write-Host 'Removing downloaded...'; ` + Remove-Item -Force -Recurse $env:BUILD_SRC\*.tar.gz; ` + Remove-Item -Force -Recurse $env:BUILD_SRC\*.zip; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\*.tar.gz; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\*.zip; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\msys2.sfx.exe; ` + Remove-Item -Force -Recurse $env:BUILD_DEPS\*.7z; + +FROM ${OS_BASE_IMAGE} + +ARG PCRE2_VERSION +ARG OPENSSL_VERSION +ARG GOLANG_VERSION +ARG VS_BUILDTOOLS_VERSION + +ARG MSYSTEM + +ARG BUILD_ARCH + +ARG MAJOR_VERSION +ARG ZBX_VERSION + 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 ` @@ -42,118 +134,37 @@ 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:0e138387df7835d7403b8351e2226c1377da804e0737db0e071b48f07c9d12ee $PCRE2_URL C:\pcre2.zip -ADD --checksum=sha256:002a2d6b30b58bf4bea46c43bdd96365aaf8daa6c428782aa4feee06da197df3 $OPENSSL_URL C:\openssl.tar.gz +COPY --from=src build_src build_src +COPY --from=src build_deps build_deps SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-Location -Path $env:SystemDrive\.; ` [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ` ` - $env:PATH = $env:PATH + [string]::Format(';{0}\mingw64\bin;{0}\go\bin;{0}\msys64\usr\bin;{0}\msys64\{1}\bin', $env:SystemDrive, $env:MSYSTEM.ToLower()); ` - [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); ` - ` $env:BUILD_OUTPUT = [string]::Format('{0}\build_output', $env:SystemDrive); ` [Environment]::SetEnvironmentVariable('BUILD_OUTPUT', $env:BUILD_OUTPUT, [EnvironmentVariableTarget]::Machine); ` $env:BUILD_SRC = [string]::Format('{0}\build_src', $env:SystemDrive); ` [Environment]::SetEnvironmentVariable('BUILD_SRC', $env:BUILD_SRC, [EnvironmentVariableTarget]::Machine); ` + $env:BUILD_DEPS = [string]::Format('{0}\build_deps', $env:SystemDrive); ` + [Environment]::SetEnvironmentVariable('BUILD_DEPS', $env:BUILD_DEPS, [EnvironmentVariableTarget]::Machine); ` + ` + $env:PATH = $env:PATH + [string]::Format(';{0}\mingw64\bin;{0}\go\bin;{0}\msys64\usr\bin;{0}\msys64\{1}\bin', $env:BUILD_DEPS, $env:MSYSTEM.ToLower()); ` + [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); ` ` 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 = '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) { ` - Write-Host ('Checksum Go Lang ({0}) failed!' -f $d_sha256); ` - exit 1; ` - }; ` - ` - Write-Host ('Downloading {0} ...' -f $env:MSYS2_URL); ` - Invoke-WebRequest -OutFile $env:TEMP\msys2.sfx.exe -Uri $(Invoke-RestMethod -UseBasicParsing $env:MSYS2_URL | ` - Select -ExpandProperty "assets" | ` - Select -ExpandProperty "browser_download_url" | ` - Select-String -Pattern '.sfx.exe$').ToString(); ` - ` - $sha256 = 'D96C53ECBFA4B9D81F6C58077965BB2E31472A8BDA4D4446EF8F45F9C601B11D'; ` - $d_sha256 = (Get-FileHash $env:TEMP\msys2.sfx.exe -Algorithm sha256).Hash; ` - Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); ` - if ($d_sha256 -ne $sha256) { ` - Write-Host ('Checksum MSYS2 ({0}) failed!' -f $d_sha256); ` -# exit 1; ` - }; ` - ` - Write-Host ('Downloading {0} ...' -f $env:MINGW_URL); ` - Invoke-WebRequest -OutFile $env:TEMP\mingw.7z -Uri $env:MINGW_URL; ` - ` - $sha256 = 'd7270f76483aefe0c88f45284b374e27648dec59fb6f89ee2f5cb62f6a060082'; ` - $d_sha256 = (Get-FileHash $env:TEMP\mingw.7z -Algorithm sha256).Hash; ` - Write-Host ('Verifying SHA256 ({0}) ...' -f $sha256); ` - if ($d_sha256 -ne $sha256) { ` - Write-Host ('Checksum Mingw-w64 ({0}) failed!' -f $d_sha256); ` - exit 1; ` - }; ` - ` - 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\; ` ` Write-Host 'Verifying install ("go version") ...'; ` go version; ` ` - Write-Host 'Installing MSYS2...'; ` - & $env:TEMP\msys2.sfx.exe -y -o"""$env:SystemDrive\""" | Out-Null; ` - bash -lc 'pacman --noprogressbar --noconfirm -Syuu'; ` - bash -lc 'pacman --noprogressbar --noconfirm -Syuu'; ` - bash -lc 'pacman --noprogressbar --sync --quiet --noconfirm mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-7zip git'; ` - bash -lc 'pacman --noprogressbar --noconfirm -Scc'; ` - bash -lc 'rm -rf /usr/share/man/* /usr/share/doc/* /usr/share/locale/*'; ` - bash -lc 'rm -rf /$MSYSTEM/usr/share/man/* /$MSYSTEM/usr/share/doc/* /$MSYSTEM/usr/share/locale/*'; ` - bash -lc 'rm -rf /$MSYSTEM/share/man/* /$MSYSTEM/share/doc/* /$MSYSTEM/share/locale/*'; ` - bash -lc 'rm -rf /var/cache/pacman/pkg/*'; ` - taskkill /F /FI 'MODULES eq msys-2.0.dll' | Out-Null; ` - compact /c /i /s:$env:SystemDrive\msys64 | Out-Null; ` - ` Write-Host 'Verifying install ("bash --version") ...'; ` bash --version; ` ` - Write-Host 'Installing Mingw-w64...'; ` - 7z x $env:TEMP\mingw.7z; ` - compact /c /i /s:$env:SystemDrive\mingw64 | Out-Null; ` - ` Write-Host 'Verifying install ("gcc -v") ...'; ` gcc -v; ` ` Write-Host ('{0} - Visual Studio components installing...' -f $(Get-Date -format 'u')); ` - cmd /C start /w $env:TEMP\vs_buildtools.exe ` + cmd /C start /w $env:BUILD_DEPS\vs_buildtools.exe ` --quiet ` --wait ` --norestart ` @@ -178,17 +189,6 @@ RUN Set-Location -Path $env:SystemDrive\.; ` ` Write-Host 'Build environment is ready...'; ` ` - Set-Location -Path $env:BUILD_SRC; ` - ` - Write-Host 'Extracting PCRE2 archive ...'; ` - Expand-Archive -Path $env:SystemDrive\pcre2.zip -DestinationPath $env:BUILD_SRC; ` - Rename-Item -Path $env:BUILD_SRC\pcre2-$env:PCRE2_VERSION -NewName $env:BUILD_SRC\pcre2; ` - ` - Write-Host 'Extracting OpenSSL archive ...'; ` - $env:SystemDirectory = [Environment]::SystemDirectory; ` - tar -zxf "$env:SystemDrive\openssl.tar.gz"; ` - Rename-Item -Path $env:BUILD_SRC\openssl-$env:OPENSSL_VERSION -NewName $env:BUILD_SRC\openssl; ` - ` Write-Host 'Building PCRE2 library ...'; ` Set-Location -Path $env:BUILD_SRC\pcre2; ` cmake --log-level=ERROR ` @@ -224,6 +224,4 @@ RUN Set-Location -Path $env:SystemDrive\.; ` mingw32-make -s -j"""$env:NUMBER_OF_PROCESSORS""" install_dev; ` mingw32-make -s clean | Out-Null; ` Write-Host 'OpenSSL is ready...'; ` - ` - Write-Host 'Removing downloaded...'; ` - Remove-Item -Force -Recurse $env:TEMP\*; + Write-Host 'Build environment is ready';