Skip to content

Commit d996a4b

Browse files
Tpo76claude
andauthored
feat(vmware): create vmware daemon container (#6143)
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 9aa42d2 commit d996a4b

4 files changed

Lines changed: 305 additions & 0 deletions

File tree

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- lib/VMware/share/VMware/VICommon.pm 2025-04-24 17:18:24.938290503 +0200
2+
+++ VICommon.pm 2025-04-24 17:18:18.690399614 +0200
3+
@@ -2319,6 +2319,8 @@
4+
my $user_agent = $self->{user_agent};
5+
$user_agent->cookie_jar->as_string
6+
=~ m/(.*)vmware_soap_session=\"\\\"([0-9a-zA-Z-](.*)+)\\\"\"(.*)/;
7+
+ $user_agent->cookie_jar->as_string
8+
+ =~ m/(.*)vmware_soap_session=[\\\"]*([0-9a-zA-Z-]+)/ unless $2;
9+
return $2;
10+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: docker-builder-connector-vmware
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
pull_request:
10+
paths:
11+
- '.github/workflows/docker-builder-connector-vmware.yml'
12+
- '.github/docker/connector/Dockerfile.connector-vmware'
13+
- 'connectors/vmware/src/**'
14+
15+
jobs:
16+
dependency-scan:
17+
uses: centreon/security-tools/.github/workflows/dependency-analysis.yml@main
18+
19+
validate:
20+
needs: [dependency-scan]
21+
runs-on: ubuntu-24.04
22+
steps:
23+
- name: Checkout sources
24+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
26+
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
27+
28+
- name: Validate Dockerfile build
29+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
30+
with:
31+
file: .github/docker/connector/Dockerfile.connector-vmware
32+
context: .
33+
build-args: |
34+
USE_SOURCE_VMWARE=true
35+
WITH_SDK=false
36+
push: false

sdks-vmware/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# sdks-vmware
2+
3+
This directory is used to provide the proprietary VMware Perl SDK files when building
4+
the `connector-vmware` Docker image with full functionality.
5+
6+
The SDK files are **not included** in this repository due to Broadcom licensing restrictions.
7+
8+
## Required files
9+
10+
| File | Description |
11+
|------|-------------|
12+
| `VMware-vSphere-Perl-SDK-7.0.0-17698549.x86_64.tar.gz` | VMware vSphere Perl SDK 7.0 |
13+
| `vsan-sdk-perl.zip` | VMware vSAN Management SDK for Perl |
14+
15+
## How to get the files
16+
17+
1. Create a free account at [Broadcom Developer Portal](https://developer.broadcom.com)
18+
2. Download **VMware vSphere Perl SDK 7.0** and **vSAN SDK for Perl**
19+
3. Place the downloaded archives in this directory
20+
21+
## Build with SDK (local)
22+
23+
Uses local source code (`USE_SOURCE_VMWARE=true`) — no `.deb` package required.
24+
25+
```bash
26+
docker build \
27+
--build-arg WITH_SDK=true \
28+
--build-arg USE_SOURCE_VMWARE=true \
29+
--file .github/docker/connector/Dockerfile.connector-vmware \
30+
--tag connector-vmware:local \
31+
.
32+
```
33+
34+
## Build without SDK (default — used by CI)
35+
36+
The image still works for plain-text credentials in `centreon_vmware.json`.
37+
`encrypted::` credentials require the SDK.
38+
39+
```bash
40+
docker build \
41+
--file .github/docker/connector/Dockerfile.connector-vmware \
42+
--tag connector-vmware:local \
43+
.
44+
```

0 commit comments

Comments
 (0)