Skip to content

Commit 5cea787

Browse files
Merge pull request #266 from AlmaLinux/gcp-images-almalinux-8
Add GCP images for AlmaLinux 8, 9, and 10
2 parents 6a638aa + 266d353 commit 5cea787

28 files changed

+2378
-66
lines changed

.github/actions/shared-steps/action.yml

Lines changed: 146 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ inputs:
3333
runs:
3434
using: "composite"
3535
steps:
36+
- uses: runs-on/action@v2
37+
# only when in runs-on environment
38+
if: env.RUNS_ON_VERSION != ''
39+
with:
40+
metrics: cpu,network,memory,disk,io
3641

3742
- name: Runner OS, install extra packages
3843
shell: bash
@@ -65,14 +70,15 @@ runs:
6570
echo "version_major=${version_major}" >> $GITHUB_ENV
6671
echo "alma_arch=${alma_arch}" >> $GITHUB_ENV
6772
68-
- name: Prepare staff
73+
- name: Prepare stuff
6974
shell: bash
7075
run: |
71-
# Prepare staff
76+
# Prepare stuff
77+
packer_opts=
7278
case ${{ env.runner_os }} in
7379
ubuntu)
7480
# Packer options
75-
packer_opts="-var ovmf_code=/usr/share/OVMF/OVMF_CODE_4M.fd -var ovmf_vars=/usr/share/OVMF/OVMF_VARS_4M.fd"
81+
packer_opts="-var qemu_binary=/usr/bin/qemu-system-${{ inputs.arch }} -var ovmf_code=/usr/share/OVMF/OVMF_CODE_4M.fd -var ovmf_vars=/usr/share/OVMF/OVMF_VARS_4M.fd"
7682
;;
7783
rhel)
7884
# Packer options
@@ -104,6 +110,10 @@ runs:
104110
# AWS S3 path to store images
105111
aws_s3_path=images/${{ env.version_major }}/${release}/${{ inputs.type }}/${{ env.TIME_STAMP }}
106112
113+
# tell packer we can use more cpu/ram if we're using runs-on
114+
# which means we're using runs-on with metal instances
115+
[[ ${{ env.RUNS_ON_VERSION }} != '' ]] && packer_opts="${packer_opts} -var cpus=$(($(nproc)-4)) -var memory_${{ env.alma_arch }}=32768"
116+
107117
# Overriding packer source, image mask and S3 path where necessary
108118
case "${{ inputs.type }}${{ env.version_major }}" in
109119
azure8|azure9)
@@ -218,6 +228,17 @@ runs:
218228
output_mask=output-${packer_source}/AlmaLinux-*.${{ env.alma_arch }}*.qcow2
219229
packer_source=qemu.${packer_source}
220230
;;
231+
gcp8|gcp9)
232+
output_mask=output-${packer_source}/AlmaLinux-*${version_major}*.${{ env.alma_arch }}.tar.gz
233+
packer_source=qemu.${packer_source}
234+
;;
235+
gcp10)
236+
packer_source=almalinux_${{ env.version_major }}_${{ inputs.type }}_${{ env.alma_arch }}
237+
[[ ${{ env.version_major }} == *"v2"* ]] && packer_source="${packer_source}_v2"
238+
[[ ${{ inputs.variant }} == *"64k"* ]] && packer_source="almalinux_${{ env.version_major }}_${{ inputs.type }}_64k_${{ env.alma_arch }}"
239+
output_mask=output-${packer_source}/AlmaLinux-*${version_major}*.${{ env.alma_arch }}.tar.gz
240+
packer_source=qemu.${packer_source}
241+
;;
221242
*)
222243
output_mask=output-${output_mask}
223244
packer_source=qemu.${packer_source}
@@ -250,8 +271,24 @@ runs:
250271
;;
251272
esac
252273
274+
- name: Remove KVM
275+
if: inputs.type == 'vagrant_virtualbox' || inputs.type == 'vagrant_vmware'
276+
shell: bash
277+
run: |
278+
# Remove KVM
279+
case ${{ env.runner_os }} in
280+
ubuntu)
281+
sudo apt-get -y remove qemu-kvm
282+
;;
283+
rhel)
284+
sudo dnf -y -q remove qemu-kvm
285+
;;
286+
esac
287+
sudo rmmod kvm_amd || sudo rmmod kvm_intel || true
288+
sudo rmmod kvm || true
289+
253290
- name: Check nested virtualization support
254-
if: inputs.arch == 'x86_64' && inputs.type != 'vagrant_virtualbox' && inputs.type != 'vagrant_vmware' && inputs.runner != 'aws-ec2'
291+
if: inputs.arch == 'x86_64' && env.RUNS_ON_VERSION == '' && inputs.type != 'vagrant_virtualbox' && inputs.type != 'vagrant_vmware'
255292
shell: bash
256293
run: |
257294
# Check nested virtualization support
@@ -354,6 +391,25 @@ runs:
354391
# Install ansible
355392
sudo ${{ env.runner_os == 'ubuntu' && 'apt-get' || 'dnf -q' }} -y install ansible
356393
394+
- name: Clone SBOM tools
395+
shell: bash
396+
run: |
397+
rm -rf sbom-tools
398+
git clone --depth=1 https://github.com/AlmaLinux/cloud-images-sbom-tools.git sbom-tools
399+
400+
- name: Set up Python and install generator deps
401+
uses: actions/setup-python@v5
402+
with:
403+
python-version: '3.11'
404+
cache: 'pip'
405+
cache-dependency-path: sbom-tools/requirements.txt
406+
407+
- name: Create venv and install
408+
shell: bash
409+
run: |
410+
python -m venv .venv-sbom
411+
.venv-sbom/bin/pip install -r sbom-tools/requirements.txt
412+
357413
- name: Initialize packer
358414
shell: bash
359415
run: sudo /usr/bin/packer init -upgrade .
@@ -363,12 +419,14 @@ runs:
363419
run: |
364420
# Build ${{ inputs.type }} image
365421
# PACKER_LOG=1
422+
sudo systemctl start libvirtd
366423
sudo sh -c "/usr/bin/packer build ${{ env.PACKER_OPTS }} -only=${{ env.packer_source }} ."
367424
368425
- name: Locate image file, generate checksum
369426
shell: bash
370427
run: |
371-
# Locate image file, generate checksum
428+
# Locate image file, generate checksum, rename repo metadata file
429+
ls -la $(dirname '${{ env.output_mask }}')
372430
image_file=$(ls -1 ${{ env.output_mask }} | head -n 1)
373431
[ "x${image_file}" = "x" ] && false
374432
cd $(dirname ${image_file})
@@ -377,70 +435,81 @@ runs:
377435
echo "IMAGE_FILE=${image_file}" >> $GITHUB_ENV
378436
echo "IMAGE_NAME=$(basename ${image_file})" >> $GITHUB_ENV
379437
380-
# - name: Setup tmate session
381-
# uses: mxschmitt/action-tmate@v3
438+
# don't fail if this doesn't exist, we may not always generate it
439+
sudo mv sbom-data-*.json $(basename ${image_file}).sbom-data.json || true
382440
383-
- name: Test/check release and architecture, list installed packages in ${{ env.IMAGE_FILE }} cloud image
384-
if: ${{ ! contains(inputs.type, 'vagrant') }}
441+
- name: Generate SBOM
385442
shell: bash
386443
run: |
387-
# List installed packages in ${{ env.IMAGE_FILE }} image
388-
389-
# Partition number with root file-system
390-
case ${{ inputs.arch }} in
391-
x86_64*) partition=4 ;;
392-
aarch64*) partition=3 ;;
393-
*) false ;;
394-
esac
395-
396-
# Image file format: raw or qcow2
397-
case ${{ inputs.type }} in
398-
oci|gencloud|opennebula) format=qcow2 ;;
399-
azure) format=raw ;;
400-
*) false ;;
401-
esac
402-
rootfs_path=/mnt/rootfs
403-
sudo mkdir -p ${rootfs_path}
404-
405-
# Install qemu-utils
406-
sudo ${{ env.runner_os == 'ubuntu' && 'apt-get' || 'dnf -q' }} \
407-
-y install \
408-
${{ env.runner_os == 'ubuntu' && 'qemu-utils' || 'qemu-img' }}
409-
410-
# Load nbd kernel module
411-
sudo modprobe nbd max_part=8
412-
413-
# Make a copy of the image file
414-
sudo cp ${{ env.IMAGE_FILE }} $(dirname ${rootfs_path})
444+
echo "Generating SBOM document of ${{ env.IMAGE_FILE }}"
445+
sudo .venv-sbom/bin/python3 sbom-tools/sbom_generator.py "${{ env.IMAGE_NAME }}" "${{ env.IMAGE_FILE }}.sbom-data.json" "${{ env.IMAGE_FILE }}.sbom.spdx.json"
415446
416-
# Attach the image file to the nbd device
417-
sudo qemu-nbd \
418-
--read-only \
419-
--format=${format} \
420-
--connect=/dev/nbd0 \
421-
$(dirname ${rootfs_path})/$(basename ${{ env.IMAGE_FILE }}) \
422-
&& sleep 10 || false
447+
- id: 'google-auth-dev-images'
448+
if: env.IMAGE_TYPE == 'gcp'
449+
uses: 'google-github-actions/auth@v2'
450+
with:
451+
workload_identity_provider: 'projects/443728870479/locations/global/workloadIdentityPools/github-actions/providers/github'
452+
service_account: 'github-actions-cloud-images@almalinux-dev-images-469421.iam.gserviceaccount.com'
423453

