xref: /freebsd/release/Makefile.ec2 (revision d3d381b2b194b4d24853e92eecef55f262688d1a)
1#
2# $FreeBSD$
3#
4#
5# Makefile for creating an EC2 AMI from a disk image.
6#
7
8# Figure out where SVN is
9.if !defined(SVN_CMD) || empty(SVN_CMD)
10. for _P in /usr/bin /usr/local/bin
11.  for _S in svn svnlite
12.   if exists(${_P}/${_S})
13SVN_CMD=   ${_P}/${_S}
14.   endif
15.  endfor
16. endfor
17.endif
18.if exists(${SRCTOP}/.svn)
19.  if empty(EC2_SVNBRANCH)
20   EC2_SVNBRANCH!=	${SVN_CMD} info --show-item relative-url ${WORLDDIR} 2>/dev/null | sed -e 's/\^\///'
21.  export EC2_SVNBRANCH
22.  endif
23.  if empty(EC2_SVNREV)
24   EC2_SVNREV!=	${SVN_CMD} info --show-item last-changed-revision ${WORLDDIR} 2>/dev/null || true
25.  export EC2_SVNREV
26.  endif
27.else
28EC2_SVNBRANCH=	unknown
29EC2_SVNREV=	unknown
30.endif
31
32.if ${BRANCH} == "CURRENT" || ${BRANCH} == "STABLE" || ${BRANCH} == "PRERELEASE"
33AMINAMESUFFIX!=	date +-%Y-%m-%d
34.endif
35.if defined(EC2PUBLIC) && !empty(EC2PUBLIC)
36PUBLISH=	--public
37.endif
38.if defined(EC2PUBLICSNAP) && !empty(EC2PUBLICSNAP)
39PUBLICSNAP=	--publicsnap
40.endif
41.if defined(EC2SNSTOPIC) && !empty(EC2SNSTOPIC)
42EC2SNSREL=	${REVISION}-${BRANCH}
43EC2SNSVERS=	${EC2_SVNBRANCH}@${EC2_SVNREV}
44.endif
45
46CLEANFILES+=		ec2ami
47
48.if !exists(/usr/local/bin/bsdec2-image-upload)
49CW_EC2_PORTINSTALL=	cw-ec2-portinstall
50CLEANFILES+=		${CW_EC2_PORTINSTALL}
51.else
52CW_EC2_PORTINSTALL=
53.endif
54
55cw-ec2-portinstall:
56.if exists(${PORTSDIR}/net/bsdec2-image-upload/Makefile)
57	env - PATH=$$PATH make -C ${PORTSDIR}/net/bsdec2-image-upload BATCH=1 all install clean
58.else
59. if !exists(/usr/local/sbin/pkg-static)
60	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
61. endif
62	env ASSUME_ALWAYS_YES=yes pkg install -y net/bsdec2-image-upload
63.endif
64	@touch ${.TARGET}
65
66ec2ami: cw-ec2 ${CW_EC2_PORTINSTALL}
67.if !defined(AWSKEYFILE) || !exists(${AWSKEYFILE})
68	@echo "--------------------------------------------------------------"
69	@echo ">>> AWSKEYFILE must point at AWS keys for EC2 AMI creation"
70	@echo "--------------------------------------------------------------"
71	@false
72.endif
73.if !defined(AWSREGION)
74	@echo "--------------------------------------------------------------"
75	@echo ">>> AWSREGION must be specified EC2 AMI creation"
76	@echo "--------------------------------------------------------------"
77	@false
78.endif
79.if !defined(AWSBUCKET)
80	@echo "--------------------------------------------------------------"
81	@echo ">>> AWSBUCKET must be specified for EC2 AMI creation"
82	@echo "--------------------------------------------------------------"
83	@false
84.endif
85	/usr/local/bin/bsdec2-image-upload ${PUBLISH} ${PUBLICSNAP} --sriov --ena \
86	    ${.OBJDIR}/ec2.raw \
87	    "${TYPE} ${REVISION}-${BRANCH}-${TARGET}${AMINAMESUFFIX}" \
88	    "${TYPE}/${TARGET} ${EC2_SVNBRANCH}@${EC2_SVNREV}" \
89	    ${AWSREGION} ${AWSBUCKET} ${AWSKEYFILE} \
90	    ${EC2SNSTOPIC} ${EC2SNSREL} ${EC2SNSVERS}
91	@touch ${.TARGET}
92