xref: /freebsd/release/Makefile.ec2 (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
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 defined(SSMPREFIX) && !empty(SSMPREFIX)
22SSMOPTS=	--ssm-name ${SSMPREFIX}/${TARGET_ARCH:S/aarch64/arm64/}/base/ufs/${REVISION}/${BRANCH}
23.endif
24.if ${TARGET_ARCH} != "amd64"
25EC2ARCH=	--${TARGET_ARCH:S/aarch64/arm64/}
26.endif
27.if !defined(AMIBOOTMETHOD)
28AMIBOOTMETHOD=	UEFI-PREFERRED
29.endif
30.if ${AMIBOOTMETHOD} == "UEFI" && ${TARGET_ARCH} == "amd64"
31BOOTMODEOPT=	--uefi
32.endif
33.if ${AMIBOOTMETHOD} == "UEFI-PREFERRED" && ${TARGET_ARCH} == "amd64"
34BOOTMODEOPT=	--uefi-preferred
35.endif
36
37CLEANFILES+=		ec2ami
38
39.if !exists(/usr/local/bin/bsdec2-image-upload)
40CW_EC2_PORTINSTALL=	cw-ec2-portinstall
41CLEANFILES+=		${CW_EC2_PORTINSTALL}
42.else
43CW_EC2_PORTINSTALL=
44.endif
45
46cw-ec2-portinstall:
47.if exists(${PORTSDIR}/net/bsdec2-image-upload/Makefile)
48	env - UNAME_r=${UNAME_r} PATH=$$PATH make -C ${PORTSDIR}/net/bsdec2-image-upload BATCH=1 all install clean
49.else
50. if !exists(/usr/local/sbin/pkg-static)
51	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
52. endif
53	env ASSUME_ALWAYS_YES=yes pkg install -y net/bsdec2-image-upload
54.endif
55	@touch ${.TARGET}
56
57ec2ami: cw-ec2 ${CW_EC2_PORTINSTALL}
58.if !defined(AWSKEYFILE) || !exists(${AWSKEYFILE})
59	@echo "--------------------------------------------------------------"
60	@echo ">>> AWSKEYFILE must point at AWS keys for EC2 AMI creation"
61	@echo "--------------------------------------------------------------"
62	@false
63.endif
64.if !defined(AWSREGION)
65	@echo "--------------------------------------------------------------"
66	@echo ">>> AWSREGION must be specified EC2 AMI creation"
67	@echo "--------------------------------------------------------------"
68	@false
69.endif
70.if !defined(AWSBUCKET)
71	@echo "--------------------------------------------------------------"
72	@echo ">>> AWSBUCKET must be specified for EC2 AMI creation"
73	@echo "--------------------------------------------------------------"
74	@false
75.endif
76	/usr/local/bin/bsdec2-image-upload ${PUBLISH} ${PUBLICSNAP} \
77	    ${EC2ARCH} ${SSMOPTS} ${BOOTMODEOPT} --sriov --ena \
78	    ${.OBJDIR}/ec2.raw \
79	    "${TYPE} ${REVISION}-${BRANCH}-${TARGET}${AMINAMESUFFIX} ${AMIBOOTMETHOD}" \
80	    "${TYPE}/${TARGET} ${GITBRANCH}@${GITREV}" \
81	    ${AWSREGION} ${AWSBUCKET} ${AWSKEYFILE} \
82	    ${EC2SNSTOPIC} ${EC2SNSREL} ${EC2SNSVERS}
83	@touch ${.TARGET}
84