1# 2# Makefile for preparing & uploading Oracle Cloud images from existing 3# .raw files created by cloudware-release. 4# 5# Overview: 6# 7# The base image is already created by cloudware-release. 8# 9# Construct the custom OCI metadata, derived from exported official OCI images. 10# It is architecture-specific but appears mostly stable over time. 11# Compress the raw image and place it in the same directory as the metadata. 12# Make a GNU format tarball of these files. 13# Upload the tarball to Oracle Cloud via a pre-approved curl URI, into 14# the FreeBSD Foundation's Oracle Cloud account. 15# 16# These images go into the "re" bucket in us-ashburn-1 region, which 17# is mounted into the FreeBSD Foundation Oracle Marketplace account. 18# Once uploaded, a manual step is needed to import the images as local 19# custom images. These can then be tested within the us-ashburn-1 region. 20# Once tested, follow the manual Oracle Marketplace import process to 21# create a new FreeBSD version, attach the images, and initiate validation 22# by Oracle. This can take up to 5 working days. Once complete, a final 23# manual step is needed to mark the currently private images, public. 24# Syncing to all sites should take 2-3 hours after this final step. 25 26ORACLE_BASENAME= ${OSRELEASE}-${BUILDDATE}${GITREV:C/^(.+)/-\1/} 27ORACLE_PORTS_LIST= ftp/curl emulators/qemu@tools 28CLEANFILES+= cw-oracle-portinstall 29 30cw-oracle-portinstall: .PHONY 31.if !exists(/usr/local/bin/curl) || !exists(/usr/local/bin/qemu-img) 32. if !exists(${PORTSDIR}/Makefile) 33. if !exists(/usr/local/sbin/pkg-static) 34 env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf 35. endif 36 env ASSUME_ALWAYS_YES=yes pkg install -y ${ORACLE_PORTS_LIST} 37. else 38 env UNAME_r=${UNAME_r} make -C \ 39 ${PORTSDIR}/ftp/curl \ 40 BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \ 41 all install clean 42 env UNAME_r=${UNAME_r} FLAVOR=tools make -C \ 43 ${PORTSDIR}/emulators/qemu \ 44 BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \ 45 all install clean 46. endif 47.endif 48 49.for _FS in ${ORACLE_FSLIST} 50ORACLE_OCI_LIST+= cw-oracle-${_FS}.oci 51ORACLE_UPLOAD_LIST+= cw-oracle-upload-${_FS} 52CLEANFILES+= cw-oracle-${_FS}.oci 53ORACLE_TMP_${_FS}= cw-oracle-${_FS}.oci.tmpdir 54CLEANDIRS+= ${ORACLE_TMP_${_FS}} 55ORACLE_METADATA= ${.CURDIR}/scripts/oracle 56ORACLE_CAPABILITY= ${.CURDIR}/scripts/oracle/image_capability_data.json 57ORACLE_TEMPLATE= ${.CURDIR}/scripts/oracle/image_metadata.json 58ORACLE_OUTPUT_${_FS}= ${ORACLE_TMP_${_FS}}/image_metadata.json 59.if ${TARGET} == "arm64" 60ORACLE_SHAPES= ${ORACLE_METADATA}/arm64_shape_compatibilities.json 61.else 62ORACLE_SHAPES= ${ORACLE_METADATA}/default_shape_compatibilities.json 63.endif 64 65cw-oracle-${_FS}.oci: cw-oracle-portinstall cw-oracle-${_FS}-raw 66 mkdir -p ${ORACLE_TMP_${_FS}} 67 # create architecture-specific JSON metadata 68 env TYPE="${TYPE}" \ 69 OSRELEASE="${OSRELEASE}" \ 70 ORACLE_CAPABILITY="${ORACLE_CAPABILITY}" \ 71 ORACLE_SHAPES="${ORACLE_SHAPES}" \ 72 ORACLE_TEMPLATE="${ORACLE_TEMPLATE}" \ 73 ORACLE_OUTPUT="${ORACLE_OUTPUT_${_FS}}" \ 74 ${ORACLE_METADATA}/generate_metadata.lua 75 76 # convert raw to native qcow2 for zstd compression, saves ~ 8GiB 77 qemu-img convert -S 512b -p -O qcow2 -c -o compression_type=zstd \ 78 ${.OBJDIR}/${ORACLE${_FS:tu}RAWIMAGE} \ 79 ${ORACLE_TMP_${_FS}}/output.QCOW2 80 81 # Create GNU-compatible tarball using BSD tar 82 tar --format=gnutar -cf ${.TARGET} -C ${ORACLE_TMP_${_FS}} \ 83 image_metadata.json output.QCOW2 84 85 echo "Oracle image ${.TARGET} is ready for upload." 86 87cw-oracle-upload-${_FS}: cw-oracle-${_FS}.oci 88.if !defined(ORACLE_PAR_URL) || empty(ORACLE_PAR_URL) 89 @echo "--------------------------------------------------------------" 90 @echo ">>> ORACLE_PAR_URL must be set for Oracle image upload" 91 @echo ">>> for testing, use a file:/// URL to a local directory" 92 @echo "--------------------------------------------------------------" 93 @false 94.endif 95 echo "Please wait ... uploading cw-oracle-${_FS}.oci to ${ORACLE_BASENAME}-${_FS}.oci" 96 curl -s ${ORACLE_PAR_URL}/${ORACLE_BASENAME}-${_FS}.oci --upload-file cw-oracle-${_FS}.oci 97 echo "Uploaded cw-oracle-${_FS}.oci as ${ORACLE_BASENAME}-${_FS}.oci" 98 touch ${.TARGET} 99.endfor 100 101cw-oracle-upload: cw-oracle-portinstall ${ORACLE_UPLOAD_LIST} 102