424-
# Mount need partition
425-
sudo fdisk -l /dev/nbd0
426-
sudo mount /dev/nbd0p${partition} ${rootfs_path} \
427-
&& sleep 10 || false
454+
- name: 'Set up Google Cloud SDK'
455+
if: env.IMAGE_TYPE == 'gcp'
456+
uses: 'google-github-actions/setup-gcloud@v3.0.0'
428457

429-
echo "[Debug] AlmaLinux release:"
430-
grep '${{ env.RELEASE_STRING }}' ${rootfs_path}/etc/almalinux-release
458+
- name: Upload output to GCP storage bucket
459+
if: env.IMAGE_TYPE == 'gcp'
460+
shell: bash
461+
run: gcloud storage cp ${{ env.IMAGE_FILE }} gs://almalinux-images-dev/almalinux-${version_major}${{ inputs.arch == 'aarch64' && '-arm64' || '' }}-v$(date +'%Y%m%d')/root.tar.gz
431462

432-
echo "[Debug] System architecture:"
433-
rpm --dbpath=${rootfs_path}/var/lib/rpm -q --qf='%{ARCH}\n' ${{ env.RELEASE_PACKAGE }} | grep '${{ env.alma_arch }}'
463+
- name: Upload SBOM data to GCP storage bucket
464+
if: env.IMAGE_TYPE == 'gcp'
465+
shell: bash
466+
run: gcloud storage cp ${{ env.IMAGE_FILE }}.sbom.spdx.json gs://almalinux-images-dev-sbom/almalinux-${version_major}${{ inputs.arch == 'aarch64' && '-arm64' || '' }}-v$(date +'%Y%m%d').sbom.spdx.json
434467

