xref: /freebsd/release/Makefile.ec2 (revision c482d65cd187a5cc311ede3e328270bfcd014e73)
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.if ${AMIBOOTMETHOD} == "UEFI-PREFERRED"
33AMIBASENAME=${TYPE} ${REVISION}-${BRANCH}-${TARGET}${AMINAMESUFFIX}
34.else
35AMIBASENAME=${TYPE} ${REVISION}-${BRANCH}-${TARGET}${AMINAMESUFFIX} ${AMIBOOTMETHOD}
36.endif
37
38CLEANFILES+=		ec2ami
39
40.if !exists(/usr/local/bin/bsdec2-image-upload)
41CW_EC2_PORTINSTALL=	cw-ec2-portinstall
42CLEANFILES+=		${CW_EC2_PORTINSTALL}
43.else
44CW_EC2_PORTINSTALL=
45.endif
46
47cw-ec2-portinstall:
48.if !exists(/usr/local/bin/bsdec2-image-upload)
49. if !exists(${PORTSDIR}/net/bsdec2-image-upload/Makefile)
50.  if !exists(/usr/local/sbin/pkg-static)
51	env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf
52.  endif
53	env ASSUME_ALWAYS_YES=yes pkg install -y net/bsdec2-image-upload
54. else
55	env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/net/bsdec2-image-upload \
56	    BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \
57	    all install clean
58. endif
59.endif
60	@touch ${.TARGET}
61
62.for _FS in ${EC2_FSLIST}
63.for _FL in ${EC2_FLAVOURS:tl}
64.if defined(SSMPREFIX) && !empty(SSMPREFIX)
65SSMOPTS_${_FL}_${_FS}=	--ssm-name ${SSMPREFIX}/${TARGET_ARCH:S/aarch64/arm64/}/${_FL}/${_FS}/${REVISION}/${BRANCH}
66.endif
67EC2AMILIST+=	ec2ami-${_FL}-${_FS}
68CLEANFILES+=	ec2ami-${_FL}-${_FS}
69ec2ami-${_FL}-${_FS}: cw-ec2-${_FL}-${_FS} ${CW_EC2_PORTINSTALL}
70.if !defined(AWSKEYFILE) || !exists(${AWSKEYFILE})
71	@echo "--------------------------------------------------------------"
72	@echo ">>> AWSKEYFILE must point at AWS keys for EC2 AMI creation"
73	@echo "--------------------------------------------------------------"
74	@false
75.endif
76.if !defined(AWSREGION)
77	@echo "--------------------------------------------------------------"
78	@echo ">>> AWSREGION must be specified EC2 AMI creation"
79	@echo "--------------------------------------------------------------"
80	@false
81.endif
82.if !defined(AWSBUCKET)
83	@echo "--------------------------------------------------------------"
84	@echo ">>> AWSBUCKET must be specified for EC2 AMI creation"
85	@echo "--------------------------------------------------------------"
86	@false
87.endif
88	/usr/local/bin/bsdec2-image-upload ${PUBLISH} ${PUBLICSNAP} \
89	    ${EC2ARCH} ${SSMOPTS_${_FL}_${_FS}} ${BOOTMODEOPT} --sriov --ena \
90	    ${.OBJDIR}/${EC2-${_FL:tu}${_FS:tu}IMAGE} \
91	    "${AMIBASENAME} ${_FL} ${_FS:tu}" \
92	    "${TYPE}/${TARGET} ${GITBRANCH}@${GITREV}" \
93	    ${AWSREGION} ${AWSBUCKET} ${AWSKEYFILE} \
94	    ${EC2SNSTOPIC} ${EC2SNSREL} ${EC2SNSVERS}
95	@touch ${.TARGET}
96.endfor
97.endfor
98
99ec2ami: ec2ami-base-${VMFS}
100ec2amis: ${EC2AMILIST}
101