# Image Builder

Builds Fedora/RHEL/Centos images like Packer but for Red Hat.

<https://osbuild.org/docs/user-guide/blueprint-reference/>

Default credentials for included images is:

username: `ducoterra`

password: `osbuild`

## Warning

From the [Red Hat
Documentation](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html-single/composing_installing_and_managing_rhel_for_edge_images/index):

> You cannot build an operating system image that differs from the RHEL image
> builder host. For example, you cannot use a RHEL system to build Fedora or
> CentOS images.

## Installing

```bash
# Install the packages
dnf install -y osbuild-composer composer-cli

# Start/enable the service
systemctl enable --now osbuild-composer.socket

# Optional: add your user to the weldr group
sudo usermod -aG weldr $USER

# Optional: cockpit dependency
dnf install -y cockpit-composer

# Optional: allow security profiles
dnf install openscap-scanner scap-security-guide
```

## Building Images

1. Create a toml file describing your image

    See `fedora42-base.toml` for an example.

2. Push the toml to composer

    ```bash
    composer-cli blueprints push active/software_osbuild/fedora43-base.toml
    
    # List blueprints
    composer-cli blueprints list
    ```

3. Generate the image

    ```bash
    # List image types
    composer-cli compose types

    # Build the image
    composer-cli compose start fedora43-base qcow2

    # Check status
    watch composer-cli compose status

    # Download logs if error
    cd /tmp && composer-cli compose logs 52963ac9-b680-4def-baaf-252845f0e3fe

    # Delete failed images
    composer-cli compose list failed -j | jq '.[].body.failed.[]?.id' | xargs -I '%' composer-cli compose delete '%'

    # Delete successful images
    composer-cli compose list finished -j | jq '.[].body.finished.[]?.id' | xargs -I '%' composer-cli compose delete '%'
    ```

4. Run the image

    ```bash
    # List your images
    composer-cli compose list finished

    # Download the image
    composer-cli compose image --filename active/software_osbuild/secrets/fedora43-base.qcow2 1884d6a3-0b13-40e1-980d-1941f9a4c4f9

    # Test with qemu
    virt-install \
    --name "fedora43-base" \
    --boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
    --cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \
    --ram=8192 \
    --os-variant=fedora41 \
    --network bridge:virbr0 \
    --graphics none \
    --console pty,target.type=virtio \
    --import --disk "path=active/software_osbuild/secrets/fedora43base.qcow2,bus=virtio"
    ```

### Image Build and Watch One Liner

```bash
composer-cli blueprints push active/software_osbuild/fedora43-base.toml && \
composer-cli compose start fedora43-base qcow2 && \
watch composer-cli compose status
```