-
Notifications
You must be signed in to change notification settings - Fork 0
921 lines (781 loc) · 34.3 KB
/
build.yml
File metadata and controls
921 lines (781 loc) · 34.3 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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
name: 🚀 Build
run-name: 🚀 Build - ${{ inputs.exporters && (inputs.exporters == '[]' && 'All exporters' || 'Custom list') || 'Auto-detected' }}
on:
workflow_dispatch:
inputs:
exporters:
description: 'JSON array of exporters (empty=auto-detect, []=all, ["name1","name2"]=specific)'
required: false
type: string
default: ''
force_rebuild:
description: 'Force rebuild (ignore state_manager)'
required: false
type: boolean
default: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# Ensure only one build runs at a time to prevent gh-pages conflicts
concurrency:
group: build
cancel-in-progress: false
jobs:
# Discover exporters to build (either from input or auto-detection)
discover:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
outputs:
exporters: ${{ steps.detect.outputs.exporters }}
build_needed: ${{ steps.detect.outputs.build_needed }}
rpm_matrix: ${{ steps.generate-matrices.outputs.rpm_matrix }}
deb_matrix: ${{ steps.generate-matrices.outputs.deb_matrix }}
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: 🔍 Detect Exporters to Build
id: detect
env:
INPUT_EXPORTERS: ${{ inputs.exporters }}
FORCE_REBUILD: ${{ inputs.force_rebuild }}
PYTHONPATH: ${{ github.workspace }}
run: |
echo "::group::🔍 Determining exporters to build"
# Check if exporters were provided as input
if [ -n "$INPUT_EXPORTERS" ] && [ "$INPUT_EXPORTERS" != "[]" ]; then
echo "Using provided exporters list"
echo "exporters=$INPUT_EXPORTERS" >> $GITHUB_OUTPUT
echo "build_needed=true" >> $GITHUB_OUTPUT
count=$(echo "$INPUT_EXPORTERS" | jq '. | length')
echo "✓ Found $count exporter(s) to build (from input)"
echo "$INPUT_EXPORTERS" | jq -r '.[]' | while read exp; do
echo " → $exp"
done
else
echo "Auto-detecting exporters using state manager"
# state_manager writes directly to $GITHUB_OUTPUT (exporters and build_needed)
python3 -m core.engine.state_manager
fi
echo "::endgroup::"
- name: 🔧 Generate Dynamic Matrices
if: steps.detect.outputs.build_needed == 'true'
id: generate-matrices
env:
EXPORTERS_LIST: ${{ steps.detect.outputs.exporters }}
run: |
echo "::group::🔧 Generating filtered build matrices"
python3 << 'PYTHON_EOF'
import json
import os
import yaml
exporters = json.loads(os.environ['EXPORTERS_LIST'])
rpm_combinations = []
deb_combinations = []
rpm_dists = ['el8', 'el9', 'el10']
# Limit DEB distributions to stay under GitHub's 256 matrix job limit
# With ~34 exporters × 2 distros × 2 archs = ~136 jobs (safe margin)
deb_dists = ['debian-12', 'debian-13']
for exporter in exporters:
manifest_path = f'exporters/{exporter}/manifest.yaml'
try:
with open(manifest_path) as f:
manifest = yaml.safe_load(f)
# Get supported architectures
supported_archs = manifest.get('build', {}).get('archs', ['amd64', 'arm64'])
# RPM matrix
if manifest.get('artifacts', {}).get('rpm', {}).get('enabled', False):
rpm_targets = manifest.get('artifacts', {}).get('rpm', {}).get('targets', [])
for dist in rpm_targets:
if dist in rpm_dists:
for arch in supported_archs:
rpm_combinations.append({
'exporter': exporter,
'arch': arch,
'dist': dist
})
# DEB matrix
if manifest.get('artifacts', {}).get('deb', {}).get('enabled', False):
deb_targets = manifest.get('artifacts', {}).get('deb', {}).get('targets', [])
for dist in deb_targets:
if dist in deb_dists:
for arch in supported_archs:
deb_combinations.append({
'exporter': exporter,
'arch': arch,
'dist': dist
})
except Exception as e:
print(f"Warning: Failed to process {exporter}: {e}")
continue
# Generate matrices
rpm_matrix = {'include': rpm_combinations} if rpm_combinations else {'include': []}
deb_matrix = {'include': deb_combinations} if deb_combinations else {'include': []}
# Write to GITHUB_OUTPUT
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'rpm_matrix={json.dumps(rpm_matrix)}\n')
f.write(f'deb_matrix={json.dumps(deb_matrix)}\n')
print(f"✓ Generated RPM matrix: {len(rpm_combinations)} jobs")
print(f"✓ Generated DEB matrix: {len(deb_combinations)} jobs")
PYTHON_EOF
echo "::endgroup::"
- name: 📊 Generate Summary
if: steps.detect.outputs.build_needed == 'true'
env:
EXPORTERS_LIST: ${{ steps.detect.outputs.exporters }}
run: |
echo "## 🏗️ Full Build Started" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Exporters to build:**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "$EXPORTERS_LIST" | jq -r '.[] | "- **" + . + "**"' >> $GITHUB_STEP_SUMMARY
# Build Docker images (parallel per exporter)
build-docker:
name: Docker - ${{ matrix.exporter }}
needs: discover
if: needs.discover.outputs.build_needed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
exporter: ${{ fromJson(needs.discover.outputs.exporters) }}
permissions:
contents: read
packages: write
security-events: write
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: Check if Docker build is enabled
id: check
run: |
exporter="${{ matrix.exporter }}"
is_enabled=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m.get('artifacts', {}).get('docker', {}).get('enabled', False))")
is_arch_supported=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print('amd64' in m.get('build', {}).get('archs', ['amd64', 'arm64']))")
if [ "$is_enabled" = "True" ] && [ "$is_arch_supported" = "True" ]; then
echo "enabled=true" >> $GITHUB_OUTPUT
else
echo "enabled=false" >> $GITHUB_OUTPUT
echo "Docker build disabled or amd64 not supported for $exporter"
fi
- name: Log in to Registry
if: steps.check.outputs.enabled == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
if: steps.check.outputs.enabled == 'true'
uses: docker/setup-buildx-action@v3
- name: 🐳 Build and Push Docker Image
if: steps.check.outputs.enabled == 'true'
env:
PYTHONPATH: ${{ github.workspace }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
exporter="${{ matrix.exporter }}"
echo "::group::🔧 Generating build files"
python3 -m core.engine.builder \
--manifest "exporters/$exporter/manifest.yaml" \
--output-dir "build/$exporter" \
--arch amd64
echo "::endgroup::"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
description=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m.get('description', ''))")
if [ -f "build/$exporter/Dockerfile" ]; then
echo "::group::🐳 Building and pushing image"
image_id="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$exporter"
image_id=$(echo $image_id | tr '[:upper:]' '[:lower:]')
docker buildx build \
--file "build/$exporter/Dockerfile" \
--push \
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}/tree/main/exporters/$exporter" \
--label "org.opencontainers.image.documentation=https://sckyzo.github.io/monitoring-hub/" \
--label "org.opencontainers.image.description=$description" \
--tag "$image_id:$version" \
--tag "$image_id:latest" \
--platform linux/amd64 \
"build/$exporter"
echo "✓ Built and pushed: $image_id:$version"
echo "::endgroup::"
fi
- name: Normalize Image Name
if: steps.check.outputs.enabled == 'true'
id: normalize
run: |
image_name="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.exporter }}:latest"
image_name=$(echo "$image_name" | tr '[:upper:]' '[:lower:]')
echo "image_ref=$image_name" >> $GITHUB_OUTPUT
- name: 🔒 Security Scan with Trivy
if: steps.check.outputs.enabled == 'true'
uses: aquasecurity/trivy-action@0.34.0
with:
image-ref: ${{ steps.normalize.outputs.image_ref }}
format: 'sarif'
output: 'trivy-${{ matrix.exporter }}.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
continue-on-error: true
- name: Check SARIF File
id: check-sarif
if: steps.check.outputs.enabled == 'true'
run: |
if [ -f "trivy-${{ matrix.exporter }}.sarif" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "⚠️ SARIF file not found, skipping upload"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Upload Trivy Results
if: steps.check.outputs.enabled == 'true' && steps.check-sarif.outputs.exists == 'true'
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: 'trivy-${{ matrix.exporter }}.sarif'
category: 'trivy-${{ matrix.exporter }}'
- name: 🧪 Container Smoke Test
if: steps.check.outputs.enabled == 'true'
run: |
exporter="${{ matrix.exporter }}"
v_enabled=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m.get('artifacts', {}).get('docker', {}).get('validation', {}).get('enabled', True))")
v_port=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m.get('artifacts', {}).get('docker', {}).get('validation', {}).get('port', 'None'))")
v_cmd=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m.get('artifacts', {}).get('docker', {}).get('validation', {}).get('command', 'None'))")
v_args=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m.get('artifacts', {}).get('docker', {}).get('validation', {}).get('args', 'None'))")
if [ "$v_enabled" != "True" ]; then
echo "Smoke test disabled for $exporter"
exit 0
fi
if [ "$v_port" = "None" ] && [ "$v_cmd" = "None" ]; then
echo "No validation configured, skipping"
exit 0
fi
image_id="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$exporter:latest"
image_id=$(echo $image_id | tr '[:upper:]' '[:lower:]')
# Command-based validation
if [ "$v_cmd" != "None" ]; then
echo "🧪 Testing command: $v_cmd"
if docker run --rm $image_id $v_cmd; then
echo "✅ Command validation passed"
else
echo "❌ Command validation failed"
exit 1
fi
fi
# Port-based validation
if [ "$v_port" != "None" ]; then
echo "🧪 Testing port: $v_port"
run_args=""
[ "$v_args" != "None" ] && run_args="$v_args"
container_id=$(docker run -d -p 9999:$v_port $image_id $run_args)
success=false
for i in {1..5}; do
echo "Attempt $i: Checking http://localhost:9999/metrics"
if curl -s --fail http://localhost:9999/metrics | grep -qiE "prometheus|exporter|metrics|# HELP|# TYPE"; then
echo "✅ Port validation passed"
success=true
break
fi
sleep 2
done
if [ "$success" = false ]; then
echo "❌ Port validation failed"
docker logs $container_id
docker rm -f $container_id
exit 1
fi
docker rm -f $container_id
fi
- name: 📝 Generate Artifact Metadata
if: steps.check.outputs.enabled == 'true'
run: |
exporter="${{ matrix.exporter }}"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
build_dir="build/$exporter"
echo "::group::📝 Generating V3 catalog metadata for Docker"
# Generate Docker metadata
image_id="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$exporter"
image_id=$(echo $image_id | tr '[:upper:]' '[:lower:]')
# Create docker images JSON array
docker_images="[{\"registry\":\"${{ env.REGISTRY }}\",\"repository\":\"${{ env.IMAGE_NAME }}/$exporter\",\"tags\":[\"$version\",\"latest\"],\"architectures\":[\"linux/amd64\"],\"created\":\"$(date -u +"%Y-%m-%dT%H:%M:%SZ")\"}]"
# Generate V3 catalog metadata for Docker
python3 core/scripts/generate_artifact_metadata.py \
--type docker \
--exporter "$exporter" \
--version "$version" \
--docker-images "$docker_images" \
--status "success" \
--output "$build_dir/docker.json"
echo "✓ Docker metadata generated: $build_dir/docker.json"
echo "::endgroup::"
- name: Upload Artifacts
if: steps.check.outputs.enabled == 'true'
uses: actions/upload-artifact@v6
with:
name: docker-${{ matrix.exporter }}
path: build/**/docker.json
if-no-files-found: ignore
retention-days: 7
# Build RPM packages (parallel per exporter, arch, dist)
build-rpm:
name: RPM - ${{ matrix.exporter }} (${{ matrix.dist }}/${{ matrix.arch }})
needs: discover
if: needs.discover.outputs.build_needed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.discover.outputs.rpm_matrix) }}
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Set up QEMU
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@v3
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: 📦 Build RPM
env:
PYTHONPATH: ${{ github.workspace }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
exporter="${{ matrix.exporter }}"
arch="${{ matrix.arch }}"
dist="${{ matrix.dist }}"
echo "::group::🔧 Generating spec file"
case $dist in
el8) image="almalinux:8" ;;
el9) image="almalinux:9" ;;
el10) image="quay.io/centos/centos:stream10" ;;
*) image="almalinux:9" ;;
esac
build_dir="build/$exporter-$arch-$dist"
python3 -m core.engine.builder \
--manifest "exporters/$exporter/manifest.yaml" \
--output-dir "$build_dir" \
--arch "$arch"
echo "::endgroup::"
spec_file="$build_dir/$exporter.spec"
if [ -f "$spec_file" ]; then
echo "::group::🐳 Building RPM in container"
chmod +x core/scripts/build_rpm.sh core/scripts/rpm_entrypoint.sh
./core/scripts/build_rpm.sh "$spec_file" "$build_dir/rpms" "$arch" "$image"
echo "::endgroup::"
fi
- name: 🔐 Sign RPM
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
run: |
exporter="${{ matrix.exporter }}"
build_dir="build/$exporter-${{ matrix.arch }}-${{ matrix.dist }}"
rpm_file=$(find "$build_dir/rpms" -name "*.rpm" | head -1)
if [ -z "$rpm_file" ]; then
echo "⚠️ No RPM file found, skipping signing"
exit 0
fi
echo "::group::🔐 Signing RPM"
chmod +x core/scripts/sign_rpm_container.sh
./core/scripts/sign_rpm_container.sh "$rpm_file" "$GPG_PRIVATE_KEY" "$GPG_PASSPHRASE" "$GPG_KEY_ID"
echo "::endgroup::"
- name: ⬆️ Upload to GitHub Releases
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
exporter="${{ matrix.exporter }}"
build_dir="build/$exporter-${{ matrix.arch }}-${{ matrix.dist }}"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
rpm_files=$(find "$build_dir/rpms" -name "*.rpm")
if [ -z "$rpm_files" ]; then
echo "⚠️ No RPM files to upload"
exit 0
fi
echo "::group::⬆️ Uploading to GitHub Releases"
python3 core/scripts/upload_to_release.py \
--repo ${{ github.repository }} \
--exporter "$exporter" \
--version "$version" \
--files $rpm_files \
--output "$build_dir/release_urls.json"
echo "::endgroup::"
- name: 📅 Create Build Info
run: |
exporter="${{ matrix.exporter }}"
build_dir="build/$exporter-${{ matrix.arch }}-${{ matrix.dist }}"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
cat > "$build_dir/build-info.json" <<EOF
{
"exporter": "$exporter",
"version": "$version",
"arch": "${{ matrix.arch }}",
"dist": "${{ matrix.dist }}",
"build_date": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"artifact_type": "rpm"
}
EOF
- name: 📝 Generate Artifact Metadata
run: |
exporter="${{ matrix.exporter }}"
arch="${{ matrix.arch }}"
dist="${{ matrix.dist }}"
build_dir="build/$exporter-$arch-$dist"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
echo "::group::📝 Generating V3 catalog metadata"
# Find RPM file
rpm_file=$(find "$build_dir/rpms" -name "*.rpm" | head -1)
if [ -z "$rpm_file" ] || [ ! -f "$rpm_file" ]; then
echo "⚠️ No RPM file found in $build_dir/rpms, skipping metadata"
exit 0
fi
FILENAME=$(basename "$rpm_file")
SHA256=$(sha256sum "$rpm_file" | awk '{print $1}')
SIZE=$(stat -c%s "$rpm_file")
echo " File: $FILENAME"
echo " SHA256: $SHA256"
echo " Size: $SIZE bytes"
# Generate V3 catalog metadata
python3 core/scripts/generate_artifact_metadata.py \
--type rpm \
--exporter "$exporter" \
--version "$version" \
--arch "$arch" \
--dist "$dist" \
--filename "$FILENAME" \
--sha256 "$SHA256" \
--size "$SIZE" \
--status "success" \
--output "$build_dir/rpm_${arch}_${dist}.json"
echo "✓ Metadata generated: $build_dir/rpm_${arch}_${dist}.json"
echo "::endgroup::"
- name: Upload Artifacts
uses: actions/upload-artifact@v6
with:
name: rpm-${{ matrix.exporter }}-${{ matrix.arch }}-${{ matrix.dist }}
path: |
build/**/release_urls.json
build/**/build-info.json
build/**/rpm_*.json
if-no-files-found: ignore
retention-days: 7
# Build DEB packages (parallel per exporter, arch, dist)
build-deb:
name: DEB - ${{ matrix.exporter }} (${{ matrix.dist }}/${{ matrix.arch }})
needs: discover
if: needs.discover.outputs.build_needed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.discover.outputs.deb_matrix) }}
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Set up QEMU
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@v3
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: 📦 Build DEB
env:
PYTHONPATH: ${{ github.workspace }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
exporter="${{ matrix.exporter }}"
arch="${{ matrix.arch }}"
dist="${{ matrix.dist }}"
# Map distribution name to Docker image
case $dist in
debian-12) image="debian:12" ;;
debian-13) image="debian:trixie" ;;
*) echo "Error: Unknown distribution: $dist"; exit 1 ;;
esac
echo "::group::🔧 Generating build files"
build_dir="build/$exporter-$arch-$dist"
python3 -m core.engine.builder \
--manifest "exporters/$exporter/manifest.yaml" \
--output-dir "$build_dir" \
--arch "$arch"
echo "::endgroup::"
if [ -d "$build_dir/debian" ]; then
echo "::group::🐳 Building DEB package ($image)"
chmod +x core/scripts/build_deb.sh
./core/scripts/build_deb.sh "$build_dir" "$build_dir/debs" "$arch" "$image"
echo "::endgroup::"
fi
- name: 🔐 Sign DEB
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
run: |
exporter="${{ matrix.exporter }}"
dist="${{ matrix.dist }}"
build_dir="build/$exporter-${{ matrix.arch }}-$dist"
deb_file=$(find "$build_dir/debs" -name "*.deb" | head -1)
if [ -z "$deb_file" ]; then
echo "⚠️ No DEB file found, skipping signing"
exit 0
fi
echo "::group::🔐 Signing DEB"
chmod +x core/scripts/sign_deb_container.sh
./core/scripts/sign_deb_container.sh "$deb_file" "$GPG_PRIVATE_KEY" "$GPG_PASSPHRASE" "$GPG_KEY_ID" "$dist"
echo "✓ DEB signed successfully"
echo "::endgroup::"
- name: ⬆️ Upload to GitHub Releases
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
exporter="${{ matrix.exporter }}"
build_dir="build/$exporter-${{ matrix.arch }}-${{ matrix.dist }}"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
deb_files=$(find "$build_dir/debs" -name "*.deb")
if [ -z "$deb_files" ]; then
echo "⚠️ No DEB files to upload"
exit 0
fi
echo "::group::⬆️ Uploading to GitHub Releases"
python3 core/scripts/upload_to_release.py \
--repo ${{ github.repository }} \
--exporter "$exporter" \
--version "$version" \
--files $deb_files \
--output "$build_dir/release_urls.json"
echo "::endgroup::"
- name: 📅 Create Build Info
run: |
exporter="${{ matrix.exporter }}"
build_dir="build/$exporter-${{ matrix.arch }}-${{ matrix.dist }}"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
cat > "$build_dir/build-info.json" <<EOF
{
"exporter": "$exporter",
"version": "$version",
"arch": "${{ matrix.arch }}",
"dist": "${{ matrix.dist }}",
"build_date": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"artifact_type": "deb"
}
EOF
- name: 📝 Generate Artifact Metadata
run: |
exporter="${{ matrix.exporter }}"
arch="${{ matrix.arch }}"
dist="${{ matrix.dist }}"
build_dir="build/$exporter-$arch-$dist"
version=$(python3 -c "import yaml; m=yaml.safe_load(open('exporters/$exporter/manifest.yaml')); print(m['version'].lstrip('v'))")
echo "::group::📝 Generating V3 catalog metadata"
# Find DEB file
deb_file=$(find "$build_dir/debs" -name "*.deb" | head -1)
if [ -z "$deb_file" ] || [ ! -f "$deb_file" ]; then
echo "⚠️ No DEB file found in $build_dir/debs, skipping metadata"
exit 0
fi
FILENAME=$(basename "$deb_file")
SHA256=$(sha256sum "$deb_file" | awk '{print $1}')
SIZE=$(stat -c%s "$deb_file")
echo " File: $FILENAME"
echo " SHA256: $SHA256"
echo " Size: $SIZE bytes"
# Generate V3 catalog metadata
python3 core/scripts/generate_artifact_metadata.py \
--type deb \
--exporter "$exporter" \
--version "$version" \
--arch "$arch" \
--dist "$dist" \
--filename "$FILENAME" \
--sha256 "$SHA256" \
--size "$SIZE" \
--status "success" \
--output "$build_dir/deb_${arch}_${dist}.json"
echo "✓ Metadata generated: $build_dir/deb_${arch}_${dist}.json"
echo "::endgroup::"
- name: Upload Artifacts
uses: actions/upload-artifact@v6
with:
name: deb-${{ matrix.exporter }}-${{ matrix.arch }}-${{ matrix.dist }}
path: |
build/**/release_urls.json
build/**/build-info.json
build/**/deb_*.json
if-no-files-found: ignore
retention-days: 7
# Aggregate security scan results
aggregate-security:
name: 📊 Aggregate Security Stats
needs: [build-docker, build-rpm, build-deb]
if: always() && !cancelled() && needs.discover.outputs.build_needed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: Download Trivy Results
uses: actions/download-artifact@v7
with:
pattern: 'trivy-*'
path: trivy-results
continue-on-error: true
- name: 📊 Aggregate Security Statistics
run: |
if [ -d "trivy-results" ] && [ "$(ls -A trivy-results 2>/dev/null)" ]; then
python3 core/scripts/aggregate_security_stats.py \
--sarif-dir trivy-results \
--output security-stats.json
else
echo "No Trivy results found, creating empty stats"
echo '{"total_vulnerabilities": 0, "by_severity": {"CRITICAL": 0, "HIGH": 0, "MEDIUM": 0, "LOW": 0}, "top_exporters": [], "scan_date": null, "total_exporters_scanned": 0}' > security-stats.json
fi
- name: Upload Security Stats
uses: actions/upload-artifact@v6
with:
name: security-stats
path: security-stats.json
retention-days: 7
# Single publish job - collect all artifacts and update gh-pages once
publish-metadata:
name: 📤 Publish Metadata & Portal
needs: [build-docker, build-rpm, build-deb, aggregate-security]
if: always() && !cancelled() && needs.discover.outputs.build_needed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Download All Artifacts
uses: actions/download-artifact@v7
with:
path: artifacts
continue-on-error: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: 📊 Update Portal and Metadata
env:
PYTHONPATH: ${{ github.workspace }}
run: |
echo "::group::📥 Preparing artifacts"
# Organize artifacts (preserve directory structure to avoid overwrites)
mkdir -p release-urls build-info catalog
if [ -d "artifacts" ]; then
# Copy with unique names to avoid overwrites
find artifacts -name "release_urls.json" | while read file; do
# Extract parent directory name for unique filename
dir=$(basename $(dirname "$file"))
cp "$file" "release-urls/${dir}_release_urls.json"
done
find artifacts -name "build-info.json" | while read file; do
dir=$(basename $(dirname "$file"))
cp "$file" "build-info/${dir}_build-info.json"
done
# Organize V3 catalog metadata JSON files
# Expected structure: catalog/<exporter>/rpm_*.json, deb_*.json, docker.json
echo "Organizing V3 catalog metadata..."
# Find all metadata JSON files and organize them
find artifacts -type f \( -name "rpm_*.json" -o -name "deb_*.json" -o -name "docker.json" \) | while read file; do
# Extract exporter name from artifact directory name
# Artifact names: rpm-<exporter>-<arch>-<dist>, deb-<exporter>-<arch>-<dist>, docker-<exporter>
# Note: artifacts have nested structure (artifacts/artifact-name/build-subdir/file.json)
artifact_dir=$(basename $(dirname $(dirname "$file")))
# Extract exporter name (remove prefix and suffix patterns)
if [[ "$artifact_dir" == docker-* ]]; then
exporter="${artifact_dir#docker-}"
elif [[ "$artifact_dir" == rpm-* ]]; then
# rpm-node_exporter-amd64-el9 -> node_exporter
exporter=$(echo "$artifact_dir" | sed 's/^rpm-//' | sed 's/-[^-]*-[^-]*$//')
elif [[ "$artifact_dir" == deb-* ]]; then
# deb-node_exporter-amd64-debian-12 -> node_exporter
# Remove: deb- prefix, then -<arch>-<dist>-<version> (3 components)
exporter=$(echo "$artifact_dir" | sed 's/^deb-//' | sed 's/-[^-]*-[^-]*-[^-]*$//')
fi
if [ -n "$exporter" ]; then
mkdir -p "catalog/$exporter"
filename=$(basename "$file")
cp "$file" "catalog/$exporter/$filename"
echo " ✓ catalog/$exporter/$filename"
fi
done
# Copy security stats if available
if [ -f "artifacts/security-stats/security-stats.json" ]; then
cp artifacts/security-stats/security-stats.json .
fi
fi
# Debug: Show what we collected
echo "Release URLs collected:"
ls -la release-urls/ || echo " (none)"
echo "Build info collected:"
ls -la build-info/ || echo " (none)"
echo "Catalog structure:"
find catalog -type f 2>/dev/null || echo " (none)"
echo "::endgroup::"
echo "::group::🌐 Generating portal"
python3 -m core.engine.site_generator_v2 \
--output index.html \
--repo-dir . \
--catalog-dir catalog
echo "::endgroup::"
echo "::group::📤 Publishing to gh-pages"
git fetch origin gh-pages
git worktree add -B gh-pages gh-pages-dist origin/gh-pages
# Copy generated files
cp index.html gh-pages-dist/
cp -r catalog gh-pages-dist/ 2>/dev/null || true
# Copy security stats if exists
if [ -f "security-stats.json" ]; then
cp security-stats.json gh-pages-dist/
fi
cd gh-pages-dist
git config user.name "Monitoring Hub Bot"
git config user.email "bot@monitoring-hub.local"
git add index.html catalog/ security-stats.json 2>/dev/null || git add index.html catalog/
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: update portal and metadata [skip ci]"
git pull --rebase origin gh-pages
git push origin gh-pages
echo "✓ Published to gh-pages"
fi
echo "::endgroup::"
- name: 📊 Generate Final Summary
run: |
echo "## ✅ Full Build Completed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Portal:** https://sckyzo.github.io/monitoring-hub/" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f "catalog/index.json" ]; then
count=$(jq '.exporters | length' catalog/index.json)
echo "**Total exporters:** $count" >> $GITHUB_STEP_SUMMARY
fi