From 7333bc7fdc1d5ce9cb75989797b8f76ad4e831fc Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Mon, 18 Nov 2024 14:49:27 -0500 Subject: [PATCH 1/2] Update to work with COSA 10e397b There was a pretty large refactor tha landed in COSA in https://github.com/coreos/coreos-assembler/pull/3943 Let's pick up those changes here and change the way we call runvm-osbuild to adapt. --- README.md | 2 +- custom-coreos-disk-images.sh | 87 +++++++++++++++++------------------- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 56fdb14..91ed2ea 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ mode and some software installed: sudo dnf update -y sudo setenforce 0 sudo sed -i -e 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config -sudo dnf install -y osbuild osbuild-tools osbuild-ostree podman jq xfsprogs e2fsprogs +sudo dnf install -y osbuild osbuild-tools osbuild-ostree podman jq xfsprogs e2fsprogs zip ``` Now you should be able to generate an image with something like: diff --git a/custom-coreos-disk-images.sh b/custom-coreos-disk-images.sh index 05dc367..444808d 100755 --- a/custom-coreos-disk-images.sh +++ b/custom-coreos-disk-images.sh @@ -18,11 +18,22 @@ set -eux -o pipefail # sudo ./custom-coreos-disk-images.sh \ # --ociarchive /path/to/coreos.ociarchive --platforms qemu,metal # -# - coreos.ociarchive.x86_64.qemu.qcow2 -# - coreos.ociarchive.x86_64.metal.qcow2 +# - coreos-qemu.x86_64.qcow2 +# - coreos-metal.x86_64.raw ARCH=$(arch) +# A list of supported platforms and the filename suffix of the main +# artifact that platform produces. +declare -A SUPPORTED_PLATFORMS=( + ['applehv']='raw.gz' + ['gcp']='tar.gz' + ['hyperv']='vhdx.zip' + ['metal4k']='raw' + ['metal']='raw' + ['qemu']='qcow2' +) + check_rpm() { req=$1 if ! rpm -q "$req" &>/dev/null; then @@ -32,7 +43,7 @@ check_rpm() { } check_rpms() { - reqs=(osbuild osbuild-tools osbuild-ostree jq xfsprogs e2fsprogs) + reqs=(osbuild osbuild-tools osbuild-ostree jq xfsprogs e2fsprogs zip) for req in "${reqs[@]}"; do check_rpm "$req" done @@ -113,59 +124,36 @@ main() { image_size=16384 # RHCOS fi - # Make a local tmpdir + # Make a local tmpdir and outidr tmpdir=$(mktemp -d ./tmp-osbuild-XXX) + outdir="${tmpdir}/out" + mkdir $outdir # Freeze on specific version for now to increase stability. #gitreporef="main" - gitreporef="3a76784b37fe073718a7f9d9d67441d9d8b34c10" + gitreporef="10e397bfd966a60e5e43ec3ad49443c0c9323d74" gitrepotld="https://raw.githubusercontent.com/coreos/coreos-assembler/${gitreporef}/" pushd "${tmpdir}" curl -LO --fail "${gitrepotld}/src/runvm-osbuild" chmod +x runvm-osbuild - for manifest in "coreos.osbuild.${ARCH}.mpp.yaml" platform.{applehv,gcp,hyperv,metal,qemu}.ipp.yaml; do + for manifest in "coreos.osbuild.${ARCH}.mpp.yaml" platform.{applehv,gcp,hyperv,metal,qemu,qemu-secex}.ipp.yaml; do curl -LO --fail "${gitrepotld}/src/osbuild-manifests/${manifest}" done popd - for platform in "${PLATFORMS[@]}"; do - - suffix= - case $platform in - applehv) - suffix=raw - ;; - gcp) - suffix=tar.gz - ;; - hyperv) - suffix=vhdx - ;; - metal) - suffix=raw - ;; - qemu) - suffix=qcow2 - ;; - *) - echo "unknown platform provided" - exit 1 - ;; - esac - outfile="./$(basename $OCIARCHIVE).${ARCH}.${platform}.${suffix}" - - # - rootfs size is only used on s390x secex so we pass "0" here - # - extra-kargs from image.yaml/image.json is currently empty - # on RHCOS but we may want to start picking it up from inside - # the container image (/usr/share/coreos-assembler/image.json) - # in the future. https://github.com/openshift/os/blob/master/image.yaml - cat > "${tmpdir}/diskvars.json" << EOF + # - rootfs size is only used on s390x secex so we pass "0" here + # - extra-kargs from image.yaml/image.json is currently empty + # on RHCOS but we may want to start picking it up from inside + # the container image (/usr/share/coreos-assembler/image.json) + # in the future. https://github.com/openshift/os/blob/master/image.yaml + runvm_osbuild_config_json="${tmpdir}/runvm-osbuild-config.json" + cat > "${runvm_osbuild_config_json}" << EOF { + "artifact-name-prefix": "$(basename -s .ociarchive $OCIARCHIVE)", "osname": "${osname}", "deploy-via-container": "true", "ostree-container": "${OCIARCHIVE}", - "image-type": "${platform}", "container-imgref": "${imgref}", "metal-image-size": "3072", "cloud-image-size": "${image_size}", @@ -173,14 +161,23 @@ main() { "extra-kargs-string": "" } EOF - "${tmpdir}/runvm-osbuild" \ - --config "${tmpdir}/diskvars.json" \ - --filepath "./${outfile}" \ - --mpp "${tmpdir}/coreos.osbuild.${ARCH}.mpp.yaml" - echo "Created $platform image file at: ${outfile}" + "${tmpdir}/runvm-osbuild" \ + --config "${runvm_osbuild_config_json}" \ + --mpp "${tmpdir}/coreos.osbuild.${ARCH}.mpp.yaml" \ + --outdir "${outdir}" \ + --platforms "$(IFS=,; echo "${PLATFORMS[*]}")" + + for platform in "${PLATFORMS[@]}"; do + # Set the filename of the artifact and the local image path + # where from the OSBuild out directory where it resides. + suffix="${SUPPORTED_PLATFORMS[$platform]}" + imgname=$(basename -s .ociarchive $OCIARCHIVE)-${platform}.${ARCH}.${suffix} + imgpath="${outdir}/${platform}/${imgname}" + mv "${imgpath}" ./ + echo "Created $platform image file at: ${imgname}" done - rm -f "${tmpdir}"/*; rmdir "${tmpdir}" # Cleanup + rm -rf "${outdir}"; rm -f "${tmpdir}"/*; rmdir "${tmpdir}" # Cleanup } main "$@" From cb130bfd4970ad9db2fd7217c3fcc31e7d70e9ac Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Mon, 18 Nov 2024 14:51:25 -0500 Subject: [PATCH 2/2] drop set -x I'm finding it a little too verbose for now. --- custom-coreos-disk-images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom-coreos-disk-images.sh b/custom-coreos-disk-images.sh index 444808d..6d48243 100755 --- a/custom-coreos-disk-images.sh +++ b/custom-coreos-disk-images.sh @@ -1,5 +1,5 @@ #!/usr/bin/bash -set -eux -o pipefail +set -euo pipefail # Run this script on a fully up to date Fedora 41 VM with SELinux # in permissive mode and the following tools installed: