Author: brd (doc,ports committer) Date: Sat Jun 27 20:39:13 2015 New Revision: 284893 URL: https://svnweb.freebsd.org/changeset/base/284893
Log: Add initial support for building Vagrant images for VMWare. Next steps will be adding Virtualbox support and uploading to Hashicorp Atlas for others to consume. Approved by: re (gjb) Added: head/release/Makefile.vagrant (contents, props changed) head/release/tools/vagrant.conf (contents, props changed) Modified: head/release/Makefile.vm Added: head/release/Makefile.vagrant ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/release/Makefile.vagrant Sat Jun 27 20:39:13 2015 (r284893) @@ -0,0 +1,94 @@ +# +# $FreeBSD$ +# +# +# Makefile for uploading Vagrant boxes to Hashicorp Atlas +# + +VAGRANT_UPLOAD_TGTS= vagrant-check-depends \ + vagrant-do-package-vmware +# atlas-do-upload +CLEANFILES+= ${VAGRANT_UPLOAD_TGTS} + +.if defined(VAGRANT_UPLOAD_CONF) && !empty(VAGRANT_UPLOAD_CONF) +. for VAR in _ACCOUNT _KEY +VAGRANT${VAR}!= grep -E ^VAGRANT${VAR} ${VAGRANT_UPLOAD_CONF} | awk -F' ' '{print $$2}' +. endfor +.endif + +.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE" +SNAPSHOT_DATE!= date +-%Y-%m-%d-%H-%M +.endif + +VAGRANT_TARGET:= ${OSRELEASE}${SNAPSHOT_DATE}.box + +vagrant-upload: ${VAGRANT_UPLOAD_TGTS} + +vagrant-check-depends: +.for VAR in _ACCOUNT _KEY +. if !defined(VAGRANT${VAR}) || empty(VAGRANT${VAR}) + @echo "Variable VAGRANT${VAR} cannot be empty." + @false +. endif +.endfor +.if !exists(/usr/local/bin/curl) +. if !exists(${PORTSDIR}/ftp/curl/Makefile) +. if !exists(/usr/local/sbin/pkg-static) + env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf +. endif + env ASSUME_ALWAYS_YES=yes pkg install -y ftp/curl +. else + make -C ${PORTSDIR}/ftp/curl BATCH=1 all install clean +. endif +.endif + +vagrant-do-package: cw-vagrant + +vagrant-do-package-vmware: vagrant-create-vmware-vmx vagrant-do-package + @cd ${.OBJDIR} && echo '{"provider":"vmware_desktop"}' > metadata.json + cd ${.OBJDIR} && tar -czf ${VAGRANT_TARGET} metadata.json vagrant.vmx vagrant.vmdk + touch ${.OBJDIR}/${.TARGET} + +atlas-create-upload: +.for PROVIDER in vmware_desktop virtualbox + /usr/local/bin/curl "https://vagrant.hashicorp.com/api/v1/box/${ATLAS_USERNAME}/${ATLAS_NAME}/version/${ATLAS_VERSION}/provider/${PROVIDER}/upload?access_token=${ATLAS_KEY}" +.endfor + touch ${.OBJDIR}/${.TARGET} + +atlas-do-upload: + /usr/local/bin/curl -X PUT --upload-file \ + ${VAGRANT_IMG} ${ATLAS_UPLOAD_PATH} + touch ${.OBJDIR}/${.TARGET} + +vagrant-create-vmware-vmx: + @cd ${.OBJDIR} && echo '.encoding = "UTF-8"' > vagrant.vmx + @cd ${.OBJDIR} && echo 'bios.bootorder = "hdd,CDROM"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'checkpoint.vmstate = ""' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'cleanshutdown = "TRUE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'config.version = "8"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'displayname = "${VAGRANT_TARGET}"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.addresstype = "generated"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.bsdname = "en0"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.connectiontype = "nat"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.displayname = "Ethernet"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.linkstatepropagation.enable = "FALSE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.pcislotnumber = "33"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.present = "TRUE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.virtualdev = "e1000"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'ethernet0.wakeonpcktrcv = "FALSE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'floppy0.present = "FALSE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'guestos = "freebsd-64"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'gui.fullscreenatpoweron = "FALSE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'gui.viewmodeatpoweron = "windowed"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'memsize = "512"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'sound.startconnected = "FALSE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'softpoweroff = "TRUE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'scsi0.pcislotnumber = "16"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'scsi0.present = "TRUE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'scsi0.virtualdev = "lsilogic"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'scsi0:0.filename = "vagrant.vmdk"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'scsi0:0.present = "TRUE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'tools.synctime = "TRUE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'usb.present = "FALSE"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'virtualhw.productcompatibility = "hosted"' >> vagrant.vmx + @cd ${.OBJDIR} && echo 'virtualhw.version = "9"' >> vagrant.vmx Modified: head/release/Makefile.vm ============================================================================== --- head/release/Makefile.vm Sat Jun 27 18:24:23 2015 (r284892) +++ head/release/Makefile.vm Sat Jun 27 20:39:13 2015 (r284893) @@ -18,7 +18,8 @@ RAW_DESC= Unformatted raw disk image CLOUDWARE?= AZURE \ EC2 \ GCE \ - OPENSTACK + OPENSTACK \ + VAGRANT AZURE_FORMAT= vhdf AZURE_DESC= Microsoft Azure platform image AZURE_DISK= ${OSRELEASE}.${AZURE_FORMAT} @@ -31,6 +32,9 @@ GCE_DISK= disk.${GCE_FORMAT} OPENSTACK_FORMAT=qcow2 OPENSTACK_DESC= OpenStack platform image OPENSTACK_DISK= ${OSRELEASE}.${OPENSTACK_FORMAT} +VAGRANT_FORMAT= vmdk +VAGRANT_DESC= Vagrant Image +VAGRANT_DISK= ${OSRELEASE}.${VAGRANT_FORMAT} .if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) . for _CW in ${CLOUDWARE} @@ -156,3 +160,4 @@ cloudware-install: .include "${.CURDIR}/Makefile.ec2" .include "${.CURDIR}/Makefile.azure" .include "${.CURDIR}/Makefile.gce" +.include "${.CURDIR}/Makefile.vagrant" Added: head/release/tools/vagrant.conf ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/release/tools/vagrant.conf Sat Jun 27 20:39:13 2015 (r284893) @@ -0,0 +1,81 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# Packages to install into the image we're creating. This is a deliberately +# minimalist set, providing only the packages necessary to bootstrap. +export VM_EXTRA_PACKAGES="firstboot-freebsd-update firstboot-pkgs" + +# Set to a list of third-party software to enable in rc.conf(5). +export VM_RC_LIST="firstboot_freebsd_update firstboot_pkgs" + +vm_extra_pre_umount() { + # The firstboot_pkgs rc.d script will download the repository + # catalogue and install or update pkg when the instance first + # launches, so these files would just be replaced anyway; removing + # them from the image allows it to boot faster. + env ASSUME_ALWAYS_YES=yes pkg -c ${DESTDIR} delete -f -y pkg + rm ${DESTDIR}/var/db/pkg/repo-*.sqlite + + # The size of the EC2 root disk can be configured at instance launch + # time; expand our filesystem to fill the disk. + echo 'growfs_enable="YES"' >> ${DESTDIR}/etc/rc.conf + + # Vagrant instances use DHCP to get their network configuration. + echo 'ifconfig_DEFAULT="SYNCDHCP"' >> ${DESTDIR}/etc/rc.conf + + # Enable sshd by default + echo 'sshd_enable="YES"' >> ${DESTDIR}/etc/rc.conf + # Disable DNS lookups by default to make SSH connect quickly + echo 'UseDNS no' >> ${DESTDIR}/etc/ssh/sshd_config + + # Disable sendmail + echo 'sendmail_enable="NO"' >> ${DESTDIR}/etc/rc.conf + echo 'sendmail_submit_enable="NO"' >> ${DESTDIR}/etc/rc.conf + echo 'sendmail_outbound_enable="NO"' >> ${DESTDIR}/etc/rc.conf + echo 'sendmail_msp_queue_enable="NO"' >> ${DESTDIR}/etc/rc.conf + + # sudo is required + echo 'firstboot_pkgs_list="sudo rsync"' >> ${DESTDIR}/etc/rc.conf + + # Create the vagrant user with a password of vagrant + /usr/sbin/pw -R ${DESTDIR} \ + groupadd vagrant -g 1001 + chroot ${DESTDIR} mkdir -p /home/vagrant + /usr/sbin/pw -R ${DESTDIR} \ + useradd vagrant \ + -m -M 0755 -w yes -n vagrant -u 1001 -g 1001 -G 0 \ + -c 'Vagrant User' -d '/home/vagrant' -s '/bin/csh' + + # Change root's password to vagrant + echo 'vagrant' | /usr/sbin/pw -R ${DESTDIR} \ + usermod root -h 0 + + # Configure sudo to allow the vagrant user + echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> ${DESTDIR}/usr/local/etc/sudoers + + # Configure the vagrant ssh key + mkdir ${DESTDIR}/home/vagrant/.ssh + chmod 700 ${DESTDIR}/home/vagrant/.ssh + echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > ${DESTDIR}/home/vagrant/.ssh/authorized_keys + chown -R 1001 ${DESTDIR}/home/vagrant/.ssh + chmod 600 ${DESTDIR}/home/vagrant/.ssh/authorized_keys + + # Reboot quickly, Don't wait at the panic screen + echo 'debug.trace_on_panic=1' >> ${DESTDIR}/etc/sysctl.conf + echo 'debug.debugger_on_panic=0' >> ${DESTDIR}/etc/sysctl.conf + echo 'kern.panic_reboot_wait_time=0' >> ${DESTDIR}/etc/sysctl.conf + + # The console is not interactive, so we might as well boot quickly. + echo 'autoboot_delay="-1"' >> ${DESTDIR}/boot/loader.conf + + # The first time the VM boots, the installed "first boot" scripts + # should be allowed to run: + # * growfs (expand the filesystem to fill the provided disk) + # * firstboot_freebsd_update (install critical updates) + # * firstboot_pkgs (install packages) + touch ${DESTDIR}/firstboot + + return 0 +} _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"