zabbix-docker/Dockerfiles/agent/windows/Dockerfile

228 lines
14 KiB
Docker
Raw Normal View History

# escape=`
ARG BUILD_BASE_IMAGE=mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022
ARG BASE_IMAGE=mcr.microsoft.com/powershell:lts-nanoserver-ltsc2022
FROM $BUILD_BASE_IMAGE as builder_base
ARG PCRE_VERSION=8.45
ARG OPENSSL_VERSION=1.1.1l
ARG LIBMODBUS_VERSION=master
ARG VS_BUILDTOOLS_URL=https://aka.ms/vs/16/release/vs_buildtools.exe
ARG NASM_URL=https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-installer-x64.exe
ARG PERL_URL=https://strawberryperl.com/download/5.32.1.1/strawberry-perl-5.32.1.1-64bit.msi
ARG GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.33.0.windows.2/Git-2.33.0.2-64-bit.exe
ARG LIBMODBUS_URL=https://github.com/stephane/libmodbus.git
ARG VS_DEV_CMD_LOCATION="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat"
ARG VC_VARS_ALL_LOCATION="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
ENV BUILD_ARCH=x64 CPU_MODEL=AMD64 `
PCRE_VERSION=$PCRE_VERSION OPENSSL_VERSION=$OPENSSL_VERSION LIBMODBUS_VERSION=$LIBMODBUS_VERSION `
GIT_URL=$GIT_URL NASM_URL=$NASM_URL PERL_URL=$PERL_URL LIBMODBUS_URL=$LIBMODBUS_URL `
VS_DEV_CMD_LOCATION=$VS_DEV_CMD_LOCATION VC_VARS_ALL_LOCATION=$VC_VARS_ALL_LOCATION
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Set-Location -Path "$env:SystemDrive"\; `
Write-Verbose -Message 'Visual Studio components installing...'; `
Invoke-WebRequest -OutFile "$env:SystemDrive\git-installer.exe" $env:GIT_URL; `
$sha256 = 'a5704733c219e9a0c96bfeb0febef62bc2518bdd4e358bc9519dbc5e63a3b5fe'; `
if ((Get-FileHash "$env:SystemDrive\git-installer.exe" -Algorithm sha256).Hash -ne $sha256) { `
Write-Host "Checksum GIT for Windows failed!"; `
exit 1; `
}; `
Start-Process -FilePath "$env:SystemDrive\git-installer.exe" -argumentlist '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /NOCANCEL /SP- /LOG /COMPONENTS="icons,assoc,assoc_sh,ext,ext\shellhere,gitlfs' -wait; `
Remove-Item -Force -Path "$env:SystemDrive\git-installer.exe"; `
Invoke-WebRequest -OutFile "$env:SystemDrive\nasm-installer.exe" $env:NASM_URL; `
$sha256 = 'a02325b9fe54f917f5d6a3036637b38dbb6addf6f7ba9d344d9b943a143fe7d0'; `
if ((Get-FileHash "$env:SystemDrive\nasm-installer.exe" -Algorithm sha256).Hash -ne $sha256) { `
Write-Host "Checksum NASM failed!"; `
exit 1; `
}; `
Start-Process -FilePath "$env:SystemDrive\nasm-installer.exe" -argumentlist '/S'; `
Invoke-WebRequest -OutFile "$env:SystemDrive\perl-installer.msi" $env:PERL_URL; `
$sha256 = '241a881670164feb0b91bb69d39fbbf84c981bec0d9f8c19959f8f48fd177768'; `
if ((Get-FileHash "$env:SystemDrive\perl-installer.msi" -Algorithm sha256).Hash -ne $sha256) { `
Write-Host "Checksum Strawberry Perl failed!"; `
exit 1; `
}; `
Start-Process -FilePath "msiexec.exe" -argumentlist """/i C:\perl-installer.msi /qn /norestart INSTALLDIR=$env:SystemDrive\Strawberry""" -wait; `
$env:PATH+=""";$env:SystemDrive\Strawberry\perl\bin"""; `
cpan Text::Template; `
Remove-Item -Force -Path "$env:SystemDrive\nasm-installer.exe"; `
Remove-Item -Force -Path "$env:SystemDrive\perl-installer.msi"; `
Invoke-WebRequest -OutFile "$env:SystemDrive\vs_buildtools.exe" $env:VS_BUILDTOOLS_URL; `
$sha256 = 'f3a7e2868c203490a4095231e20e628bf661b7469f2d53626f3fbbdfc161d471'; `
if ((Get-FileHash "$env:SystemDrive\vs_buildtools.exe" -Algorithm sha256).Hash -ne $sha256) { `
Write-Host "Checksum Visual Studio Build tools failed!"; `
exit 1; `
}; `
Write-Host "Visual Studio components installing..."; `
cmd /C start /w "$env:SystemDrive\vs_buildtools.exe" --quiet --wait --norestart --nocache modify `
--installPath """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools""" `
# https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2019
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 `
--add Microsoft.VisualStudio.Component.VC.CMake.Project; `
if ($err = dir $Env:TEMP -Filter dd_setup_*_errors.log | where Length -gt 0 | Get-Content) { `
throw $err; `
}; `
Wait-Process -name msiexec; `
Write-Host "Visual Studio components installed"; `
Remove-Item -Force -Path "$env:SystemDrive\vs_buildtools.exe"; `
Get-ChildItem -Path """${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer""" -Directory -Recurse | Remove-Item -Force Recurse; `
Remove-Item -Force -Recurse "$env:TEMP\*";
RUN Set-Location -Path "$env:SystemDrive"\; `
Import-Module """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; `
Enter-VsDevShell -VsInstallPath """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools""" -DevCmdArguments """-arch=$env:BUILD_ARCH"""; `
Invoke-WebRequest -OutFile "$env:SystemDrive\pcre-$env:PCRE_VERSION.zip" https://ftp.pcre.org/pub/pcre/pcre-$env:PCRE_VERSION.zip; `
$sha256 = '5b709aa45ea3b8bb73052947200ad187f651a2049158fb5bbfed329e4322a977'; `
if ((Get-FileHash "$env:SystemDrive\pcre-$env:PCRE_VERSION.zip" -Algorithm sha256).Hash -ne $sha256) { `
Write-Host "Checksum PCRE library failed!"; `
exit 1; `
}; `
Expand-Archive -Path "$env:SystemDrive\pcre-$env:PCRE_VERSION.zip" -DestinationPath $env:SystemDrive ; `
Rename-Item -Path "$env:SystemDrive\pcre-$env:PCRE_VERSION" -NewName "$env:SystemDrive\pcre_build"; `
New-Item -ItemType directory -Path "$env:SystemDrive\pcre_build\build" | Out-Null; `
Set-Location -Path "$env:SystemDrive\pcre_build\build"; `
cmake -G """Visual Studio 16 2019""" -A $env:BUILD_ARCH -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON -DPCRE_SUPPORT_UTF=ON -DCMAKE_C_FLAGS_RELEASE:string="/MT" ..; `
msbuild PCRE.sln `
-maxcpucount:"""$env:NUMBER_OF_PROCESSORS""" `
/property:Configuration="Release" `
/property:Platform="$env:BUILD_ARCH" `
/target:pcre; `
Remove-Item -Force -Path "$env:SystemDrive\pcre-$env:PCRE_VERSION.zip"
RUN Set-Location -Path "$env:SystemDrive"\; `
$env:PATH+=""";$env:SystemDrive\Strawberry\perl\bin;$env:SystemDrive\Program Files\NASM"""; `
Import-Module """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; `
Enter-VsDevShell -VsInstallPath """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools""" -DevCmdArguments """-arch=$env:BUILD_ARCH"""; `
Invoke-WebRequest -OutFile "$env:SystemDrive\openssl-$env:OPENSSL_VERSION.tar.gz" https://www.openssl.org/source/openssl-$env:OPENSSL_VERSION.tar.gz; `
$sha256 = '0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1'; `
if ((Get-FileHash "$env:SystemDrive\openssl-$env:OPENSSL_VERSION.tar.gz" -Algorithm sha256).Hash -ne $sha256) { `
Write-Host "Checksum OpenSSL library failed!"; `
exit 1; `
}; `
tar -zxf $env:SystemDrive\openssl-$env:OPENSSL_VERSION.tar.gz; `
Rename-Item -Path "$env:SystemDrive\openssl-$env:OPENSSL_VERSION" -NewName "$env:SystemDrive\openssl_build"; `
Set-Location -Path "$env:SystemDrive\openssl_build"; `
perl $env:SystemDrive\openssl_build\Configure `
VC-WIN64A `
no-shared `
no-ui-console `
no-tests `
# enable-capieng `
no-capieng `
--api=1.1.0 `
--prefix="$env:SystemDrive\openssl_output_$env:BUILD_ARCH" `
--openssldir="$env:SystemDrive\openssl_output_ssl"; `
set CL=/MP; `
nmake; `
nmake install_sw; `
Remove-Item -Force -Path "$env:SystemDrive\openssl-$env:OPENSSL_VERSION.tar.gz"
COPY modbus.vs16.vcxproj c:\
COPY modbus.vs16.sln c:\
COPY modbus.vs16.vcxproj.filters c:\
RUN Set-Location -Path "$env:SystemDrive"; `
Import-Module """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; `
Enter-VsDevShell -VsInstallPath """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools""" -DevCmdArguments """-arch=$env:BUILD_ARCH"""; `
Start-Process -FilePath "${env:ProgramFiles}\Git\bin\git.exe" -Wait -ArgumentList """-c advice.detachedHead=false clone $env:LIBMODBUS_URL --branch $env:LIBMODBUS_VERSION --depth 1 --single-branch libmodbus"""; `
Copy-Item -Path "$env:SystemDrive\modbus.vs16.vcxproj" "$env:SystemDrive\libmodbus\src\win32\modbus.vs16.vcxproj"; `
Copy-Item -Path "$env:SystemDrive\modbus.vs16.sln" "$env:SystemDrive\libmodbus\src\win32\modbus.vs16.sln"; `
Copy-Item -Path "$env:SystemDrive\modbus.vs16.vcxproj.filters" "$env:SystemDrive\libmodbus\src\win32\modbus.vs16.vcxproj.filters"; `
Set-Location -Path "$env:SystemDrive\libmodbus\src\win32"; `
cscript .\configure.js; `
msbuild modbus.vs16.sln `
-maxcpucount:"""$env:NUMBER_OF_PROCESSORS""" `
/property:Configuration="Release" `
/property:Platform="$env:BUILD_ARCH"
FROM builder_base as builder_zabbix
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG MAJOR_VERSION=6.0
ARG ZBX_VERSION=${MAJOR_VERSION}.0
ARG ZABBIX_VERSION_RC_NUM=2400
ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ARG ZBX_COMPONENT=all
ENV ZBX_SOURCES=$ZBX_SOURCES MAJOR_VERSION=$MAJOR_VERSION ZBX_VERSION=$ZBX_VERSION ZABBIX_VERSION_RC_NUM=$ZABBIX_VERSION_RC_NUM
RUN Set-Location -Path "$env:SystemDrive"\; `
Import-Module """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; `
Enter-VsDevShell -VsInstallPath """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\BuildTools""" -DevCmdArguments """-arch=$env:BUILD_ARCH"""; `
Start-Process -FilePath "${env:ProgramFiles}\Git\bin\git.exe" -Wait -ArgumentList """-c advice.detachedHead=false clone $env:ZBX_SOURCES --branch master --depth 1 --single-branch zabbix-$env:ZBX_VERSION"""; `
Write-Host "Building Zabbix $env:ZBX_VERSION version"; `
Set-Location -Path "$env:SystemDrive\zabbix-$env:ZBX_VERSION"; `
$ZbxRevision=(git rev-parse --short HEAD); `
(Get-Content include/version.h).replace('{ZABBIX_REVISION}', $ZbxRevision) | Set-Content include/version.h; `
Set-Location -Path "$env:SystemDrive\zabbix-$env:ZBX_VERSION\build\win32\project"; `
set CL=/MP; `
nmake -f Makefile `
CPU=$env:CPU_MODEL `
CFLAGS="""/D ZABBIX_VERSION_REVISION=$ZbxRevision /D HAVE_LIBMODBUS_STATIC""" `
PCREINCDIR="$env:SystemDrive\pcre_build\build" `
PCRELIBDIR="$env:SystemDrive\pcre_build\build\Release" TLS=openssl `
RFLAGS="""/D ZABBIX_VERSION_REVISION=$ZbxRevision /D ZABBIX_VERSION_RC_NUM=$env:ZABBIX_VERSION_RC_NUM""" `
# LIBS="Crypt32.lib" `
TLSINCDIR="$env:SystemDrive\openssl_output_$env:BUILD_ARCH\include" `
TLSLIBDIR="$env:SystemDrive\openssl_output_$env:BUILD_ARCH\lib" `
MODBINCDIR="$env:SystemDrive\libmodbus\src" `
MODBLIBDIR="$env:SystemDrive\libmodbus\src\win32\$env:BUILD_ARCH\Release" `
$env:ZBX_COMPONENT; `
New-Item -ItemType directory -Path "$env:SystemDrive\zabbix" | Out-Null; `
New-Item -ItemType directory -Path "$env:SystemDrive\zabbix\sbin" | Out-Null; `
New-Item -ItemType directory -Path "$env:SystemDrive\zabbix\conf" | Out-Null; `
& $env:SystemDrive\zabbix-$env:ZBX_VERSION\bin\win64\zabbix_agentd.exe -V; `
dumpbin /dependents $env:SystemDrive\zabbix-$env:ZBX_VERSION\bin\win64\zabbix_agentd.exe; `
Copy-Item -Path "$env:SystemDrive\zabbix-$env:ZBX_VERSION\bin\win64\zabbix_agentd.exe" "$env:SystemDrive\zabbix\sbin"; `
Copy-Item -Path "$env:SystemDrive\zabbix-$env:ZBX_VERSION\bin\win64\zabbix_get.exe" "$env:SystemDrive\zabbix\sbin"; `
Copy-Item -Path "$env:SystemDrive\zabbix-$env:ZBX_VERSION\bin\win64\zabbix_sender.exe" "$env:SystemDrive\zabbix\sbin"; `
Copy-Item -Path "$env:SystemDrive\zabbix-$env:ZBX_VERSION\conf\zabbix_agentd.win.conf" "$env:SystemDrive\zabbix\conf"
FROM $BASE_IMAGE
ARG MAJOR_VERSION=6.0
ARG ZBX_VERSION=${MAJOR_VERSION}.0
ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
LABEL org.opencontainers.image.title="Zabbix agent" `
org.opencontainers.image.authors="Alexey Pustovalov <alexey.pustovalov@zabbix.com>" `
org.opencontainers.image.vendor="Zabbix LLC" `
org.opencontainers.image.url="https://zabbix.com/" `
org.opencontainers.image.description="Zabbix agent is deployed on a monitoring target to actively monitor local resources and applications" `
org.opencontainers.image.licenses="GPL v2.0" `
org.opencontainers.image.documentation="https://www.zabbix.com/documentation/${MAJOR_VERSION}/manual/installation/containers" `
org.opencontainers.image.version="${ZBX_VERSION}" `
org.opencontainers.image.source="${ZBX_SOURCES}"
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';"]
WORKDIR C:\zabbix\
COPY --from=builder_zabbix ["C:\\zabbix", "C:\\zabbix"]
COPY [".\\docker-entrypoint.ps1", "C:\\zabbix"]
USER ContainerAdministrator
RUN setx /M PATH """$env:PATH;$env:SystemDrive\zabbix\sbin;$env:SystemDrive\zabbix\bin;"""; `
setx /M ZbxDir """$env:SystemDrive\zabbix"""
RUN Set-Location -Path "$env:SystemDrive"\; `
New-Item -ItemType directory -Path "$env:ZbxDir\conf\zabbix_agentd.d" | Out-Null; `
New-Item -ItemType directory -Path "$env:ZbxDir\enc" | Out-Null; `
New-Item -ItemType directory -Path "$env:ZbxDir\modules" | Out-Null; `
net user /add zabbix; `
$acl = Get-Acl -Path $env:ZbxDir; `
$ace = New-Object Security.AccessControl.FileSystemAccessRule ('zabbix', 'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow'); `
$acl.AddAccessRule($ace); `
Set-Acl -AclObject $acl -Path $env:ZbxDir
USER zabbix
EXPOSE 10050/TCP
CMD C:\zabbix\docker-entrypoint.ps1 C:\zabbix\sbin\zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -f