xref: /freebsd/release/Makefile.ec2 (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
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
29.endif
30.if ${AMIBOOTMETHOD} == "UEFI" && ${TARGET_ARCH} == "amd64"
31BOOTMODEOPT=	--uefi
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
54ec2ami: cw-ec2 ${CW_EC2_PORTINSTALL}
55.if !defined(AWSKEYFILE) || !exists(${AWSKEYFILE})
56	@echo "--------------------------------------------------------------"
57	@echo ">>> AWSKEYFILE must point at AWS keys for EC2 AMI creation"
58	@echo "--------------------------------------------------------------"
59	@false
60.endif
61.if !defined(AWSREGION)
62	@echo "--------------------------------------------------------------"
63	@echo ">>> AWSREGION must be specified EC2 AMI creation"
64	@echo "--------------------------------------------------------------"
65	@false
66.endif
67.if !defined(AWSBUCKET)
68	@echo "--------------------------------------------------------------"
69	@echo ">>> AWSBUCKET must be specified for EC2 AMI creation"
70	@echo "--------------------------------------------------------------"
71	@false
72.endif
73	/usr/local/bin/bsdec2-image-upload ${PUBLISH} ${PUBLICSNAP} \
74	    ${EC2ARCH} ${SSMOPTS} ${BOOTMODEOPT} --sriov --ena \
75	    ${.OBJDIR}/ec2.raw \
76	    "${TYPE} ${REVISION}-${BRANCH}-${TARGET}${AMINAMESUFFIX} ${AMIBOOTMETHOD}" \
77	    "${TYPE}/${TARGET} ${GITBRANCH}@${GITREV}" \
78	    ${AWSREGION} ${AWSBUCKET} ${AWSKEYFILE} \
79	    ${EC2SNSTOPIC} ${EC2SNSREL} ${EC2SNSVERS}
80	@touch ${.TARGET}
81