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