#! /bin/sh # Build an Open Container Initiative (OCI) container image curdir=$1; shift rev=$1; shift branch=$1; shift arch=$1; shift image=$1; shift output=$1; shift major=${rev%.*} minor=${rev#*.} abi=FreeBSD:${major}:${arch} ver=${rev}-${branch}-${arch} echo "Building OCI freebsd${major}-${image} image for ${abi}" . ${curdir}/tools/oci-image-${image}.conf init_repo() { local workdir=$1; shift local abi=$1; shift mkdir -p ${workdir}/repos cat > ${workdir}/repos/base.conf < ${workdir}/config.json local config_hash=$(sha256 -q < ${workdir}/config.json) local config_size=$(stat -f %z ${workdir}/config.json) echo "{\"schemaVersion\":2,\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\",\"config\":{\"mediaType\":\"application/vnd.oci.image.config.v1+json\",\"digest\":\"sha256:${config_hash}\",\"size\":${config_size}},\"layers\":[{\"mediaType\":\"application/vnd.oci.image.layer.v1.tar+gzip\",\"digest\":\"sha256:${root_hash}\",\"size\":${root_size}}],\"annotations\":{}}" > ${workdir}/manifest.json local manifest_hash=$(sha256 -q < ${workdir}/manifest.json) local manifest_size=$(stat -f %z ${workdir}/manifest.json) mkdir -p ${workdir}/oci/blobs/sha256 echo "{\"imageLayoutVersion\": \"1.0.0\"}" > ${workdir}/oci/oci-layout echo "{\"schemaVersion\":2,\"manifests\":[{\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\",\"digest\":\"sha256:${manifest_hash}\",\"size\":${manifest_size},\"annotations\":{\"org.opencontainers.image.ref.name\":\"freebsd-${image}:${ver}\"}}]}" > ${workdir}/oci/index.json ln ${workdir}/rootfs.tar.gz ${workdir}/oci/blobs/sha256/${root_hash} ln ${workdir}/config.json ${workdir}/oci/blobs/sha256/${config_hash} ln ${workdir}/manifest.json ${workdir}/oci/blobs/sha256/${manifest_hash} tar -C ${workdir}/oci --xz --strip-components 1 --no-read-sparse -a -cf ${output} . } # Prefix with "container-image-" so that we can create a unique work area under # ${.OBJDIR}. We can assume that make has set our working directory to # ${.OBJDIR}. workdir=${PWD}/container-image-${image} init_repo ${workdir} ${abi} if [ -n "${OCI_BASE_IMAGE}" ]; then base_workdir=${PWD}/container-image-${OCI_BASE_IMAGE} else base_workdir= fi create_container ${workdir} ${base_workdir} oci_image_build commit_container ${workdir} ${image} ${output}