Skip to content

image-based

image-based #87

Workflow file for this run

name: Build and Deploy k4all
on:
pull_request:
branches:
- image-based
paths-ignore:
- "**/*.md"
- "**/*.txt"
push:
branches:
- image-based
paths-ignore:
- "**/*.md"
- "**/*.txt"
workflow_dispatch:
inputs:
changelog:
description: 'Brief description of changes in this build'
required: false
env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_NAME: k4all-image
K4ALL_VERSION: testing
ARCH: x86_64
VARIANT: CoreOS
ISO_NAME: k4all-${{ github.ref_name }}-testing.iso
RAW_NAME: k4all-${{ github.ref_name }}-testing.raw
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name || github.run_id }}
cancel-in-progress: true
jobs:
# build-and-push-image:
# name: Build and Push Fedora CoreOS Image
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# id-token: write
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4
# - name: Set Up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Set Up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Log in to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Build and Push Image
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ./Containerfile
# platforms: linux/amd64
# push: true
# tags: |
# ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
# ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
build-iso:
name: Build Bootable ISO
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Create Output Directory
run: mkdir -p output
- name: Install required packages
run: |
sudo apt-get update
sudo apt-get install -y podman xorriso genisoimage fdisk kpartx
- name: Build Raw Image
run: |
sudo podman pull ghcr.io/gpillon/k4all-image
sudo podman run \
--rm \
--privileged \
--pull=newer \
--security-opt label=type:unconfined_t \
-v ./output:/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
quay.io/centos-bootc/bootc-image-builder:latest \
--type raw \
--rootfs xfs \
--local ghcr.io/gpillon/k4all-image
- name: Configure Loop Devices
run: |
sudo tree output/
sudo mv output/image/disk.raw output/${{ env.RAW_NAME }}
sudo chown 1000:1000 output/${{ env.RAW_NAME }}
- name: Convert Raw to ISO
run: |
# Set up loop device and get device name
LOOP_DEV=$(sudo losetup --show -f output/${{ env.RAW_NAME }})
echo "Using loop device: $LOOP_DEV"
# Set up partition mapping
sudo kpartx -av $LOOP_DEV
# Create temporary mount points
sudo mkdir -p /mnt/raw /mnt/boot /mnt/efi
# Find the root and boot partitions
ROOT_PART=$(echo $LOOP_DEV | sed 's/\/dev\//\/dev\/mapper\//')
ROOT_PART="${ROOT_PART}p4" # root is partition 4
BOOT_PART="${ROOT_PART%p4}p3" # boot is partition 3
# Mount partitions
sudo mount $ROOT_PART /mnt/raw
sudo mount $BOOT_PART /mnt/boot
# Debug: List contents of important directories
echo "Boot/ostree contents:"
sudo ls -la /mnt/boot/ostree
# Create ISO directory structure
mkdir -p isofs/{isolinux,EFI/BOOT}
# Find and copy the most recent kernel and initramfs
BOOT_DIR=$(sudo find /mnt/boot/ostree -name "*.0" -type d | head -n 1)
echo "Using boot directory: $BOOT_DIR"
# Copy boot files from OSTree directory
sudo cp $BOOT_DIR/vmlinuz isofs/isolinux/vmlinuz
sudo cp $BOOT_DIR/initramfs isofs/isolinux/initrd
# Install and copy required isolinux files
sudo apt-get install -y syslinux syslinux-common
sudo cp /usr/lib/ISOLINUX/isolinux.bin isofs/isolinux/
sudo cp /usr/lib/syslinux/modules/bios/*.c32 isofs/isolinux/
# Create isolinux configuration
cat > isofs/isolinux/isolinux.cfg << EOF
DEFAULT linux
TIMEOUT 20
PROMPT 0
LABEL linux
KERNEL vmlinuz
APPEND initrd=initrd root=live:CDLABEL=BOOTC-ISO rd.live.image quiet console=tty0 console=ttyS0,115200n8
EOF
# Create ISO
sudo xorriso -as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "BOOTC-ISO" \
-eltorito-boot isolinux/isolinux.bin \
-eltorito-catalog isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-output output/${{ env.ISO_NAME }} \
isofs
# Cleanup
sudo umount /mnt/boot
sudo umount /mnt/raw
sudo kpartx -d $LOOP_DEV
sudo losetup -d $LOOP_DEV
sudo rm -rf isofs /mnt/{raw,boot,efi}
- name: Upload ISO to Job Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.IMAGE_NAME }}-${{ github.ref_name }}
path: output/${{ env.ISO_NAME }}
if-no-files-found: error
retention-days: 7
overwrite: true
generate-release:
name: Generate Release
needs: build-iso
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Branch Name
id: get-branch
run: |
BRANCH_NAME=${GITHUB_REF##*/}
echo "branch=${BRANCH_NAME}" >> $GITHUB_OUTPUT
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}-${{ steps.get-branch.outputs.branch }}
path: ./artifacts
- name: Generate Changelog
id: generate-changelog
run: |
echo "This release was generated for branch ${{ steps.get-branch.outputs.branch }}" > changelog.md
- name: Create or Update Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ steps.get-branch.outputs.branch }}
tag_name: ${{ steps.get-branch.outputs.branch }}
body_path: ./changelog.md
make_latest: ${{ steps.get-branch.outputs.branch == 'main' }}
prerelease: ${{ steps.get-branch.outputs.branch != 'main' }}
- name: Upload ISO to Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./artifacts/${{ env.ISO_NAME }}
asset_name: ${{ env.ISO_NAME }}
content_type: application/octet-stream