141f7db3aSBrad Davis# 241f7db3aSBrad Davis# 3accb19a8SBrad Davis# Makefile for producing and uploading Vagrant boxes to Hashicorp Atlas 441f7db3aSBrad Davis# 5accb19a8SBrad Davis# Usage Example: 6accb19a8SBrad Davis# Create a Vagrant image for VirtualBox: 7accb19a8SBrad Davis# make vagrant-box WITH_VMIMAGES=y WITH_CLOUDWARE=y \ 8accb19a8SBrad Davis# CLOUDWARE=vagrant-virtualbox VMFORMATS=vmdk 9accb19a8SBrad Davis# 10accb19a8SBrad Davis# To create a Vagrant image for VMWare and Upload it to Atlas: 11accb19a8SBrad Davis# VAGRANT_KEY is your Atlas API Token 12accb19a8SBrad Davis# VAGRANT_USERNAME is your Atlas Username 13accb19a8SBrad Davis# env VAGRANT_KEY=foo VAGRANT_USERNAME=bar make vagrant-upload \ 14accb19a8SBrad Davis# WITH_VMIMAGES=y WITH_CLOUDWARE=y CLOUDWARE=vagrant-vmware \ 15accb19a8SBrad Davis# VMFORMATS=vmdk 16accb19a8SBrad Davis# For more info: https://www.vagrantup.com/docs/other/atlas.html 1741f7db3aSBrad Davis# 1841f7db3aSBrad Davis 19bf97d722SGlen BarberVAGRANT_IMG?= ${.OBJDIR}/vagrant.vmdk 20a54bd595SBrad DavisVAGRANT_UPLOAD_TGTS= vagrant-check-depends 2141f7db3aSBrad DavisCLEANFILES+= ${VAGRANT_UPLOAD_TGTS} 2241f7db3aSBrad Davis 2341f7db3aSBrad Davis.if defined(VAGRANT_UPLOAD_CONF) && !empty(VAGRANT_UPLOAD_CONF) 24811fc8fdSGlen Barber. for VAR in _KEY _USERNAME 2541f7db3aSBrad DavisVAGRANT${VAR}!= grep -E ^VAGRANT${VAR} ${VAGRANT_UPLOAD_CONF} | awk -F' ' '{print $$2}' 2602158ab0SGlen BarberATLAS${VAR}:= ${VAGRANT${VAR}} 2741f7db3aSBrad Davis. endfor 2841f7db3aSBrad Davis.endif 2941f7db3aSBrad Davis 3041f7db3aSBrad Davis.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE" 310a459a71SGlen BarberSNAPSHOT_DATE!= date +-${BUILDDATE} 3241f7db3aSBrad Davis.endif 3341f7db3aSBrad Davis 34a54bd595SBrad DavisVAGRANT_VERSION!= date +%Y.%m.%d 35104dac63SGlen BarberVAGRANT_TARGET:= ${OSRELEASE}${SNAPSHOT_DATE} 36a54bd595SBrad Davis.if !empty(CLOUDWARE) 37a54bd595SBrad Davis. for _PROVIDER in ${CLOUDWARE} 38ef7a4820SBrad Davis. if ${_PROVIDER:tu:MVAGRANT*} 39ef7a4820SBrad DavisVAGRANT_PROVIDERS+= ${_PROVIDER:tu:S/VAGRANT-//:tl} 40a54bd595SBrad Davis. endif 41a54bd595SBrad Davis. endfor 42a54bd595SBrad Davis.endif 43a54bd595SBrad DavisVAGRANT_PROVIDERS?= vmware virtualbox 44811fc8fdSGlen Barber 4541f7db3aSBrad Davis 4641f7db3aSBrad Davisvagrant-check-depends: 47f19a742fSBrad Davis.for VAR in _KEY _USERNAME _VERSION 4841f7db3aSBrad Davis. if !defined(VAGRANT${VAR}) || empty(VAGRANT${VAR}) 4941f7db3aSBrad Davis @echo "Variable VAGRANT${VAR} cannot be empty." 5041f7db3aSBrad Davis @false 5141f7db3aSBrad Davis. endif 5241f7db3aSBrad Davis.endfor 5341f7db3aSBrad Davis.if !exists(/usr/local/bin/curl) 5441f7db3aSBrad Davis. if !exists(${PORTSDIR}/ftp/curl/Makefile) 5541f7db3aSBrad Davis. if !exists(/usr/local/sbin/pkg-static) 5641f7db3aSBrad Davis env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf 5741f7db3aSBrad Davis. endif 58f19a742fSBrad Davis env ASSUME_ALWAYS_YES=yes pkg install -y curl 5941f7db3aSBrad Davis. else 60*6c87aed3SColin Percival env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/ftp/curl \ 61*6c87aed3SColin Percival BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \ 62*6c87aed3SColin Percival all install clean 6341f7db3aSBrad Davis. endif 6441f7db3aSBrad Davis.endif 6541f7db3aSBrad Davis 668c4b4cc3SGlen Barber.for PROVIDER in ${VAGRANT_PROVIDERS} 67a54bd595SBrad DavisCLEANFILES+= vagrant-do-package-${PROVIDER} ${VAGRANT_TARGET}.${PROVIDER}.box 68a54bd595SBrad DavisCLEANDIRS+= ${PROVIDER} 69a54bd595SBrad DavisVAGRANT_UPLOAD_TGTS+= vagrant-do-upload-${PROVIDER} 7041f7db3aSBrad Davis 71a54bd595SBrad Davis${PROVIDER}: 72a54bd595SBrad Davis @mkdir -p ${PROVIDER} 73a54bd595SBrad Davis 74a54bd595SBrad Davis${VAGRANT_TARGET}.${PROVIDER}.box: ${PROVIDER} cw-vagrant-${PROVIDER} vagrant-create-${PROVIDER}-metadata 75a54bd595SBrad Davis @echo "==> PACKAGING: ${VAGRANT_TARGET}.${PROVIDER}.box in `pwd`" 76a54bd595SBrad Davis @cp vagrant-${PROVIDER}.vmdk ${PROVIDER}/vagrant.vmdk 77a54bd595SBrad Davis. if ${PROVIDER} == "virtualbox" 78a54bd595SBrad Davis @(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}"}' > metadata.json) 79a54bd595SBrad Davis @(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json box.ovf vagrant.vmdk) 80a54bd595SBrad Davis. elif ${PROVIDER} == "vmware" 81a54bd595SBrad Davis @(cd ${.OBJDIR}/${PROVIDER} && echo '{"provider":"${PROVIDER}_desktop"}' > metadata.json) 82a54bd595SBrad Davis @(cd ${.OBJDIR}/${PROVIDER} && tar -czf ../${VAGRANT_TARGET}.${PROVIDER}.box metadata.json vagrant.vmx vagrant.vmdk) 83a54bd595SBrad Davis. endif 84a54bd595SBrad Davis 85a54bd595SBrad DavisCLEANFILES+= vagrant-do-upload-${PROVIDER} 86ef7a4820SBrad Davisvagrant-do-upload-${PROVIDER}: vagrant-box 87a54bd595SBrad Davis. if ${PROVIDER} == "virtualbox" 88a54bd595SBrad Davis ${.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} 89a54bd595SBrad Davis. elif ${PROVIDER} == "vmware" 90a54bd595SBrad Davis ${.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} 91a54bd595SBrad Davis. endif 92a54bd595SBrad Davis touch ${.OBJDIR}/${.TARGET} 93ef7a4820SBrad Davis 94ef7a4820SBrad Davisvagrant-box: ${VAGRANT_TARGET}.${PROVIDER}.box 95ef7a4820SBrad Davis 96a54bd595SBrad Davis.endfor 97a54bd595SBrad Davis 98a54bd595SBrad Davisvagrant-upload: ${VAGRANT_UPLOAD_TGTS} 99a54bd595SBrad Davis 100a54bd595SBrad Davisvagrant-create-virtualbox-metadata: virtualbox/box.ovf 101a54bd595SBrad Davis 102a54bd595SBrad Davisvirtualbox/box.ovf: ${.CURDIR}/scripts/box.ovf 103a54bd595SBrad Davis cp ${.ALLSRC} virtualbox/ 104a54bd595SBrad Davis 10581c6dfbfSBrad Davisvmware/vagrant.vmx: ${.CURDIR}/scripts/vagrant.vmx 10681c6dfbfSBrad Davis cp ${.ALLSRC} vmware/ 107a54bd595SBrad Davis 108a54bd595SBrad Davisvagrant-create-vmware-metadata: vmware/vagrant.vmx 109