xref: /freebsd/release/Makefile.vagrant (revision 4543ef516683042d46f3bd3bb8a4f3f746e00499)
1#
2#
3# Makefile for producing and uploading Vagrant boxes to Hashicorp Atlas
4#
5# Usage Example:
6#   Create a Vagrant image for VirtualBox:
7#     make vagrant-box WITH_VMIMAGES=y WITH_CLOUDWARE=y \
8#       CLOUDWARE=vagrant-virtualbox VMFORMATS=vmdk
9#
10#   To create a Vagrant image for VMWare and Upload it to Atlas:
11#     VAGRANT_KEY is your Atlas API Token
12#     VAGRANT_USERNAME is your Atlas Username
13#     env VAGRANT_KEY=foo VAGRANT_USERNAME=bar make vagrant-upload \
14#       WITH_VMIMAGES=y WITH_CLOUDWARE=y CLOUDWARE=vagrant-vmware \
15#       VMFORMATS=vmdk
16#     For more info: https://www.vagrantup.com/docs/other/atlas.html
17#
18
19VAGRANT_IMG?=		${.OBJDIR}/vagrant.vmdk
20VAGRANT_UPLOAD_TGTS=	vagrant-check-depends
21CLEANFILES+=		${VAGRANT_UPLOAD_TGTS}
22
23.if defined(VAGRANT_UPLOAD_CONF) && !empty(VAGRANT_UPLOAD_CONF)
24. for VAR in _KEY _USERNAME
25VAGRANT${VAR}!=		grep -E ^VAGRANT${VAR} ${VAGRANT_UPLOAD_CONF} | awk -F'	' '{print $$2}'
26ATLAS${VAR}:=		${VAGRANT${VAR}}
27. endfor
28.endif
29
30.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE"
31SNAPSHOT_DATE!=		date +-${BUILDDATE}
32.endif
33
34VAGRANT_VERSION!=	date +%Y.%m.%d
35VAGRANT_TARGET:=	${OSRELEASE}${SNAPSHOT_DATE}
36.if !empty(CLOUDWARE)
37. for _PROVIDER in ${CLOUDWARE}
38.  if ${_PROVIDER:tu:MVAGRANT*}
39VAGRANT_PROVIDERS+=	${_PROVIDER:tu:S/VAGRANT-//:tl}
40.  endif
41. endfor
42.endif
43VAGRANT_PROVIDERS?=	vmware virtualbox
44
45
46vagrant-check-depends:
47.for VAR in _KEY _USERNAME _VERSION
48. if !defined(VAGRANT${VAR}) || empty(VAGRANT${VAR})
49	@echo "Variable VAGRANT${VAR} cannot be empty."
50	@false
51. endif
52.endfor
53.if !exists(/usr/local/bin/curl)
54. if !exists(${PORTSDIR}/ftp/curl/Makefile)
55.  if !exists(/usr/local/sbin/pkg-static)
56	env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf
57.  endif
58	env ASSUME_ALWAYS_YES=yes pkg install -y curl
59. else
60	env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/ftp/curl BATCH=1 all install clean
61. endif
62.endif
63
64.for PROVIDER in ${VAGRANT_PROVIDERS}
65CLEANFILES+=	vagrant-do-package-${PROVIDER} ${VAGRANT_TARGET}.${PROVIDER}.box
66CLEANDIRS+=	${PROVIDER}
67VAGRANT_UPLOAD_TGTS+=	vagrant-do-upload-${PROVIDER}
68
69${PROVIDER}:
70	@mkdir -p ${PROVIDER}
71
72${VAGRANT_TARGET}.${PROVIDER}.box: ${PROVIDER} cw-vagrant-${PROVIDER} vagrant-create-${PROVIDER}-metadata
73	@echo "==> PACKAGING: ${VAGRANT_TARGET}.${PROVIDER}.box in `pwd`"
74	@cp vagrant-${PROVIDER}.vmdk ${PROVIDER}/vagrant.vmdk
75. if ${PROVIDER} == "virtualbox"
76	@(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}"}' > metadata.json)
77	@(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json box.ovf vagrant.vmdk)
78. elif ${PROVIDER} == "vmware"
79	@(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}_desktop"}' > metadata.json)
80	@(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json vagrant.vmx vagrant.vmdk)
81. endif
82
83CLEANFILES+=	vagrant-do-upload-${PROVIDER}
84vagrant-do-upload-${PROVIDER}: vagrant-box
85. if ${PROVIDER} == "virtualbox"
86	${.CURDIR}/scripts/atlas-upload.sh -b ${TYPE}-${REVISION}-${BRANCH} -f ${VAGRANT_TARGET}.${PROVIDER}.box -p ${PROVIDER} -k ${VAGRANT_KEY} -u ${VAGRANT_USERNAME} -v ${VAGRANT_VERSION}
87. elif ${PROVIDER} == "vmware"
88	${.CURDIR}/scripts/atlas-upload.sh -b ${TYPE}-${REVISION}-${BRANCH} -f ${VAGRANT_TARGET}.${PROVIDER}.box -p ${PROVIDER}_desktop -k ${VAGRANT_KEY} -u ${VAGRANT_USERNAME} -v ${VAGRANT_VERSION}
89. endif
90	touch ${.OBJDIR}/${.TARGET}
91
92vagrant-box: ${VAGRANT_TARGET}.${PROVIDER}.box
93
94.endfor
95
96vagrant-upload:	${VAGRANT_UPLOAD_TGTS}
97
98vagrant-create-virtualbox-metadata: virtualbox/box.ovf
99
100virtualbox/box.ovf: ${.CURDIR}/scripts/box.ovf
101	cp ${.ALLSRC} virtualbox/
102
103vmware/vagrant.vmx: ${.CURDIR}/scripts/vagrant.vmx
104	cp ${.ALLSRC} vmware/
105
106vagrant-create-vmware-metadata: vmware/vagrant.vmx
107