Repository navigation
447 lines (413 loc) · 16.5 KB
/
Copy pathgeneric-plugins.yml
File metadata and controls
447 lines (413 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
name: Generic Plugins
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
paths:
- 'rust-plugins/**'
- 'packaging/centreon-plugin-*-snmp-rs/**'
- 'tests/resources/**'
- 'tests/os/linux/snmp/**'
- 'tests/os/windows/snmp/**'
push:
branches:
- develop
- master
tags:
- 'plugins-*'
paths:
- 'rust-plugins/**'
- 'packaging/centreon-plugin-*-snmp-rs/**'
- 'tests/resources/**'
- 'tests/os/linux/snmp/**'
- 'tests/os/windows/snmp/**'
jobs:
dependency-scan:
uses: centreon/security-tools/.github/workflows/dependency-analysis.yml@main
get-environment:
needs: [dependency-scan]
uses: ./.github/workflows/get-environment.yml
with:
version_file: rust-plugins/Cargo.toml
build:
needs: [get-environment]
if: |
needs.get-environment.outputs.skip_workflow == 'false' &&
needs.get-environment.outputs.stability != 'stable' &&
! cancelled()
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-24.04
arch: amd64
target: x86_64-unknown-linux-musl
- runner: ubuntu-24.04-arm
arch: arm64
target: aarch64-unknown-linux-musl
runs-on: ${{ matrix.runner }}
name: "Build the generic plugins ${{ matrix.arch }}"
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Unit tests
run: |
cd rust-plugins
cargo test
shell: bash
# The binary is built once per architecture and packaged for every supported distribution,
# so it must not depend on the glibc of the runner: the oldest distribution we ship to (el8)
# provides glibc 2.28 while ubuntu-24.04 provides 2.39, and glibc offers no forward
# compatibility. Linking statically against musl removes the dependency on the system libc
# entirely.
# Each architecture is built natively rather than cross-compiled, because the default linker
# of the musl targets is the host cc, which cannot link objects of a foreign architecture.
- name: Build optimized binary
run: |
cd rust-plugins
rustup target add ${{ matrix.target }}
cargo build --release --target ${{ matrix.target }}
# Keep the artifact where the cache, the nfpm configuration and the test job expect it.
mkdir -p target/release
cp target/${{ matrix.target }}/release/centreon-plugin-rust-snmp target/release/
shell: bash
- name: Check the binary has no dynamic dependency
run: |
cd rust-plugins
# A statically linked binary has no NEEDED entry. Do not rely on `file`, which reports
# "static-pie linked" rather than "statically linked" for this target.
if objdump -p target/release/centreon-plugin-rust-snmp | grep NEEDED; then
echo "::error::Binary links against shared libraries and will not run on every supported distribution"
exit 1
fi
echo "Binary is statically linked, it does not depend on the system libc"
shell: bash
- name: Save binary to cache
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: rust-plugins/target/release/
key: ${{ github.sha }}-${{ github.run_id }}-build-generic-plugins-${{ matrix.arch }}
# Add to your PR the label upload-artifacts to get the binaries as artifacts
- if: ${{ contains(github.event.pull_request.labels.*.name, 'upload-artifacts') }}
name: Upload binary artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: binaries-${{ matrix.arch }}
path: rust-plugins/target/release/centreon-plugin-rust-snmp
retention-days: 1
package:
needs: [get-environment, build]
if: |
needs.get-environment.outputs.skip_workflow == 'false' &&
needs.get-environment.outputs.stability != 'stable' &&
! cancelled()
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
# `arch` is the architecture name stamped into the package metadata, which differs
# between packagers (x86_64/aarch64 for rpm, amd64/arm64 for deb), while `binary_arch`
# selects which build cache the binary is restored from.
# The container always runs on amd64: nfpm only writes metadata and does not need to run
# on the target architecture.
include:
- package_extension: rpm
image: packaging-plugins-alma8
distrib: el8
arch: x86_64
binary_arch: amd64
- package_extension: rpm
image: packaging-plugins-alma9
distrib: el9
arch: x86_64
binary_arch: amd64
- package_extension: rpm
image: packaging-plugins-alma10
distrib: el10
arch: x86_64
binary_arch: amd64
- package_extension: deb
image: packaging-plugins-bookworm
distrib: bookworm
arch: amd64
binary_arch: amd64
- package_extension: deb
image: packaging-plugins-bookworm
distrib: bookworm
arch: arm64
binary_arch: arm64
- package_extension: deb
image: packaging-plugins-trixie
distrib: trixie
arch: amd64
binary_arch: amd64
- package_extension: deb
image: packaging-plugins-trixie
distrib: trixie
arch: arm64
binary_arch: arm64
- package_extension: deb
image: packaging-plugins-jammy
distrib: jammy
arch: amd64
binary_arch: amd64
- package_extension: deb
image: packaging-plugins-jammy
distrib: jammy
arch: arm64
binary_arch: arm64
- package_extension: deb
image: packaging-plugins-noble
distrib: noble
arch: amd64
binary_arch: amd64
- package_extension: deb
image: packaging-plugins-noble
distrib: noble
arch: arm64
binary_arch: arm64
container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}
credentials:
username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}
name: Package ${{ matrix.distrib }} ${{ matrix.arch }}
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Restore binary from cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: rust-plugins/target/release/
key: ${{ github.sha }}-${{ github.run_id }}-build-generic-plugins-${{ matrix.binary_arch }}
fail-on-cache-miss: true
- name: Build package
uses: ./.github/actions/package-nfpm
with:
nfpm_file_pattern: "rust-plugins/packaging/centreon-generic-plugins.yaml"
distrib: ${{ matrix.distrib }}
package_extension: ${{ matrix.package_extension }}
version: ${{ needs.get-environment.outputs.version }}
release: 1
arch: ${{ matrix.arch }}
commit_hash: ${{ github.sha }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-generic-plugins-${{ matrix.distrib }}-${{ matrix.arch }}
rpm_gpg_key: ${{ secrets.RPM_GPG_SIGNING_KEY }}
rpm_gpg_signing_key_id: ${{ secrets.RPM_GPG_SIGNING_KEY_ID }}
rpm_gpg_signing_passphrase: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }}
stability: ${{ needs.get-environment.outputs.stability }}
# The architecture must be part of the key: two rows of the matrix share the same
# distribution, and the cache silently keeps the first write on an existing key, which
# would deliver the wrong architecture.
- name: Save to cache
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ./*.${{ matrix.package_extension }}
key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}-${{ matrix.arch }}
test-generic-plugins:
needs: [get-environment, build]
if: |
needs.get-environment.outputs.skip_workflow == 'false' &&
needs.get-environment.outputs.stability != 'stable' &&
! cancelled()
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-24.04
arch: amd64
- runner: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runner }}
container:
# Multi-platform manifest built by docker-builder-testing-plugins.yml: the architecture
# of the runner selects the matching variant.
image: ghcr.io/${{ github.repository }}/testing:bookworm
name: Run robot tests ${{ matrix.arch }}
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Restore binary from cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: rust-plugins/target/release/
key: ${{ github.sha }}-${{ github.run_id }}-build-generic-plugins-${{ matrix.arch }}
fail-on-cache-miss: true
- name: Start SNMP simulator and run robot tests
run: |
mkdir -p /var/lib/snmp/cert_indexes/
useradd snmp || true
snmpsim-command-responder --logging-method=null --agent-udpv4-endpoint=127.0.0.1:2024 --process-user=snmp --process-group=snmp --data-dir='./tests' &
# waiting till localhost is listening on UDP port 2024
timeout 60 bash -c 'while : ; do
# 0100007F:07E8 is 127.0.0.1:2024 in HEX
grep " 0100007F:07E8 " /proc/net/udp >/dev/null && break
sleep 0.5
done ; echo "snmpsim is listening"' || exit 1
# Test all tests that use the rust plugin
robot --include centreon-plugin-rust-snmp --exclude notauto --outputdir /tmp/robot-tests ./tests
shell: bash
- name: Upload logs as artifacts if tests failed
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: test-generic-plugins-log-${{ matrix.arch }}
path: /tmp/robot-tests
retention-days: 1
deliver-packages:
needs: [get-environment, build, package, test-generic-plugins]
if: |
needs.get-environment.outputs.skip_workflow == 'false' &&
(contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) || ( needs.get-environment.outputs.stability == 'stable' && github.event_name != 'workflow_dispatch')) &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- distrib: el8
package_extension: rpm
arch: x86_64
- distrib: el9
package_extension: rpm
arch: x86_64
- distrib: el10
package_extension: rpm
arch: x86_64
- distrib: bookworm
package_extension: deb
arch: amd64
- distrib: bookworm
package_extension: deb
arch: arm64
- distrib: trixie
package_extension: deb
arch: amd64
- distrib: trixie
package_extension: deb
arch: arm64
- distrib: jammy
package_extension: deb
arch: amd64
- distrib: jammy
package_extension: deb
arch: arm64
- distrib: noble
package_extension: deb
arch: amd64
- distrib: noble
package_extension: deb
arch: arm64
name: deliver ${{ matrix.distrib }} ${{ matrix.arch }}
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Delivery
uses: ./.github/actions/package-delivery
with:
module_name: generic-plugins
distrib: ${{ matrix.distrib }}
arch: ${{ matrix.arch }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}-${{ matrix.arch }}
stability: ${{ needs.get-environment.outputs.stability }}
release_type: ${{ needs.get-environment.outputs.release_type }}
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
deliver-packages-pulp:
needs: [get-environment, build, package, test-generic-plugins]
if: |
needs.get-environment.outputs.skip_workflow == 'false' &&
(contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) || ( needs.get-environment.outputs.stability == 'stable' && github.event_name != 'workflow_dispatch')) &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
runs-on: centreon-ubuntu-26.04-small
permissions:
contents: read
id-token: write
pull-requests: read
strategy:
fail-fast: false
matrix:
# package-delivery-pulp takes no arch input: each row simply restores the cache holding
# its own architecture and uploads it.
include:
- distrib: el8
package_extension: rpm
arch: x86_64
- distrib: el9
package_extension: rpm
arch: x86_64
- distrib: el10
package_extension: rpm
arch: x86_64
- distrib: bookworm
package_extension: deb
arch: amd64
- distrib: bookworm
package_extension: deb
arch: arm64
- distrib: trixie
package_extension: deb
arch: amd64
- distrib: trixie
package_extension: deb
arch: arm64
- distrib: jammy
package_extension: deb
arch: amd64
- distrib: jammy
package_extension: deb
arch: arm64
- distrib: noble
package_extension: deb
arch: amd64
- distrib: noble
package_extension: deb
arch: arm64
name: deliver ${{ matrix.distrib }} ${{ matrix.arch }} on pulp
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Deliver packages on Pulp
if: ${{ contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) }}
id: deliver_pulp
uses: ./.github/actions/package-delivery-pulp
with:
module_name: generic-plugins
repository_name: plugins
distrib: ${{ matrix.distrib }}
version: ""
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}-${{ matrix.arch }}
stability: ${{ needs.get-environment.outputs.stability }}
release_type: ${{ needs.get-environment.outputs.release_type }}
is_cloud: "false"
pulp_url: ${{ vars.PULP_API_URL }}
pulp_content_url: ${{ vars.PULP_CONTENT_URL }}
audience: ${{ vars.PULP_OIDC_AUDIENCE }}
- name: Promote packages on Pulp
if: ${{ needs.get-environment.outputs.stability == 'stable' && needs.get-environment.outputs.release_type != '' }}
id: promote_pulp
uses: ./.github/actions/promote-to-stable-pulp
with:
module_name: generic-plugins
repository_name: plugins
distrib: ${{ matrix.distrib }}
major_version: ""
stability: stable
release_type: ${{ needs.get-environment.outputs.release_type }}
is_cloud: "false"
pulp_url: ${{ vars.PULP_API_URL }}
pulp_content_url: ${{ vars.PULP_CONTENT_URL }}
audience: ${{ vars.PULP_OIDC_AUDIENCE }}
set-skip-label:
needs: [get-environment, deliver-packages]
if: |
needs.get-environment.outputs.skip_workflow == 'false' &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
uses: ./.github/workflows/set-pull-request-skip-label.yml