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 \ 61 BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \ 62 all install clean 63. endif 64.endif 65 66.for PROVIDER in ${VAGRANT_PROVIDERS} 67CLEANFILES+= vagrant-do-package-${PROVIDER} ${VAGRANT_TARGET}.${PROVIDER}.box 68CLEANDIRS+= ${PROVIDER} 69VAGRANT_UPLOAD_TGTS+= vagrant-do-upload-${PROVIDER} 70 71${PROVIDER}: 72 @mkdir -p ${PROVIDER} 73 74${VAGRANT_TARGET}.${PROVIDER}.box: ${PROVIDER} cw-vagrant-${PROVIDER} vagrant-create-${PROVIDER}-metadata 75 @echo "==> PACKAGING: ${VAGRANT_TARGET}.${PROVIDER}.box in `pwd`" 76 @cp vagrant-${PROVIDER}.vmdk ${PROVIDER}/vagrant.vmdk 77. if ${PROVIDER} == "virtualbox" 78 @(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}"}' > metadata.json) 79 @(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json box.ovf vagrant.vmdk) 80. elif ${PROVIDER} == "vmware" 81 @(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}_desktop"}' > metadata.json) 82 @(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json vagrant.vmx vagrant.vmdk) 83. endif 84 85CLEANFILES+= vagrant-do-upload-${PROVIDER} 86vagrant-do-upload-${PROVIDER}: vagrant-box 87. if ${PROVIDER} == "virtualbox" 88 ${.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} 89. elif ${PROVIDER} == "vmware" 90 ${.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} 91. endif 92 touch ${.OBJDIR}/${.TARGET} 93 94vagrant-box: ${VAGRANT_TARGET}.${PROVIDER}.box 95 96.endfor 97 98vagrant-upload: ${VAGRANT_UPLOAD_TGTS} 99 100vagrant-create-virtualbox-metadata: virtualbox/box.ovf 101 102virtualbox/box.ovf: ${.CURDIR}/scripts/box.ovf 103 cp ${.ALLSRC} virtualbox/ 104 105vmware/vagrant.vmx: ${.CURDIR}/scripts/vagrant.vmx 106 cp ${.ALLSRC} vmware/ 107 108vagrant-create-vmware-metadata: vmware/vagrant.vmx 109