435-
# Get installed packages list
436-
sudo sh -c "rpm --dbpath=${rootfs_path}/var/lib/rpm -qa --queryformat '%{NAME}\n' | sort > ${{ env.IMAGE_FILE }}.txt"
468+
- name: Clone gce_image_publish repo
469+
if: env.IMAGE_TYPE == 'gcp'
470+
uses: actions/checkout@v5
471+
with:
472+
path: compute-image-tools
473+
repository: GoogleCloudPlatform/compute-image-tools
474+
ref: "20250916.00"
437475

438-
[ -f ${{ env.IMAGE_FILE }}.txt ] \
439-
&& echo "got_pkgs_list=true" >> $GITHUB_ENV \
440-
|| echo "got_pkgs_list=false" >> $GITHUB_ENV
476+
- name: Build gce_image_publish tool
477+
if: env.IMAGE_TYPE == 'gcp'
478+
shell: bash
479+
run: |
480+
# we need golang
481+
case ${{ env.runner_os }} in
482+
ubuntu)
483+
sudo apt update
484+
sudo apt-get -y install golang-go
485+
;;
486+
rhel)
487+
sudo dnf -y -q install golang
488+
;;
489+
esac
490+
# print golang version for reference
491+
go version
492+
# Build gce_image_publish tool
493+
cd compute-image-tools/cli_tools/gce_image_publish
494+
go mod tidy
495+
go install
496+
497+
- name: Create test image on GCP
498+
if: env.IMAGE_TYPE == 'gcp'
499+
shell: bash
500+
run: |
501+
/home/$USER/go/bin/gce_image_publish \
502+
-var:environment=test \
503+
-skip_confirmation \
504+
-rollout_rate=0 \
505+
-publish_project="almalinux-dev-images-469421" \
506+
-work_project="almalinux-dev-images-469421" \
507+
-replace \
508+
-source_gcs_path="gs://almalinux-images-dev/" \
509+
vm-scripts/gcp/almalinux_${version_major}${{ inputs.arch == 'aarch64' && '_arm64' || '' }}.publish.json
441510
442511
- name: Test ${{ inputs.type }} ${{ inputs.variant }} image
443-
if: inputs.run_test == 'true'
512+
if: inputs.run_test == 'true' && contains(inputs.type, 'vagrant')
444513
shell: bash
445514
run: |
446515
# Test ${{ inputs.type }} ${{ inputs.variant }} image
@@ -538,6 +607,24 @@ runs:
538607
name: ${{ env.IMAGE_NAME }}
539608
path: ${{ env.IMAGE_FILE }}
540609

610+
- uses: actions/upload-artifact@v4
611+
name: Store collected sbom data as artifact
612+
id: sbom-data-artifact
613+
if: inputs.store_as_artifact == 'true'
614+
with:
615+
compression-level: 9
616+
name: ${{ env.IMAGE_NAME }}.sbom-data.json
617+
path: ${{ env.IMAGE_FILE }}.sbom-data.json
618+
619+
- uses: actions/upload-artifact@v4
620+
name: Store SBOM as artifact
621+
id: sbom-artifact
622+
if: inputs.store_as_artifact == 'true'
623+
with:
624+
compression-level: 9
625+
name: ${{ env.IMAGE_NAME }}.sbom.spdx.json
626+
path: ${{ env.IMAGE_FILE }}.sbom.spdx.json
627+
541628
- uses: actions/upload-artifact@v4
542629
name: Store checksum as artifact
543630
id: checksum-artifact
@@ -552,7 +639,7 @@ runs:
552639
id: pkglist-artifact
553640
if: inputs.store_as_artifact == 'true' && env.got_pkgs_list == 'true'
554641
with:
555-
compression-level: 1
642+
compression-level: 9
556643
name: ${{ env.IMAGE_NAME }}.txt
557644
path: ${{ env.IMAGE_FILE }}.txt
558645

0 commit comments

Comments
 (0)