Skip to content

feat: adds github workflow to create an ironic esp image #178

feat: adds github workflow to create an ironic esp image

feat: adds github workflow to create an ironic esp image #178

---
name: build-ironic-images
on:
workflow_dispatch:
pull_request:
paths:
- 'ironic-images/**'
push:
branches:
- main
paths:
- 'ironic-images/**'
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
discover:
runs-on: ubuntu-latest
outputs:
yaml-files: ${{ steps.set-matrix.outputs.yaml-files }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Find YAML files
id: set-matrix
run: |
yaml_files="[$(find . -maxdepth 1 -type f \( -name '*.yaml' -o -name '*.yml' \) -printf '"%f", ' | sed 's/, $//')]"
echo "yaml-files=${yaml_files}" >> $GITHUB_OUTPUT
working-directory: ironic-images
build-esp-image:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ironic-images
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install Dependencies
run: sudo apt update && sudo apt install -y grub-efi-amd64-signed shim-signed mtools ipxe
- name: Create esp image
run: |
cp /usr/lib/shim/shimx64.efi.signed /tmp/bootx64.efi
cp /usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed /tmp/grubx64.efi
dd if=/dev/zero of=/tmp/esp.img bs=4096 count=1024
mkfs.msdos -F 12 -n ESP_IMAGE /tmp/esp.img
mmd -i /tmp/esp.img EFI EFI/BOOT
mcopy -i /tmp/esp.img -v /tmp/bootx64.efi ::EFI/BOOT/BOOTX64.efi
mcopy -i /tmp/esp.img -v /tmp/grubx64.efi ::EFI/BOOT/GRUBX64.efi
mdir -i /tmp/esp.img ::EFI/BOOT
mkdir artifacts
cp /tmp/esp.img artifacts
- name: Copy ipxe images
run: cp /usr/lib/ipxe/{undionly.kpxe,ipxe.efi,snponly.efi} artifacts
- name: Show artifacts
run: ls -la artifacts
- name: Save artifacts for next job
uses: actions/upload-artifact@v4
with:
name: image-artifacts
path: ironic-images/artifacts/
build-tenant-images:
runs-on: ubuntu-latest
needs: [discover, build-esp-image]
defaults:
run:
working-directory: ironic-images
strategy:
matrix:
yaml-file: ${{ fromJson(needs.discover.outputs.yaml-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up variables
run: |
echo "Processing YAML file: ${{ matrix.yaml-file }}"
imagename=$(grep -m 1 '^- imagename:' "${{ matrix.yaml-file }}" | awk '{print $3}')
echo "distro=${imagename%-*}" >> $GITHUB_ENV
echo "release=${imagename##*-}" >> $GITHUB_ENV
- name: Setup python environment
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
id: setup-python
with:
python-version: '3.11'
cache: 'pip'
- name: Install Dependencies
run: sudo apt update && sudo apt install -y debootstrap qemu-utils squashfs-tools kpartx
- name: Install python packages
run: pip install -r requirements.txt
- name: Build Images
run: |
diskimage-builder ${{ matrix.yaml-file }}
mkdir -p upload
find . -maxdepth 1 -type f \( -name '*.qcow2' -o -name '*.kernel' -o -name '*.initramfs' \) -exec cp {} upload/ \;
env:
DIB_RELEASE: ${{ env.release }}
ELEMENTS_PATH: "${{ env.distro == 'ipa-debian' && format('{0}/share/ironic-python-agent-builder/dib:{1}/ironic-images/custom_elements', env.pythonLocation, github.workspace) || ''}}"
- name: Set timestamp environment variable
run: echo "TIMESTAMP=$(git show --no-patch --no-notes --pretty='%cd' --date=format:'%Y%m%d%H%M%S' ${{ github.sha }})" >> $GITHUB_ENV
- name: Download artifacts from previous job
uses: actions/download-artifact@v4
with:
name: image-artifacts
path: ironic-images/artifacts
- name: Copy image artifacts from previous job in to uploads directory
run: ls -la artifacts && cp -R artifacts/* upload/
- name: Publish Release
id: create_release
uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # v2
with:
name: understack-images
tag_name: understack-images-${{ env.TIMESTAMP }}
make_latest: true
fail_on_unmatched_files: true
files: ironic-images/upload/*
if: ${{ github.ref == 'refs/heads/main' }}
cleanup:
runs-on: ubuntu-latest
needs: build-tenant-images
steps:
- name: Clean up artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: image-artifacts