zabbix/Dockerfiles/build-mysql/windows/Dockerfile.agent2
2026-07-15 17:51:41 +09:00

122 lines
7.1 KiB
Docker

# syntax=docker/dockerfile:1.6
# escape=`
ARG MAJOR_VERSION=7.4
ARG ZBX_VERSION=${MAJOR_VERSION}.12
ARG BUILD_BASE_IMAGE=zabbix-build-base:ltsc2022-agent2-${ZBX_VERSION}
FROM ${BUILD_BASE_IMAGE} AS builder
ARG MAJOR_VERSION
ARG ZBX_VERSION
ARG ZABBIX_VERSION_RC_NUM=2400
ARG ZBX_SOURCES=https://git.zabbix.com/scm/zbx/zabbix.git
ARG MONGODB_PLUGIN_SOURCES=https://git.zabbix.com/scm/ap/mongodb.git
ARG POSTGRESQL_PLUGIN_SOURCES=https://git.zabbix.com/scm/ap/postgresql.git
ARG MSSQL_PLUGIN_SOURCES=https://git.zabbix.com/scm/ap/mssql.git
ARG EMBER_PLUS_PLUGIN_SOURCES=https://git.zabbix.com/scm/ap/ember-plus.git
ARG NVIDIA_GPU_PLUGIN_SOURCES=https://git.zabbix.com/scm/ap/nvidia-gpu.git
ARG GIT_BRANCH
ARG ZBX_PLUGINS_VERSION=${GIT_BRANCH:-$ZBX_VERSION}
ENV ZBX_SOURCES=$ZBX_SOURCES MAJOR_VERSION=$MAJOR_VERSION ZBX_VERSION=$ZBX_VERSION GIT_BRANCH=${GIT_BRANCH:-$ZBX_VERSION} `
MONGODB_PLUGIN_SOURCES=$MONGODB_PLUGIN_SOURCES MONGODB_PLUGIN_VERSION=${ZBX_PLUGINS_VERSION} `
POSTGRESQL_PLUGIN_SOURCES=$POSTGRESQL_PLUGIN_SOURCES POSTGRESQL_PLUGIN_VERSION=${ZBX_PLUGINS_VERSION} `
MSSQL_PLUGIN_SOURCES=$MSSQL_PLUGIN_SOURCES MSSQL_PLUGIN_VERSION=${ZBX_PLUGINS_VERSION} `
EMBER_PLUS_PLUGIN_SOURCES=$EMBER_PLUS_PLUGIN_SOURCES EMBER_PLUS_PLUGIN_VERSION=${ZBX_PLUGINS_VERSION} `
NVIDIA_GPU_PLUGIN_SOURCES=$NVIDIA_GPU_PLUGIN_SOURCES NVIDIA_GPU_PLUGIN_VERSION=${ZBX_PLUGINS_VERSION} `
ZABBIX_VERSION_RC_NUM=$ZABBIX_VERSION_RC_NUM `
ZBX_SOURCES_DIR=C:\\zabbix-${ZBX_VERSION} ZBX_OUTPUT_DIR=C:\\zabbix-${ZBX_VERSION}-output
LABEL org.opencontainers.image.title="Zabbix agent 2 build (Windows)" `
org.opencontainers.image.authors="Alexey Pustovalov <alexey.pustovalov@zabbix.com>" `
org.opencontainers.image.vendor="Zabbix SIA" `
org.opencontainers.image.url="https://zabbix.com/" `
org.opencontainers.image.description="Zabbix build for agent 2 images based on Windows" `
org.opencontainers.image.licenses="AGPL v3.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 ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Set-Location -Path $env:SystemDrive\.; `
`
New-Item -ItemType directory -Path $env:ZBX_SOURCES_DIR | Out-Null; `
New-Item -ItemType directory -Path $env:ZBX_OUTPUT_DIR | Out-Null; `
New-Item -ItemType directory -Path $env:ZBX_OUTPUT_DIR\sbin | Out-Null; `
New-Item -ItemType directory -Path $env:ZBX_OUTPUT_DIR\conf | Out-Null; `
New-Item -ItemType directory -Path $env:ZBX_OUTPUT_DIR\conf\zabbix_agentd.d | Out-Null; `
New-Item -ItemType directory -Path $env:ZBX_OUTPUT_DIR\zabbix-agent2-plugin | Out-Null; `
`
Write-Host ('Checkout GIT {0} ({1}) repository ...' -f $env:ZBX_SOURCES, $env:GIT_BRANCH); `
git -c advice.detachedHead=false clone $env:ZBX_SOURCES --branch $env:GIT_BRANCH --depth 1 --single-branch $env:ZBX_SOURCES_DIR; `
Remove-Item -Recurse -Force $env:ZBX_SOURCES_DIR\ui -ErrorAction SilentlyContinue; `
Remove-Item -Recurse -Force $env:ZBX_SOURCES_DIR\templates -ErrorAction SilentlyContinue; `
Remove-Item -Recurse -Force $env:ZBX_SOURCES_DIR\database -ErrorAction SilentlyContinue; `
Remove-Item -Recurse -Force $env:ZBX_SOURCES_DIR\create -ErrorAction SilentlyContinue; `
`
Write-Host ('Building Zabbix agent 2 {0} version ...' -f $env:ZBX_VERSION); `
Set-Location -Path $env:ZBX_SOURCES_DIR; `
$ZbxRevision=(git rev-parse --short HEAD); `
(Get-Content include\version.h).replace('{ZABBIX_REVISION}', $ZbxRevision) | Set-Content include\version.h; `
(Get-Content src\go\pkg\version\version.go).replace('{ZABBIX_REVISION}', $ZbxRevision) | Set-Content src\go\pkg\version\version.go; `
Set-Location -Path $env:ZBX_SOURCES_DIR\build\mingw; `
mingw32-make -j"""$env:NUMBER_OF_PROCESSORS""" `
CGO_LDFLAGS="""-lcrypt32 -L$env:BUILD_OUTPUT\openssl\lib -L$env:BUILD_OUTPUT\pcre2\lib""" `
PCRE2=$env:BUILD_OUTPUT\pcre2 `
OPENSSL=$env:BUILD_OUTPUT\openssl `
RFLAGS="""-DZABBIX_VERSION_RC_NUM=$env:ZABBIX_VERSION_RC_NUM"""; `
`
Write-Host 'Verifying build ("zabbix_agent2.exe -V") ...'; `
& $env:ZBX_SOURCES_DIR\bin\win64\zabbix_agent2.exe -V; `
ldd $env:ZBX_SOURCES_DIR\bin\win64\zabbix_agent2.exe; `
`
Copy-Item -Path $env:ZBX_SOURCES_DIR\bin\win64\zabbix_agent2.exe $env:ZBX_OUTPUT_DIR\sbin; `
Copy-Item -Path $env:ZBX_SOURCES_DIR\src\go\conf\zabbix_agent2.win.conf $env:ZBX_OUTPUT_DIR\conf\zabbix_agent2.conf_template; `
Copy-Item -Recurse -Path $env:ZBX_SOURCES_DIR\src\go\conf\zabbix_agent2.d $env:ZBX_OUTPUT_DIR\conf\zabbix_agent2.d; `
mingw32-make -s clean;
RUN function Build-Plugin { `
param( `
[Parameter(Mandatory)] [string] $Name, `
[Parameter(Mandatory)] [string] $Repo, `
[Parameter(Mandatory)] [string] $Version, `
[Parameter(Mandatory)] [string] $Binary, `
[Parameter(Mandatory)] [string] $Conf, `
[Parameter(Mandatory)] [string] $OutName `
); `
`
$workDir = Join-Path $env:SystemDrive "$Name-plugin-$Version"; `
$outBinDir = Join-Path $env:ZBX_OUTPUT_DIR 'zabbix-agent2-plugin'; `
$outConfDir = Join-Path $env:ZBX_OUTPUT_DIR 'conf\zabbix_agent2.d\plugins.d'; `
$binaryPath = Join-Path $workDir """$Binary.exe"""; `
`
Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue; `
`
Write-Host ('Building {0} plugin {1} version ...' -f $Name, $Version); `
git -c advice.detachedHead=false clone $Repo --branch $Version --depth 1 --single-branch $workDir; `
`
Set-Location -Path $workDir; `
mingw32-make; `
`
Write-Host ('Verifying {0} plugin ({1}.exe -V) ...' -f $Name, $Binary); `
& $binaryPath -V; `
`
Copy-Item -Path $binaryPath -Destination (Join-Path $outBinDir """$OutName.exe""") -Force; `
Copy-Item -Path (Join-Path $workDir $Conf) -Destination $outConfDir -Force; `
`
mingw32-make -s clean; `
}; `
`
New-Item -ItemType Directory -Force -Path (Join-Path $env:ZBX_OUTPUT_DIR 'zabbix-agent2-plugin') | Out-Null; `
New-Item -ItemType Directory -Force -Path (Join-Path $env:ZBX_OUTPUT_DIR 'conf\zabbix_agent2.d\plugins.d') | Out-Null; `
`
Build-Plugin mongodb $env:MONGODB_PLUGIN_SOURCES $env:MONGODB_PLUGIN_VERSION zabbix-agent2-plugin-mongodb mongodb.conf mongodb; `
Build-Plugin postgresql $env:POSTGRESQL_PLUGIN_SOURCES $env:POSTGRESQL_PLUGIN_VERSION zabbix-agent2-plugin-postgresql postgresql.conf postgresql; `
Build-Plugin mssql $env:MSSQL_PLUGIN_SOURCES $env:MSSQL_PLUGIN_VERSION zabbix-agent2-plugin-mssql mssql.conf mssql; `
$env:PATH = $env:PATH + [string]::Format(';{0}', $env:MSYS_BIN); `
Build-Plugin ember $env:EMBER_PLUS_PLUGIN_SOURCES $env:EMBER_PLUS_PLUGIN_VERSION zabbix-agent2-plugin-ember-plus ember.conf ember-plus; `
Build-Plugin nvidia-gpu $env:NVIDIA_GPU_PLUGIN_SOURCES $env:NVIDIA_GPU_PLUGIN_VERSION zabbix-agent2-plugin-nvidia-gpu nvidia.conf nvidia-gpu;