1# 2# $FreeBSD$ 3# 4# 5# Makefile for creating an EC2 AMI from a disk image. 6# 7 8.if ${BRANCH} == "CURRENT" || ${BRANCH} == "STABLE" || ${BRANCH} == "PRERELEASE" 9AMINAMESUFFIX!= date +-${BUILDDATE} 10.endif 11.if defined(EC2PUBLIC) && !empty(EC2PUBLIC) 12PUBLISH= --public 13.endif 14.if defined(EC2PUBLICSNAP) && !empty(EC2PUBLICSNAP) 15PUBLICSNAP= --publicsnap 16.endif 17.if defined(EC2SNSTOPIC) && !empty(EC2SNSTOPIC) 18EC2SNSREL= ${REVISION}-${BRANCH} 19EC2SNSVERS= ${GITBRANCH}@${GITREV} 20.endif 21.if ${TARGET_ARCH} != "amd64" 22EC2ARCH= --${TARGET_ARCH:S/aarch64/arm64/} 23.endif 24.if !defined(AMIBOOTMETHOD) 25AMIBOOTMETHOD= UEFI-PREFERRED 26.endif 27.if ${AMIBOOTMETHOD} == "UEFI" && ${TARGET_ARCH} == "amd64" 28BOOTMODEOPT= --uefi 29.endif 30.if ${AMIBOOTMETHOD} == "UEFI-PREFERRED" && ${TARGET_ARCH} == "amd64" 31BOOTMODEOPT= --uefi-preferred 32.endif 33 34CLEANFILES+= ec2ami 35 36.if !exists(/usr/local/bin/bsdec2-image-upload) 37CW_EC2_PORTINSTALL= cw-ec2-portinstall 38CLEANFILES+= ${CW_EC2_PORTINSTALL} 39.else 40CW_EC2_PORTINSTALL= 41.endif 42 43cw-ec2-portinstall: 44.if exists(${PORTSDIR}/net/bsdec2-image-upload/Makefile) 45 env - UNAME_r=${UNAME_r} PATH=$$PATH make -C ${PORTSDIR}/net/bsdec2-image-upload BATCH=1 all install clean 46.else 47. if !exists(/usr/local/sbin/pkg-static) 48 env ASSUME_ALWAYS_YES=yes pkg bootstrap -y 49. endif 50 env ASSUME_ALWAYS_YES=yes pkg install -y net/bsdec2-image-upload 51.endif 52 @touch ${.TARGET} 53 54.for _FS in ${EC2_FSLIST} 55.if defined(SSMPREFIX) && !empty(SSMPREFIX) 56SSMOPTS_${_FS}= --ssm-name ${SSMPREFIX}/${TARGET_ARCH:S/aarch64/arm64/}/base/${_FS}/${REVISION}/${BRANCH} 57.endif 58EC2AMILIST+= ec2ami-${_FS} 59ec2ami-${_FS}: cw-ec2-${_FS} ${CW_EC2_PORTINSTALL} 60.if !defined(AWSKEYFILE) || !exists(${AWSKEYFILE}) 61 @echo "--------------------------------------------------------------" 62 @echo ">>> AWSKEYFILE must point at AWS keys for EC2 AMI creation" 63 @echo "--------------------------------------------------------------" 64 @false 65.endif 66.if !defined(AWSREGION) 67 @echo "--------------------------------------------------------------" 68 @echo ">>> AWSREGION must be specified EC2 AMI creation" 69 @echo "--------------------------------------------------------------" 70 @false 71.endif 72.if !defined(AWSBUCKET) 73 @echo "--------------------------------------------------------------" 74 @echo ">>> AWSBUCKET must be specified for EC2 AMI creation" 75 @echo "--------------------------------------------------------------" 76 @false 77.endif 78 /usr/local/bin/bsdec2-image-upload ${PUBLISH} ${PUBLICSNAP} \ 79 ${EC2ARCH} ${SSMOPTS_${_FS}} ${BOOTMODEOPT} --sriov --ena \ 80 ${.OBJDIR}/${EC2${_FS:tu}IMAGE} \ 81 "${TYPE} ${REVISION}-${BRANCH}-${TARGET}${AMINAMESUFFIX} ${AMIBOOTMETHOD} ${_FS:tu}" \ 82 "${TYPE}/${TARGET} ${GITBRANCH}@${GITREV}" \ 83 ${AWSREGION} ${AWSBUCKET} ${AWSKEYFILE} \ 84 ${EC2SNSTOPIC} ${EC2SNSREL} ${EC2SNSVERS} 85 @touch ${.TARGET} 86.endfor 87 88ec2ami: ec2ami-${VMFS} 89ec2amis: ${EC2AMILIST} 90