Page MenuHomeFreeBSD
Paste P549

dch hacked upload script for OCI images
ActivePublic

Authored by dch on Oct 5 2022, 9:46 PM.
Tags
None
Referenced Files
F49314884: dch hacked upload script for OCI images
Oct 5 2022, 9:46 PM
Subscribers
None
function upload-to-oci.fish
# assumes you built via something like https://reviews.freebsd.org/D34746 already
# needs devel/oci-cli
set -x FREEBSD_VERSION (sh ../sys/conf/newvers.sh -V RELEASE | sed -E -e 's,^.+="(.+)",\1,')
set -x IMAGE_NAME (echo FreeBSD-$FREEBSD_VERSION-(uname -m)-(uname -p)-(date -u +%Y%m%d)-(git rev-parse HEAD | cut -c -7))
set -x IMAGE_SRC /usr/obj/usr/*/arm64.aarch64/release/oci.qcow2
set -x IMAGE_RAW $IMAGE_NAME.raw
set -x IMAGE_COW $IMAGE_NAME.qcow2
set -x IMAGE_JSON /tmp/$IMAGE_NAME.json
set -x IMAGE_SCHEMA /tmp/freebsd-arm64-schema.json
# we recompress the image as qemu-img gives significantly smaller size
test -s /tmp/$IMAGE_RAW \
|| qemu-img convert -S 1k -p -O raw \
$IMAGE_SRC /tmp/$IMAGE_RAW
test -s /tmp/$IMAGE_COW \
|| qemu-img convert -S 1k -p -O qcow2 -c \
/tmp/$IMAGE_RAW /tmp/$IMAGE_COW
# ideally, check that this new image can boot at least in qemu
# prepare OCI JSON paperwork
set -x OCI_NS (oci os ns get | jq -r .data)
set -x OCI_CID (oci iam user list | jq -r '.data[0]."compartment-id"')
# upload the file
test -s $IMAGE_JSON \
|| oci os object bulk-upload \
--namespace $OCI_NS \
--bucket-name freebsd-images \
--parallel-upload-count 10 \
--verify-checksum \
--no-overwrite \
--src-dir /tmp \
--include $IMAGE_COW
# convert the upload into a bootable iage
test -s $IMAGE_JSON \
|| oci compute image import from-object \
--bucket-name freebsd-images \
--compartment-id $OCI_CID \
--namespace $OCI_NS \
--operating-system FreeBSD \
--operating-system-version $FREEBSD_VERSION \
--source-image-type QCOW2 \
--launch-mode emulated \
--name $IMAGE_COW \
--display-name $IMAGE_COW
# wait for successful import
# lifecycle state changes from IMPORTING to AVAILABLE in ~ 15 minutes
echo -n importing...
while test ! -s $IMAGE_JSON
echo -n .
sleep 15
oci compute image list \
--compartment-id $OCI_CID \
--lifecycle-state AVAILABLE \
--display-name $IMAGE_COW \
> $IMAGE_JSON
end
echo OK
set -x OCI_IMAGE_OCID (jq -r '.data[0].id' $IMAGE_JSON)
jq . $IMAGE_JSON
# images need to have a schema
# get the global schema id
# this is flaky I think if there is no existing image to clone from
# this requires one manual schema change for an image previously
set -x OCI_GLOBAL_SCHEMA_ID (oci compute image-capability-schema list \
--compartment-id $OCI_CID --all \
| jq -r '.data[0]."compute-global-image-capability-schema-version-name"')
# get the default schema from the first entry in the global schema
# remove the E1000 and VFIO network attachment types
# this is our sanitised schema
oci compute image-capability-schema list \
--compartment-id $OCI_CID --all \
| jq -r '.data[0]."schema-data"' \
| egrep -v 'E1000|VFIO' \
| jq . > $IMAGE_SCHEMA
# create a new schema, attached to this specific image type
oci compute image-capability-schema create \
--compartment-id $OCI_CID \
--global-image-capability-schema-version-name $OCI_GLOBAL_SCHEMA_ID \
--image-id $OCI_IMAGE_OCID \
--schema-data file://$IMAGE_SCHEMA \
| jq .
# obtain a list of valid shapes
set -x OCI_VALID_SHAPES (oci compute shape list \
--compartment-id $OCI_CID \
| jq -r '.data[].shape' | sort | uniq)
# restrict this image to *only* boot on arm64 A1.Flex & A1.BM shapes
for s in $OCI_VALID_SHAPES
oci compute image-shape-compatibility-entry remove --force \
--image-id $OCI_IMAGE_OCID \
--shape-name $s
end
# add back the ones we need
for s in BM.Standard.A1.160 VM.Standard.A1.Flex
oci compute image-shape-compatibility-entry add \
--image-id $OCI_IMAGE_OCID --shape-name $s \
| jq .
end
end

Event Timeline

dch created this object in space S1 Global.