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