#!/bin/bash set -euo pipefail usage() { cat </dev/null || break; done) & } while [ $# -gt 0 ]; do flag="${1}"; shift; case "${flag}" in --config) config="${1}"; shift;; --help) usage; exit;; --mpp) mppyaml="${1}"; shift;; --outdir) outdir="${1}"; shift;; --platforms) # Split the comma separated string of platforms into an array IFS=, read -ra platforms <<<"$1"; shift ;; *) echo "${flag} is not understood."; usage; exit 10;; esac; done artifact_name_prefix=$(getconfig_def "artifact-name-prefix" "custom-coreos") build_version=$(getconfig_def "build-version" "0") ostree_container=$(getconfig "ostree-container") osname=$(getconfig "osname") metal_image_size_mb=$(getconfig "metal-image-size") cloud_image_size_mb=$(getconfig "cloud-image-size") rootfs_size_mb=$(getconfig "rootfs-size") container_imgref=$(getconfig "container-imgref") container_repo=$(getconfig_def "container-repo" "") container_tag=$(getconfig_def "container-tag" "") extra_kargs=$(getconfig "extra-kargs-string" "") # Since the underlying osbuild manifests will prefer the ociarchive # if it exists then let's check here to see if the container exists # in local container storage. If it does then we'll just pass that # and not pass any ociarchive info into the build. # # XXX: Disabling this for now as it ends up with inconsistent digests # in our deployed bootimages versus what's pushed to the registry # and is causing zincati to not work. # https://github.com/coreos/fedora-coreos-tracker/issues/2066 #if podman image exists "${container_repo}:${container_tag}"; then # ostree_container="" #fi # Since it doesn't exist create loop-control [ ! -e /dev/loop-control ] && mknod /dev/loop-control c 10 237 # Put the store on the cache filesystem since in the case we are # running unprivileged in COSA we won't be able to create files # with SELinux labels that the host's policy doesn't know about. storedir=cache/osbuild/store # Musical chairs for now with the outdir because osbuild does # cp -a and that will fail to preserve ownership when copying # from the cache qcow2 (where files are owned by root) to the # virtiofs mount. Eventually we can use idmapped virtiofs mount # inside the supermin VM and we won't need this. # https://gitlab.com/virtio-fs/virtiofsd/-/merge_requests/245 orig_outdir=$outdir outdir=cache/osbuild/out processed_json=$(mktemp -t osbuild-XXXX.json) myarch= for myarch in x86_64 aarch64 riscv64 ppc64le s390x; do processed_json="./osbuild-mpp-out-${myarch}.json" mppyaml="/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.${myarch}.mpp.yaml" # Run through the preprocessor # Note: don't quote the size arguements since they are numbers, not strings set -x; osbuild-mpp \ -D arch=\""${myarch}"\" \ -D artifact_name_prefix=\""${artifact_name_prefix}"\" \ -D build_version=\""${build_version}"\" \ -D ociarchive=\""${ostree_container}"\" \ -D osname=\""${osname}"\" \ -D container_imgref=\""${container_imgref}"\" \ -D container_repo=\""${container_repo}"\" \ -D container_tag=\""${container_tag}"\" \ -D extra_kargs=\""${extra_kargs}"\" \ -D metal_image_size_mb="${metal_image_size_mb}" \ -D cloud_image_size_mb="${cloud_image_size_mb}" \ -D rootfs_size_mb="${rootfs_size_mb}" \ "${mppyaml}" "${processed_json}" set +x done exit 1 log_disk_usage # Build the image set -x # shellcheck disable=SC2068 osbuild \ --out "$outdir" \ --store "$storedir" \ --cache-max-size 20GiB \ --checkpoint deployed-tree \ --checkpoint tree \ --checkpoint raw-image \ --checkpoint metal \ --checkpoint metal4k \ ${platforms[@]/#/--export=} \ "${processed_json}" set +x mv "${outdir}"/* "${orig_outdir}/" rm -f "${processed_json}"