Skip to content

Commit

Permalink
Cleanup and fixes for iso builds
Browse files Browse the repository at this point in the history
- pull in some cleanup from porting changes to achillobator
- use forked bootc-image-builder and cleanup iso build/run recipes
  • Loading branch information
detiber committed Dec 20, 2024
1 parent 960180c commit e23a4b1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 44 deletions.
93 changes: 51 additions & 42 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ export image_name := env("IMAGE_NAME", "main")
export centos_version := env("CENTOS_VERSION", "stream10")
export default_tag := env("DEFAULT_TAG", "latest")

# work around issue with upstream image builder,
# should converge back on upstream (quay.io/centos-bootc/bootc-image-builder:latest)
# asap

export bib_image := env("BIB_IMAGE", "ghcr.io/centos-workstation/bootc-image-builder:latest")

alias build-vm := build-qcow2
alias rebuild-vm := rebuild-qcow2
alias run-vm := run-vm-qcow2

[private]
default:
@just --list
Expand Down Expand Up @@ -123,7 +133,16 @@ _build-bib $target_image $tag $type $config: (_rootful_load_image target_image t
#!/usr/bin/env bash
set -euo pipefail
mkdir -p "output"

echo "Cleaning up previous build"

if [[ $type == iso ]]; then
sudo rm -rf "output/bootiso" || true
else
sudo rm -rf "output/${type}" || true
fi

sudo rm -rf "output/${type}" || true
sudo rm "output/manifest-${type}.json" || true

Expand All @@ -142,63 +161,44 @@ _build-bib $target_image $tag $type $config: (_rootful_load_image target_image t
-v $(pwd)/${config} \
-v $(pwd)/output:/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
quay.io/centos-bootc/bootc-image-builder:latest \
"${bib_image}" \
${args} \
"${target_image}"

sudo chown -R $USER:$USER output

if [[ $type == qcow2 ]]; then
echo "making the image biggerer"
sudo qemu-img resize "output/qcow2/disk.qcow2" 80G
fi
_rebuild-bib $target_image $tag $type $config: (build target_image tag) && (_build-bib target_image tag type config)

build-vm $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "qcow2" "image-builder.config.toml")
[group('Build Virtal Machine Image')]
build-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "qcow2" "image-builder.config.toml")

[group('Build Virtal Machine Image')]
build-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "raw" "image-builder.config.toml")

[group('Build Virtal Machine Image')]
build-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "iso" "image-builder-iso.config.toml")

run-vm $target_image=("localhost/" + image_name) $tag=default_tag:
#!/usr/bin/bash
set -eoux pipefail
[group('Build Virtal Machine Image')]
rebuild-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "qcow2" "image-builder.config.toml")

qcow2_file="output/qcow2/disk.qcow2"
[group('Build Virtal Machine Image')]
rebuild-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "raw" "image-builder.config.toml")

if [[ ! -f "${qcow2_file}" ]]; then
just build-vm "$target_image" "$tag"
fi
[group('Build Virtal Machine Image')]
rebuild-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "iso" "image-builder-iso.config.toml")

# Determine which port to use
port=8006;
while grep -q :${port} <<< $(ss -tunalp); do
port=$(( port + 1 ))
done
echo "Using Port: ${port}"
echo "Connect to http://localhost:${port}"
run_args=()
run_args+=(--rm --privileged)
run_args+=(--pull=newer)
run_args+=(--publish "127.0.0.1:${port}:8006")
run_args+=(--env "CPU_CORES=4")
run_args+=(--env "RAM_SIZE=8G")
run_args+=(--env "DISK_SIZE=64G")
# run_args+=(--env "BOOT_MODE=windows_secure")
run_args+=(--env "TPM=Y")
run_args+=(--env "GPU=Y")
run_args+=(--device=/dev/kvm)
run_args+=(--volume "${PWD}/${qcow2_file}":"/boot.qcow2")
run_args+=(docker.io/qemux/qemu-docker)
podman run "${run_args[@]}" &
xdg-open http://localhost:${port}
fg "%podman"

run-iso $target_image=("localhost/" + image_name) $tag=default_tag:
_run-vm $target_image $tag $type $config:
#!/usr/bin/bash
set -eoux pipefail

iso_file="output/iso/myiso.iso"
image_file="output/${type}/disk.${type}"

if [[ ! -f "${iso_file}" ]]; then
just build-iso "$target_image" "$tag"
if [[ $type == iso ]]; then
image_file="output/bootiso/install.iso"
fi

if [[ ! -f "${image_file}" ]]; then
just "build-${type}" "$target_image" "$tag"
fi

# Determine which port to use
Expand All @@ -219,8 +219,17 @@ run-iso $target_image=("localhost/" + image_name) $tag=default_tag:
run_args+=(--env "TPM=Y")
run_args+=(--env "GPU=Y")
run_args+=(--device=/dev/kvm)
run_args+=(--volume "${PWD}/${iso_file}":"/boot.iso")
run_args+=(--volume "${PWD}/${image_file}":"/boot.${type}")
run_args+=(docker.io/qemux/qemu-docker)
podman run "${run_args[@]}" &
xdg-open http://localhost:${port}
fg "%podman"

[group('Run Virtal Machine')]
run-vm-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "qcow2" "image-builder.config.toml")

[group('Run Virtal Machine')]
run-vm-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "raw" "image-builder.config.toml")

[group('Run Virtal Machine')]
run-vm-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "iso" "image-builder-iso.config.toml")
18 changes: 16 additions & 2 deletions image-builder-iso.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@ graphical --non-interactive
lang en_US.UTF-8
zerombr
clearpart --all --initlabel --disklabel=gpt
autopart --noswap --type btrfs
autopart --noswap --type xfs
network --bootproto=dhcp --device=link --activate --onboot=on
timezone --utc America/New_York
firstboot --enable
reboot
%post --nochroot
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install flathub com.github.tchx84.Flatseal -y
flatpak install flathub org.keepassxc.KeePassXC -y
%end
"""

[customizations.installer.modules]
enable = [
"org.fedoraproject.Anaconda.Modules.Localization",
"org.fedoraproject.Anaconda.Modules.Timezone"
"org.fedoraproject.Anaconda.Modules.Network",
"org.fedoraproject.Anaconda.Modules.Payloads",
"org.fedoraproject.Anaconda.Modules.Runtime",
"org.fedoraproject.Anaconda.Modules.Security",
"org.fedoraproject.Anaconda.Modules.Services",
"org.fedoraproject.Anaconda.Modules.Storage",
"org.fedoraproject.Anaconda.Modules.Subscription",
"org.fedoraproject.Anaconda.Modules.Timezone",
"org.fedoraproject.Anaconda.Modules.Users"
]

0 comments on commit e23a4b1

Please sign in to comment.