Skip to content

Commit

Permalink
feat: create ISO builder action (#1)
Browse files Browse the repository at this point in the history
* feat: create ISO builder action

* chore: update README and switch to kebab case

* Update action.yml

* Update action.yml

* fix: correctly set output directory
  • Loading branch information
p5 authored Dec 23, 2024
1 parent 793f713 commit 4b40b14
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# bootc-image-builder-action
# `@centos-workstation/bootc-image-builder-action`

Build bootc images into disk images or ISOs.

Currently only ISOs are supported, but contributions are welcome.

## Usage

### Inputs

```yaml
- uses: centos-workstation
with:
# Configuration file for the image builder.
# Required.
config-file:

# The expected artifact type
# Optional. Default is 'iso'
type:

# Image (registry with tag) used in the artifact.
# Required.
image:

# The upstream builder image.
# Optional. Default is 'quay.io/centos-bootc/bootc-image-builder:latest'
bootc-image-builder-image:
```
### Outputs
| Name | Description | Example |
| - | - | - |
| `output-directory` | Directory containing all output artifacts | `./outputs/buildiso` |
| `output-file` | Path to the build file | `./outputs/buildiso/install.iso` |
| `checksum-path` | Path to the checksum file | `./outputs/buildiso/CHECKSUM` |
| `checksum` | Checksum of the build file | `sha256:...` |
108 changes: 108 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Bootc Image Builder
description: Build bootc images into disk images or ISOs

inputs:
config-file:
description: 'Path to the config file'
required: true
type:
description: 'Type of image to build (e.g. iso)'
required: false
default: 'iso'
image:
description: 'Name of the image (e.g. ghcr.io/myorg/myimage:latest)'
required: true
bootc-image-builder-image:
description: 'Name of the bootc image builder image'
required: false
default: 'quay.io/centos-bootc/bootc-image-builder:latest'

outputs:
output-directory:
description: 'Directory containing the built image'
value: ${{ steps.set-outputs.outputs.output_directory }}
output-file:
description: 'Path to the built image'
value: ${{ steps.set-outputs.outputs.path }}
checksum-path:
description: 'Checksum of the built image'
value: ${{ steps.set-outputs.outputs.checksum_path }}
checksum:
description: 'Checksum of the built image'
value: ${{ steps.set-outputs.outputs.checksum }}

runs:
using: 'composite'
steps:
- name: Configure Podman
shell: bash
run: |
sudo mkdir -p /etc/containers
echo -e "[storage]\ndriver = \"overlay\"\nrunroot = \"/run/containers/storage\"\ngraphroot = \"/var/lib/containers/storage\"" \
| sudo tee /etc/containers/storage.conf
# workaround https://github.com/containers/podman/issues/21683
sudo apt install -y sqlite3
echo "update DBConfig set GraphDriver = 'overlay' where GraphDriver = '';" | sudo sh -c '(cd /var/lib/containers/storage && sqlite3 db.sql)'
- name: Pull Image
shell: bash
run:
sudo podman pull ${{ inputs.image }}

- name: Build ISO
if: ${{ inputs.type == 'iso' }}
id: build
shell: bash
env:
CONFIG_FILE: ${{ inputs.config-file }}
IMAGE: ${{ inputs.image }}
BOOTC_IMAGE_BUILDER_IMAGE: ${{ inputs.bootc-image-builder-image }}
run: |
DESIRED_UID=$(id -u)
DESIRED_GID=$(id -g)
CONFIG_FILE_EXTENSION="${CONFIG_FILE##*.}"
mkdir -p ./output
sudo podman run \
--rm \
--privileged \
--pull=newer \
--security-opt label=type:unconfined_t \
-v $CONFIG_FILE:/config.$CONFIG_FILE_EXTENSION:ro \
-v ./output:/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
$BOOTC_IMAGE_BUILDER_IMAGE \
--type iso \
--local \
--chown $DESIRED_UID:$DESIRED_GID \
$IMAGE
# Create a checksum of the output file, stored in the same directory
CHECKSUM=$(sha256sum ./output/bootiso/*.iso | awk '{print $1}')
echo $CHECKSUM > ./output/bootiso/CHECKSUM
ISO_PATH=$(ls $OUTPUT_DIRECTORY/bootiso/*.iso)
# Get the parent directory of the ISO
OUTPUT_DIRECTORY=$(dirname $ISO_PATH)
echo "OUTPUT_DIRECTORY=$OUTPUT_DIRECTORY" >> $GITHUB_OUTPUT
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_OUTPUT
echo "CHECKSUM_PATH=$OUTPUT_DIRECTORY/CHECKSUM" >> $GITHUB_OUTPUT
echo "ISO_PATH=$ISO_PATH" >> $GITHUB_OUTPUT
- name: Set Outputs
id: set-outputs
shell: bash
env:
OUTPUT_DIRECTORY: ${{ steps.build.outputs.OUTPUT_DIRECTORY }}
CHECKSUM: ${{ steps.build.outputs.CHECKSUM }}
CHECKSUM_PATH: ${{ steps.build.outputs.CHECKSUM_PATH }}
ISO_PATH: ${{ steps.build.outputs.ISO_PATH }}
run: |
echo "output_directory=$OUTPUT_DIRECTORY" >> $GITHUB_OUTPUT
echo "checksum=$CHECKSUM" >> $GITHUB_OUTPUT
echo "checksum_path=$CHECKSUM_PATH" >> $GITHUB_OUTPUT
echo "path=$ISO_PATH" >> $GITHUB_OUTPUT

0 comments on commit 4b40b14

Please sign in to comment.