|
| 1 | +# Build arg to select vmware Perl source: false=use .deb (production), true=use local repo (dev/test) |
| 2 | +ARG USE_SOURCE_VMWARE=false |
| 3 | +# Build arg to include VMware Perl SDK (requires proprietary files in sdks-vmware/ — see sdks-vmware/README.md) |
| 4 | +ARG WITH_SDK=false |
| 5 | + |
| 6 | +############################################# |
| 7 | +# Stage 1: Extract files from .deb packages |
| 8 | +############################################# |
| 9 | +FROM debian:12-slim AS extractor |
| 10 | + |
| 11 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 12 | + dpkg \ |
| 13 | + && rm -rf /var/lib/apt/lists/* |
| 14 | + |
| 15 | +# Extract .deb package (mounted via --mount during build) |
| 16 | +RUN --mount=type=bind,source=packages-centreon,target=/packages \ |
| 17 | + mkdir -p /extracted && \ |
| 18 | + cd /packages && \ |
| 19 | + for deb in centreon-plugin-Virtualization-VMWare-daemon*.deb; do \ |
| 20 | + echo "Extracting $deb..."; \ |
| 21 | + dpkg-deb -x "$deb" /extracted/; \ |
| 22 | + done && \ |
| 23 | + echo "=== Extracted Perl modules ===" && \ |
| 24 | + ls -lah /extracted/usr/share/perl5/centreon/ || true && \ |
| 25 | + echo "=== Extracted binaries ===" && \ |
| 26 | + ls -lah /extracted/usr/bin/ || true |
| 27 | + |
| 28 | +############################################# |
| 29 | +# Stage 1b/1c: Perl modules source selector |
| 30 | +# USE_SOURCE_VMWARE=false → extract from .deb (production default) |
| 31 | +# USE_SOURCE_VMWARE=true → copy from local repo source (dev/testing) |
| 32 | +############################################# |
| 33 | +FROM scratch AS vmware-perl-false |
| 34 | +COPY --from=extractor /extracted/usr/share/perl5/centreon /centreon-modules/ |
| 35 | + |
| 36 | +FROM scratch AS vmware-perl-true |
| 37 | +COPY connectors/vmware/src/centreon/ /centreon-modules/ |
| 38 | + |
| 39 | +ARG USE_SOURCE_VMWARE=false |
| 40 | +# hadolint ignore=DL3006 |
| 41 | +FROM vmware-perl-${USE_SOURCE_VMWARE} AS vmware-perl-selected |
| 42 | + |
| 43 | +############################################# |
| 44 | +# Stage 1d/1e: Binary source selector |
| 45 | +############################################# |
| 46 | +FROM scratch AS vmware-bin-false |
| 47 | +COPY --from=extractor /extracted/usr/bin/centreon_vmware.pl /centreon_vmware.pl |
| 48 | +COPY --from=extractor /extracted/usr/bin/centreon_vmware_convert_config_file /centreon_vmware_convert_config_file |
| 49 | + |
| 50 | +FROM scratch AS vmware-bin-true |
| 51 | +COPY connectors/vmware/src/centreon_vmware.pl /centreon_vmware.pl |
| 52 | +COPY connectors/vmware/src/centreon/script/centreon_vmware_convert_config_file /centreon_vmware_convert_config_file |
| 53 | + |
| 54 | +ARG USE_SOURCE_VMWARE=false |
| 55 | +# hadolint ignore=DL3006 |
| 56 | +FROM vmware-bin-${USE_SOURCE_VMWARE} AS vmware-bin-selected |
| 57 | + |
| 58 | +############################################# |
| 59 | +# Stage 2a: VMware SDK — with SDK (WITH_SDK=true) |
| 60 | +# Requires SDK archives in sdks-vmware/ (gitignored — proprietary Broadcom license): |
| 61 | +# - VMware-vSphere-Perl-SDK-7.0.0-17698549.x86_64.tar.gz (download from https://developer.broadcom.com) |
| 62 | +# - vsan-sdk-perl.zip (download from https://developer.broadcom.com) |
| 63 | +# Build with: docker build --build-arg WITH_SDK=true . |
| 64 | +############################################# |
| 65 | +FROM debian:12-slim AS sdk-true |
| 66 | + |
| 67 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 68 | + perl \ |
| 69 | + make \ |
| 70 | + patch \ |
| 71 | + unzip \ |
| 72 | + && rm -rf /var/lib/apt/lists/* |
| 73 | + |
| 74 | +COPY .github/docker/connector/VICommon.patch /tmp/VICommon.patch |
| 75 | + |
| 76 | +RUN --mount=type=bind,source=sdks-vmware,target=/sdks \ |
| 77 | + set -e && \ |
| 78 | + cd /tmp && \ |
| 79 | + tar zxf /sdks/VMware-vSphere-Perl-SDK-7.0.0-17698549.x86_64.tar.gz && \ |
| 80 | + cd vmware-vsphere-cli-distrib && \ |
| 81 | + patch --backup lib/VMware/share/VMware/VICommon.pm /tmp/VICommon.patch && \ |
| 82 | + perl Makefile.PL && \ |
| 83 | + make pure_install && \ |
| 84 | + echo "=== vSphere SDK installed ===" && \ |
| 85 | + ls -lah /usr/local/share/perl/ |
| 86 | + |
| 87 | +RUN --mount=type=bind,source=sdks-vmware,target=/sdks \ |
| 88 | + set -e && \ |
| 89 | + cd /tmp && \ |
| 90 | + unzip /sdks/vsan-sdk-perl.zip && \ |
| 91 | + mkdir -p /usr/local/share/perl5/VMware && \ |
| 92 | + cp ./vsan-sdk-perl/bindings/VIM25Vsanmgmt* /usr/local/share/perl5/VMware/ && \ |
| 93 | + echo "=== vSAN SDK installed ===" && \ |
| 94 | + ls -lah /usr/local/share/perl5/VMware/ |
| 95 | + |
| 96 | +############################################# |
| 97 | +# Stage 2b: VMware SDK — without SDK (WITH_SDK=false, default) |
| 98 | +# Used by CI and public image builds. The daemon starts but encrypted:: |
| 99 | +# credentials won't be decryptable without the SDK. |
| 100 | +############################################# |
| 101 | +FROM debian:12-slim AS sdk-false |
| 102 | + |
| 103 | +RUN mkdir -p /usr/local/share/perl/5.36.0/VMware /usr/local/share/perl5/VMware |
| 104 | + |
| 105 | +# hadolint ignore=DL3006 |
| 106 | +FROM sdk-${WITH_SDK} AS sdk-installer |
| 107 | + |
| 108 | +############################################# |
| 109 | +# Stage 3: Runtime - Debian 12 slim image |
| 110 | +############################################# |
| 111 | +FROM debian:12-slim AS centreon-vmware |
| 112 | + |
| 113 | +ARG VERSION |
| 114 | +ARG STABILITY |
| 115 | + |
| 116 | +# Create users and groups |
| 117 | +RUN groupadd -g 33 www-data 2>/dev/null || true && \ |
| 118 | + groupadd -g 900 centreon && \ |
| 119 | + useradd -u 900 -g centreon -m -r -d /var/spool/centreon -s /bin/bash centreon && \ |
| 120 | + groupadd -g 901 centreon-engine && \ |
| 121 | + useradd -u 901 -g centreon-engine -m -r -d /var/lib/centreon-engine -s /bin/bash centreon-engine && \ |
| 122 | + groupadd -g 903 centreon-gorgone && \ |
| 123 | + useradd -u 903 -g centreon-gorgone -m -r -d /var/lib/centreon-gorgone -s /bin/bash centreon-gorgone && \ |
| 124 | + usermod -aG centreon-engine centreon && \ |
| 125 | + usermod -aG centreon-gorgone centreon |
| 126 | + |
| 127 | +# Add Centreon plugins-stable repository (needed for libnet-curl-perl on amd64) |
| 128 | +RUN apt-get update && apt-get install -y --no-install-recommends gnupg wget ca-certificates && \ |
| 129 | + echo "deb [arch=amd64] https://packages.centreon.com/apt-plugins-stable/ bookworm main" \ |
| 130 | + > /etc/apt/sources.list.d/centreon-plugins.list && \ |
| 131 | + wget -O- https://apt-key.centreon.com | gpg --dearmor \ |
| 132 | + | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1 && \ |
| 133 | + rm -rf /var/lib/apt/lists/* |
| 134 | + |
| 135 | +# Install runtime dependencies |
| 136 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 137 | + perl \ |
| 138 | + libclass-methodmaker-perl \ |
| 139 | + libcrypt-openssl-aes-perl \ |
| 140 | + libcrypt-ssleay-perl \ |
| 141 | + libio-socket-inet6-perl \ |
| 142 | + libjson-xs-perl \ |
| 143 | + liblwp-protocol-https-perl \ |
| 144 | + libsoap-lite-perl \ |
| 145 | + libtext-template-perl \ |
| 146 | + libuuid-perl \ |
| 147 | + libzmq-constants-perl \ |
| 148 | + libzmq-libzmq4-perl \ |
| 149 | + libxml-libxml-perl \ |
| 150 | + libjson-perl \ |
| 151 | + libzmq5 \ |
| 152 | + && rm -rf /var/lib/apt/lists/* |
| 153 | + |
| 154 | +# Install libnet-curl-perl (only available in Centreon plugins repo for amd64, cpanm fallback for arm64) |
| 155 | +RUN ARCH=$(dpkg --print-architecture) && \ |
| 156 | + if [ "$ARCH" = "amd64" ]; then \ |
| 157 | + apt-get update && apt-get install -y --no-install-recommends \ |
| 158 | + libnet-curl-perl && \ |
| 159 | + rm -rf /var/lib/apt/lists/*; \ |
| 160 | + else \ |
| 161 | + apt-get update && apt-get install -y --no-install-recommends \ |
| 162 | + cpanminus \ |
| 163 | + build-essential \ |
| 164 | + libcurl4-openssl-dev \ |
| 165 | + libssl-dev && \ |
| 166 | + rm -rf /var/lib/apt/lists/* && \ |
| 167 | + cpanm --notest Net::Curl; \ |
| 168 | + fi |
| 169 | + |
| 170 | +# Create directory structure |
| 171 | +RUN mkdir -p \ |
| 172 | + /etc/centreon \ |
| 173 | + /tmp/centreon_vmware && \ |
| 174 | + chown -R centreon-gorgone:centreon /etc/centreon && \ |
| 175 | + chmod -R 775 /etc/centreon && \ |
| 176 | + chown centreon:centreon /tmp/centreon_vmware && \ |
| 177 | + chmod 775 /tmp/centreon_vmware |
| 178 | + |
| 179 | +# Copy VMware SDK from installer stage |
| 180 | +# vSphere SDK: make pure_install puts modules in the versioned site path |
| 181 | +COPY --from=sdk-installer /usr/local/share/perl/ /usr/local/share/perl/ |
| 182 | +# vSAN SDK: copied directly to /usr/local/share/perl5/VMware/ |
| 183 | +COPY --from=sdk-installer /usr/local/share/perl5/VMware/ /usr/local/share/perl5/VMware/ |
| 184 | + |
| 185 | +# Copy Perl modules from selector (centreon vmware modules + script modules) |
| 186 | +COPY --from=vmware-perl-selected /centreon-modules/ /usr/share/perl5/centreon/ |
| 187 | + |
| 188 | +# Copy executables from selector |
| 189 | +COPY --from=vmware-bin-selected --chmod=755 /centreon_vmware.pl /usr/bin/centreon_vmware.pl |
| 190 | +COPY --from=vmware-bin-selected --chmod=755 /centreon_vmware_convert_config_file /usr/bin/centreon_vmware_convert_config_file |
| 191 | + |
| 192 | +# Copy default configuration (template with placeholder vCenter URLs) |
| 193 | +COPY --chown=centreon-gorgone:centreon --chmod=660 \ |
| 194 | + connectors/vmware/packaging/config/centreon_vmware-conf.json \ |
| 195 | + /etc/centreon/centreon_vmware.json |
| 196 | + |
| 197 | +# Verify critical files exist |
| 198 | +RUN echo "=== Verification ===" && \ |
| 199 | + ls -lah /usr/bin/centreon_vmware.pl && \ |
| 200 | + ls -lah /usr/bin/centreon_vmware_convert_config_file && \ |
| 201 | + ls -lah /usr/share/perl5/centreon/ && \ |
| 202 | + ls -lah /usr/local/share/perl5/VMware/ && \ |
| 203 | + ls -lah /etc/centreon/ && \ |
| 204 | + echo "=== Files verified ===" |
| 205 | + |
| 206 | +ENV PERL5LIB=/usr/local/share/perl5:/usr/share/perl5:/usr/lib/perl5 |
| 207 | + |
| 208 | +WORKDIR /etc/centreon |
| 209 | + |
| 210 | +USER centreon |
| 211 | + |
| 212 | +CMD ["/usr/bin/perl", "/usr/bin/centreon_vmware.pl", \ |
| 213 | + "--config-extra=/etc/centreon/centreon_vmware.json", \ |
| 214 | + "--logfile=/dev/stdout", \ |
| 215 | + "--severity=error"] |
0 commit comments