forked from AlmaLinux/cloud-images
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Include SBOM generation into GCP images build pipeline #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
javihernandez
wants to merge
9
commits into
gcp-images-almalinux-8
Choose a base branch
from
javi-gcp-images-sbom
base: gcp-images-almalinux-8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
78d912e
Add GCP images for AlmaLinux 8, 9, and 10
jonathanspw 61846ce
Add initial sbom generation support
javihernandez 0156113
Merge branch 'sbom' into javi-gcp-images-sbom
javihernandez d528449
Add sbom generation from collected data and upload artifact
javihernandez 466f2c6
Update gcp 8 and 9 packer definitions
javihernandez 85e48ab
Update paths around SBOM generation
javihernandez a8c4bf8
Run sbom_generator as sudo
javihernandez e3a92b2
Restored commented actions
javihernandez cc249ac
Pull cloud-images-sbom-tools from AlmaLinux organization
javihernandez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,11 @@ inputs: | |
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - uses: runs-on/action@v2 | ||
| # only when in runs-on environment | ||
| if: env.RUNS_ON_VERSION != '' | ||
| with: | ||
| metrics: cpu,network,memory,disk,io | ||
|
|
||
| - name: Runner OS, install extra packages | ||
| shell: bash | ||
|
|
@@ -73,14 +78,15 @@ runs: | |
| echo "version_major=${version_major}" >> $GITHUB_ENV | ||
| echo "alma_arch=${alma_arch}" >> $GITHUB_ENV | ||
|
|
||
| - name: Prepare staff | ||
| - name: Prepare stuff | ||
| shell: bash | ||
| run: | | ||
| # Prepare staff | ||
| # Prepare stuff | ||
| packer_opts= | ||
| case ${{ env.runner_os }} in | ||
| ubuntu) | ||
| # Packer options | ||
| packer_opts="-var ovmf_code=/usr/share/OVMF/OVMF_CODE_4M.fd -var ovmf_vars=/usr/share/OVMF/OVMF_VARS_4M.fd" | ||
| 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" | ||
| ;; | ||
| rhel) | ||
| # Packer options | ||
|
|
@@ -114,6 +120,10 @@ runs: | |
| # AWS S3 path to store images | ||
| aws_s3_path=images/${{ env.version_major }}/${release}/${{ inputs.type }}/${{ env.TIME_STAMP }} | ||
|
|
||
| # tell packer we can use more cpu/ram if we're using runs-on | ||
| # which means we're using runs-on with metal instances | ||
| [[ ${{ env.RUNS_ON_VERSION }} != '' ]] && packer_opts="${packer_opts} -var cpus=$(($(nproc)-4)) -var memory_${{ env.alma_arch }}=32768" | ||
|
|
||
| # Overriding packer source, image mask and S3 path where necessary | ||
| case "${{ inputs.type }}${{ env.version_major }}" in | ||
| azure8|azure9) | ||
|
|
@@ -228,6 +238,17 @@ runs: | |
| output_mask=output-${packer_source}/AlmaLinux-*.${{ env.alma_arch }}*.qcow2 | ||
| packer_source=qemu.${packer_source} | ||
| ;; | ||
| gcp8|gcp9) | ||
| output_mask=output-${packer_source}/AlmaLinux-*${version_major}*.${{ env.alma_arch }}.tar.gz | ||
| packer_source=qemu.${packer_source} | ||
| ;; | ||
| gcp10) | ||
| packer_source=almalinux_${{ env.version_major }}_${{ inputs.type }}_${{ env.alma_arch }} | ||
| [[ ${{ env.version_major }} == *"v2"* ]] && packer_source="${packer_source}_v2" | ||
| [[ ${{ inputs.variant }} == *"64k"* ]] && packer_source="almalinux_${{ env.version_major }}_${{ inputs.type }}_64k_${{ env.alma_arch }}" | ||
| output_mask=output-${packer_source}/AlmaLinux-*${version_major}*.${{ env.alma_arch }}.tar.gz | ||
| packer_source=qemu.${packer_source} | ||
| ;; | ||
| *) | ||
| output_mask=output-${output_mask} | ||
| packer_source=qemu.${packer_source} | ||
|
|
@@ -260,8 +281,24 @@ runs: | |
| ;; | ||
| esac | ||
|
|
||
| - name: Remove KVM | ||
| if: inputs.type == 'vagrant_virtualbox' || inputs.type == 'vagrant_vmware' | ||
| shell: bash | ||
| run: | | ||
| # Remove KVM | ||
| case ${{ env.runner_os }} in | ||
| ubuntu) | ||
| sudo apt-get -y remove qemu-kvm | ||
| ;; | ||
| rhel) | ||
| sudo dnf -y -q remove qemu-kvm | ||
| ;; | ||
| esac | ||
| sudo rmmod kvm_amd || sudo rmmod kvm_intel || true | ||
| sudo rmmod kvm || true | ||
|
|
||
| - name: Check nested virtualization support | ||
| if: inputs.arch == 'x86_64' && inputs.type != 'vagrant_virtualbox' && inputs.type != 'vagrant_vmware' && inputs.runner != 'aws-ec2' | ||
| if: inputs.arch == 'x86_64' && env.RUNS_ON_VERSION == '' && inputs.type != 'vagrant_virtualbox' && inputs.type != 'vagrant_vmware' | ||
| shell: bash | ||
| run: | | ||
| # Check nested virtualization support | ||
|
|
@@ -356,6 +393,26 @@ runs: | |
| # Install ansible | ||
| sudo ${{ env.runner_os == 'ubuntu' && 'apt-get' || 'dnf -q' }} -y install ansible | ||
|
|
||
| - name: Clone SBOM tools | ||
| shell: bash | ||
| run: | | ||
| rm -rf sbom-tools | ||
| git clone --depth=1 https://github.com/javihernandez/cloud-images-sbom-tools.git sbom-tools | ||
|
|
||
| - name: Set up Python and install generator deps | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
| cache: 'pip' | ||
| cache-dependency-path: sbom-tools/requirements.txt | ||
|
|
||
| - name: Create venv and install | ||
| shell: bash | ||
| run: | | ||
| python -m venv .venv-sbom | ||
| . .venv-sbom/bin/activate | ||
| pip install -r sbom-tools/requirements.txt | ||
javihernandez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Initialize packer | ||
| shell: bash | ||
| run: sudo /usr/bin/packer init -upgrade . | ||
|
|
@@ -365,12 +422,13 @@ runs: | |
| run: | | ||
| # Build ${{ inputs.type }} image | ||
| # PACKER_LOG=1 | ||
| sudo systemctl start libvirtd | ||
| sudo sh -c "/usr/bin/packer build ${{ env.PACKER_OPTS }} -only=${{ env.packer_source }} ." | ||
|
|
||
| - name: Locate image file, generate checksum | ||
| shell: bash | ||
| run: | | ||
| # Locate image file, generate checksum | ||
| # Locate image file, generate checksum, rename repo metadata file | ||
| ls -la $(dirname '${{ env.output_mask }}') | ||
| image_file=$(ls -1 ${{ env.output_mask }} | head -n 1) | ||
| [ "x${image_file}" = "x" ] && false | ||
|
|
@@ -380,8 +438,85 @@ runs: | |
| echo "IMAGE_FILE=${image_file}" >> $GITHUB_ENV | ||
| echo "IMAGE_NAME=$(basename ${image_file})" >> $GITHUB_ENV | ||
|
|
||
| # - name: Setup tmate session | ||
| # uses: mxschmitt/action-tmate@v3 | ||
| # don't fail if this doesn't exist, we may not always generate it | ||
| sudo mv sbom-data-*.json $(basename ${image_file}).sbom-data.json || true | ||
|
|
||
| - id: 'google-auth-dev-images' | ||
| if: env.IMAGE_TYPE == 'gcp' | ||
| uses: 'google-github-actions/auth@v2' | ||
| with: | ||
| workload_identity_provider: 'projects/443728870479/locations/global/workloadIdentityPools/github-actions/providers/github' | ||
| service_account: 'github-actions-cloud-images@almalinux-dev-images-469421.iam.gserviceaccount.com' | ||
|
|
||
| - name: 'Set up Google Cloud SDK' | ||
| if: env.IMAGE_TYPE == 'gcp' | ||
| uses: 'google-github-actions/[email protected]' | ||
|
|
||
| - name: 'Upload output to GCP storage bucket' | ||
| if: env.IMAGE_TYPE == 'gcp' | ||
| shell: bash | ||
| 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 | ||
|
|
||
| - name: Clone gce_image_publish repo | ||
| if: env.IMAGE_TYPE == 'gcp' | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| path: compute-image-tools | ||
| repository: GoogleCloudPlatform/compute-image-tools | ||
| ref: "20250916.00" | ||
|
|
||
| - name: Build gce_image_publish tool | ||
| if: env.IMAGE_TYPE == 'gcp' | ||
| shell: bash | ||
| run: | | ||
| # we need golang | ||
| case ${{ env.runner_os }} in | ||
| ubuntu) | ||
| sudo apt update | ||
| sudo apt-get -y install golang-go | ||
| ;; | ||
| rhel) | ||
| sudo dnf -y -q install golang | ||
| ;; | ||
| esac | ||
| # print golang version for reference | ||
| go version | ||
| # Build gce_image_publish tool | ||
| cd compute-image-tools/cli_tools/gce_image_publish | ||
| go mod tidy | ||
| go install | ||
|
|
||
| - name: Create test image on GCP | ||
| if: env.IMAGE_TYPE == 'gcp' | ||
| shell: bash | ||
| run: | | ||
| /home/$USER/go/bin/gce_image_publish \ | ||
| -var:environment=test \ | ||
| -skip_confirmation \ | ||
| -rollout_rate=0 \ | ||
| -publish_project="almalinux-dev-images-469421" \ | ||
| -work_project="almalinux-dev-images-469421" \ | ||
| -replace \ | ||
| -source_gcs_path="gs://almalinux-images-dev/" \ | ||
| vm-scripts/gcp/almalinux_${version_major}${{ inputs.arch == 'aarch64' && '_arm64' || '' }}.publish.json | ||
|
|
||
| # - name: 'Run Google cloud-image-testing tests (basic suite)' | ||
| # if: env.IMAGE_TYPE == 'gcp' && inputs.run_test == 'true' | ||
| # shell: bash | ||
| # run: | | ||
| # cd cloud-image-tests | ||
| # ./bin/manager \ | ||
| # -local_path bin \ | ||
| # -project almalinux-image-testing-469421 \ | ||
| # -filter '^(cvm|livemigrate|suspendresume|loadbalancer|guestagent|hostnamevalidation|imageboot|licensevalidation|network|security|hotattach|lssd|disk|packagevalidation|ssh|metadata|vmspec)$' \ | ||
| # -images 'projects/almalinux-dev-images-469421/global/images/family/almalinux-${{ env.version_major }}${{ inputs.arch == 'aarch64' && '-arm64' || '' }}' \ | ||
| # -parallel_stagger 10s -parallel_count 20 | ||
|
|
||
| - name: Generate SBOM | ||
| shell: bash | ||
| run: | | ||
| echo "Generating SBOM document of ${{ env.IMAGE_FILE }}" | ||
| 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" | ||
|
|
||
| - name: Test ${{ inputs.type }} ${{ inputs.variant }} image | ||
| # Skip testing for vagrant_virtualbox on GH runner because 'vugrant up' fails to connect to the newly created VM via ssh: | ||
|
|
@@ -474,6 +609,24 @@ runs: | |
| name: ${{ env.IMAGE_NAME }} | ||
| path: ${{ env.IMAGE_FILE }} | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| name: Store collected sbom data as artifact | ||
| id: sbom-data-artifact | ||
| if: inputs.store_as_artifact == 'true' | ||
| with: | ||
| compression-level: 9 | ||
| name: ${{ env.IMAGE_NAME }}.sbom-data.json | ||
| path: ${{ env.IMAGE_FILE }}.sbom-data.json | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| name: Store SBOM as artifact | ||
| id: sbom-artifact | ||
| if: inputs.store_as_artifact == 'true' | ||
| with: | ||
| compression-level: 9 | ||
| name: ${{ env.IMAGE_NAME }}.sbom.spdx.json | ||
| path: ${{ env.IMAGE_FILE }}.sbom.spdx.json | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| name: Store checksum as artifact | ||
| id: checksum-artifact | ||
|
|
@@ -488,7 +641,7 @@ runs: | |
| id: pkglist-artifact | ||
| if: inputs.store_as_artifact == 'true' && env.got_pkgs_list == 'true' | ||
| with: | ||
| compression-level: 1 | ||
| compression-level: 9 | ||
| name: ${{ env.IMAGE_NAME }}.txt | ||
| path: ${{ env.IMAGE_FILE }}.txt | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.