diff --git a/bootc/scenario3a/custom.sh b/bootc/scenario3a/custom.sh deleted file mode 100755 index 8c2e73a..0000000 --- a/bootc/scenario3a/custom.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -Eeuo pipefail - -if [[ "$UID" -ne 0 ]]; then - echo "This command must be run as root!" - exit 1 -fi - -SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -PROJECT_DIR="$(dirname "$SCRIPT_DIR")" - -. "$PROJECT_DIR/config.env" - -function bootc_image_builder () { - local config="$1" - shift - podman run --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t -v "$config:/$(basename $config):ro" \ - -v $PWD/root/usr/local/libvirt/images/nextcloud:/output -v /var/lib/containers/storage:/var/lib/containers/storage \ - registry.redhat.io/rhel10/bootc-image-builder:latest --config "/$(basename $config)" "$@" -} - -BOOTC_IMAGE="$(echo -n "$TARGET_IMAGE_TEMPLATE" | SCENARIO=scenario1 envsubst)" -echo "Building qcow2 from $BOOTC_IMAGE..." -bootc_image_builder "$PWD/config.toml" --type qcow2 "$BOOTC_IMAGE" - diff --git a/bootc/scenario3a/root/etc/default/bootstrap-vm-nextcloud.env b/bootc/scenario3a/root/etc/default/bootstrap-vm-nextcloud.env index c17f9e5..0e2e1cd 100644 --- a/bootc/scenario3a/root/etc/default/bootstrap-vm-nextcloud.env +++ b/bootc/scenario3a/root/etc/default/bootstrap-vm-nextcloud.env @@ -4,4 +4,5 @@ DOMAIN_DISK_SIZE=100 DOMAIN_OS_VARIANT=rhel9.6 DOMAIN_MAC_ADDRESS=04:00:00:00:00:01 FLIGHTCTL_LABELS_OVERRIDE={ "type": "virtualmachine", "vm.name": "nextcloud", "scenario": "scenario1" } -DOMAIN_DISK_SOURCE=edge-registry.itix.fr/demo-edge-retail/scenario1:latest +DOMAIN_DISK_SOURCE=edge-registry.itix.fr/demo-edge-retail/scenario1-qcow2:latest +REGISTRY_AUTH_FILE=/etc/ostree/auth.json diff --git a/bootc/scenario3a/root/etc/systemd/system/bootstrap-vm@.service b/bootc/scenario3a/root/etc/systemd/system/bootstrap-vm@.service index 6bd41e1..edefd2a 100644 --- a/bootc/scenario3a/root/etc/systemd/system/bootstrap-vm@.service +++ b/bootc/scenario3a/root/etc/systemd/system/bootstrap-vm@.service @@ -1,6 +1,8 @@ [Unit] Description=RHDE VM Bootstrap Service Documentation=man:systemd.service(5) +After=network-online.target +Wants=network-online.target # Only start if the VM root disk does not exist ConditionPathExists=!/var/lib/libvirt/images/%i/root.qcow2 diff --git a/bootc/scenario3a/root/usr/local/bin/bootstrap-vm.sh b/bootc/scenario3a/root/usr/local/bin/bootstrap-vm.sh index b5b5467..c6446ce 100755 --- a/bootc/scenario3a/root/usr/local/bin/bootstrap-vm.sh +++ b/bootc/scenario3a/root/usr/local/bin/bootstrap-vm.sh @@ -26,12 +26,34 @@ cleanup() { } trap cleanup EXIT +# This function extracts the first layer blob from a Podman artifact and saves it to the specified output file. +# It is used when the "podman artifact extract" command is not available. +function podman_artifact_extract() { + local ARTIFACT="$1" + local OUTPUT_FILE="$2" + local container_id + + local DIGEST_WITH_ALGO="$(podman artifact inspect $ARTIFACT | jq -r '.Manifest.layers[0].digest')" + local FILENAME="$(podman artifact inspect $ARTIFACT | jq -r '.Manifest.layers[0].annotations["org.opencontainers.image.title"]')" + echo "Extracting blob $DIGEST_WITH_ALGO ($FILENAME) from artifact $ARTIFACT to $OUTPUT_FILE..." + + local BLOB_HASH="${DIGEST_WITH_ALGO#sha256:}" + local SOURCE_PATH="$(find /var/lib/containers/storage -type f -name $BLOB_HASH)" + if [ -z "$SOURCE_PATH" ]; then + echo "Blob $BLOB_HASH not found in container storage!" + return 1 + fi + + cp "$SOURCE_PATH" "$OUTPUT_FILE" +} + # Create a temporary directory to hold the VM image and copy the base image there install -m 0710 -o root -g qemu --context=system_u:object_r:virt_image_t:s0 -d "$temp_dir" # Pull the base image defined in the environment file podman artifact pull "${DOMAIN_DISK_SOURCE}" -podman artifact extract "${DOMAIN_DISK_SOURCE}" "$temp_dir/root.qcow2" +#podman artifact extract "${DOMAIN_DISK_SOURCE}" "$temp_dir/root.qcow2" +podman_artifact_extract "${DOMAIN_DISK_SOURCE}" "$temp_dir/root.qcow2" chown root:qemu "$temp_dir/root.qcow2" chmod 0660 "$temp_dir/root.qcow2" chcon system_u:object_r:virt_image_t:s0 "$temp_dir/root.qcow2"