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