#!/bin/bash set -euo pipefail : "${KUBE_IMG_CACHE:?KUBE_IMG_CACHE is required}" : "${KUBE_VERSION:?KUBE_VERSION is required}" : "${ARCH:?ARCH is required}" : "${ROOTFS:?ROOTFS is required}" OS=linux # IMPORTANT: # This must match what the target system will use at runtime. # If your target CRI-O uses overlay, leave this as overlay. # If overlay seeding fails in your build environment, fix the build env; # do not silently switch to vfs unless the target will also use vfs. STORAGE_DRIVER="${STORAGE_DRIVER:-overlay}" # Optional. Needed by many overlay-in-container setups. FUSE_OVERLAYFS="${FUSE_OVERLAYFS:-/usr/bin/fuse-overlayfs}" # Keep archive cache version/arch scoped so downloads do not get mixed. ARCHIVE_DIR="${KUBE_IMG_CACHE}/archives/${ARCH}/${KUBE_VERSION}" # Seed directly into the target rootfs image store. TARGET_GRAPHROOT="${ROOTFS}/var/lib/containers/storage" # Build-host temporary runtime state for containers/storage. TMPDIR="$(mktemp -d)" RUNROOT="${TMPDIR}/runroot" STORAGE_CONF="${TMPDIR}/storage.conf" cleanup() { rm -rf "${TMPDIR}" } trap cleanup EXIT mkdir -p "${ARCHIVE_DIR}" mkdir -p "${TARGET_GRAPHROOT}" mkdir -p "${RUNROOT}" echo "============================================================" echo "Preparing Kubernetes CRI-O image store" echo " KUBE_VERSION = ${KUBE_VERSION}" echo " ARCH = ${ARCH}" echo " ARCHIVE_DIR = ${ARCHIVE_DIR}" echo " TARGET_GRAPHROOT = ${TARGET_GRAPHROOT}" echo " STORAGE_DRIVER = ${STORAGE_DRIVER}" echo "============================================================" # Build a temporary containers/storage config that writes directly into # the target rootfs image store. if [ "${STORAGE_DRIVER}" = "overlay" ]; then cat > "${STORAGE_CONF}" < "${STORAGE_CONF}" </dev/null 2>&1; then echo "Store hit: ${img}" continue fi echo "Seeding CRI-O store: ${img}" skopeo copy \ --override-os "${OS}" \ --override-arch "${ARCH}" \ "oci-archive:${archive}" \ "containers-storage:${img}" done echo echo "Done." echo "Archives: ${ARCHIVE_DIR}" echo "CRI-O storage: ${TARGET_GRAPHROOT}"