xref: /freebsd/release/Makefile.oracle (revision df21a004be237a1dccd03c7b47254625eea62fa9)
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/}
27CLEANFILES+=	cw-oracle-portinstall
28
29cw-oracle-portinstall: .PHONY
30.if (!exists(/usr/local/bin/curl) || !exists(/usr/local/bin/qemu-img)) && !exists(${PORTSDIR}/Makefile)
31. if !exists(/usr/local/sbin/pkg-static)
32	env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf
33. endif
34.endif
35.if !exists(/usr/local/bin/curl)
36. if !exists(${PORTSDIR}/Makefile)
37	env ASSUME_ALWAYS_YES=yes pkg install -y ftp/curl
38. else
39	env UNAME_r=${UNAME_r} make -C \
40		${PORTSDIR}/ftp/curl \
41		BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \
42		all install clean
43. endif
44.endif
45.if !exists(/usr/local/bin/qemu-img)
46. if !exists(${PORTSDIR}/Makefile)
47	env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu@tools
48. else
49	env UNAME_r=${UNAME_r} FLAVOR=tools make -C \
50		${PORTSDIR}/emulators/qemu \
51		BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \
52		all install clean
53. endif
54.endif
55
56.for _FS in ${ORACLE_FSLIST}
57ORACLE_OCI_LIST+=	cw-oracle-${_FS}.oci
58ORACLE_UPLOAD_LIST+=	cw-oracle-upload-${_FS}
59CLEANFILES+=		cw-oracle-${_FS}.oci
60ORACLE_TMP_${_FS}=		cw-oracle-${_FS}.oci.tmpdir
61CLEANDIRS+=		${ORACLE_TMP_${_FS}}
62ORACLE_METADATA=	${.CURDIR}/scripts/oracle
63ORACLE_CAPABILITY=	${.CURDIR}/scripts/oracle/image_capability_data.json
64ORACLE_TEMPLATE=	${.CURDIR}/scripts/oracle/image_metadata.json
65ORACLE_OUTPUT_${_FS}=	${ORACLE_TMP_${_FS}}/image_metadata.json
66.if ${TARGET} == "arm64"
67ORACLE_SHAPES=		${ORACLE_METADATA}/arm64_shape_compatibilities.json
68.else
69ORACLE_SHAPES=		${ORACLE_METADATA}/default_shape_compatibilities.json
70.endif
71
72cw-oracle-${_FS}.oci: cw-oracle-portinstall cw-oracle-${_FS}-raw
73	mkdir -p ${ORACLE_TMP_${_FS}}
74	# create architecture-specific JSON metadata
75	env TYPE="${TYPE}" \
76		OSRELEASE="${OSRELEASE}" \
77		ORACLE_CAPABILITY="${ORACLE_CAPABILITY}" \
78		ORACLE_SHAPES="${ORACLE_SHAPES}" \
79		ORACLE_TEMPLATE="${ORACLE_TEMPLATE}" \
80		ORACLE_OUTPUT="${ORACLE_OUTPUT_${_FS}}" \
81		${ORACLE_METADATA}/generate_metadata.lua
82
83	# convert raw to native qcow2 for zstd compression, saves ~ 8GiB
84	qemu-img convert -S 512b -p -O qcow2 -c -o compression_type=zstd \
85		${.OBJDIR}/${ORACLE${_FS:tu}RAWIMAGE} \
86		${ORACLE_TMP_${_FS}}/output.QCOW2
87
88	# Create GNU-compatible tarball using BSD tar
89	tar --format=gnutar -cf ${.TARGET} -C ${ORACLE_TMP_${_FS}} \
90		image_metadata.json output.QCOW2
91
92	echo "Oracle image ${.TARGET} is ready for upload."
93
94cw-oracle-upload-${_FS}: cw-oracle-${_FS}.oci
95.if !defined(ORACLE_PAR_URL) || empty(ORACLE_PAR_URL)
96	@echo "--------------------------------------------------------------"
97	@echo ">>> ORACLE_PAR_URL must be set for Oracle image upload"
98	@echo ">>> for testing, use a file:/// URL to a local directory"
99	@echo "--------------------------------------------------------------"
100	@false
101.endif
102	echo "Please wait ... uploading cw-oracle-${_FS}.oci to ${ORACLE_BASENAME}-${_FS}.oci"
103	curl -s ${ORACLE_PAR_URL}/${ORACLE_BASENAME}-${_FS}.oci --upload-file cw-oracle-${_FS}.oci
104	echo "Uploaded cw-oracle-${_FS}.oci as ${ORACLE_BASENAME}-${_FS}.oci"
105	touch ${.TARGET}
106.endfor
107
108cw-oracle-upload: cw-oracle-portinstall ${ORACLE_UPLOAD_LIST}
109