diff --git a/Vagrantfile b/Vagrantfile index ab397d0a3e..453431403c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,6 +1,70 @@ # -*- mode: ruby -*- # vi: set ft=ruby : +module OS + def OS.windows? + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + end + + def OS.mac? + (/darwin/ =~ RUBY_PLATFORM) != nil + end + + def OS.unix? + !OS.windows? + end + + def OS.linux? + OS.unix? and not OS.mac? + end +end + +ENV['VAGRANT_DEFAULT_PROVIDER'] ||= OS.mac? ? 'vmware_fusion' : "vmware_workstation" + +fusion_path="/Applications/VMware Fusion.app/Contents/Library" +if File.directory?(fusion_path) + ENV['PATH'] = "#{fusion_path}:#{ENV['PATH']}" +end + +appcatalyst_path="/opt/vmware/appcatalyst/libexec" +if File.directory?(appcatalyst_path) + ENV['PATH'] = "#{appcatalyst_path}:#{ENV['PATH']}" +end + +# Hey Now! thanks StackOverflow: http://stackoverflow.com/a/28801317/1233435 +req_plugins = %w(vagrant-triggers) + +if OS.mac? + req_plugins << "vagrant-vmware-fusion" if File.directory?(fusion_path) + req_plugins << "vagrant-vmware-appcatalyst" if File.directory?(appcatalyst_path) +else + req_plugins << "vagrant-vmware-workstation" +end + +# Cycle through the required plugins and install what's missing. +plugins_install = req_plugins.select { |plugin| !Vagrant.has_plugin? plugin } +licensed_plugins = plugins_install.select { |plugin| plugin =~ /vagrant-vmware-(?:fusion|workstation)$/ } +licensed_plugins.each do |plugin| + unless File.exist? "#{ENV["VAGRANT_VMWARE_LICENSE_FILE"]||"./#{plugin}.lic"}" + abort "Failed to configure license, you can configure the path with VAGRANT_VMWARE_LICENSE_FILE" + end +end + +unless plugins_install.empty? + puts "Installing plugins: #{plugins_install.join(' ')}" + if system "vagrant plugin install #{plugins_install.join(' ')}" + exec "vagrant #{ARGV.join(' ')}" + else + abort 'Installation of one or more plugins has failed. Aborting.' + end +end + +licensed_plugins.each do |plugin| + unless system "vagrant plugin license #{plugin} #{ENV["VAGRANT_VMWARE_LICENSE_FILE"]||"./#{plugin}.lic"}" + abort "Failed to configure license, you can configure the path with VAGRANT_VMWARE_LICENSE_FILE" + end +end + VAGRANTFILE_API_VERSION = '2' # VM configuration, as we're compiling an OS from scratch, make sure the @@ -14,14 +78,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box_check_update = false - config.vm.provider('vmware_fusion') do |v| - v.vmx['memsize'] = vm_config[:ram] - v.vmx['numvcpus'] = vm_config[:cpu] - end - - config.vm.provider('vmware_workstation') do |v| - v.vmx['memsize'] = vm_config[:ram] - v.vmx['numvcpus'] = vm_config[:cpu] + %w(vmware_fusion vmware_workstation vmware_appcatalyst).each do |p| + config.vm.provider p do |v| + v.vmx['memsize'] = vm_config[:ram] + v.vmx['numvcpus'] = vm_config[:cpu] + v.vmx['ethernet0.virtualDev'] = 'vmxnet3' + v.vmx['vhv.enable'] = 'true' + end end # Sync the current folder as /workspaces/photon using rsync. diff --git a/support/package-builder/Logger.py b/support/package-builder/Logger.py index dbab413d1a..f70151cc38 100644 --- a/support/package-builder/Logger.py +++ b/support/package-builder/Logger.py @@ -19,23 +19,19 @@ def getLogger (mymodule, logpath=None): # add formatter to handler fhandler.setFormatter(formatter) ch.setFormatter(formatter) - + logger.addHandler(ch) logger.addHandler(fhandler) logger.setLevel(logging.DEBUG) logger.info("--------------------------------------------------------------------------") - logger.info("Staring Log") + logger.info("Starting Log") logger.info("--------------------------------------------------------------------------") return logger - + if __name__ == "__main__": #Logger.getLogger("my module") t1 = Logger.getLogger("my module") t1.info("test1") - t2 = Logger.getLogger("my module") + t2 = Logger.getLogger("my module") t2.info("test2") t1.info("test3") - - - - diff --git a/support/packer-templates/photon-build-machine.json b/support/packer-templates/photon-build-machine.json index d9cd7535ec..563655aea3 100644 --- a/support/packer-templates/photon-build-machine.json +++ b/support/packer-templates/photon-build-machine.json @@ -1,67 +1,62 @@ { - "builders": [ - { - "name": "photon-build-machine", - "vm_name": "photon-build-machine", - "vmdk_name": "photon-build-machine-disk0", - "type": "vmware-iso", - "headless": true, - "disk_size": 40960, - "disk_type_id": 0, - "guest_os_type": "ubuntu-64", - "iso_url": "http://ubuntu.bhs.mirrors.ovh.net/ftp.ubuntu.com/releases/trusty/ubuntu-14.04.2-server-amd64.iso", - "iso_checksum": "3bfa6eac84d527380d0cc52db9092cde127f161e", - "iso_checksum_type": "sha1", - "ssh_username": "vagrant", - "ssh_password": "vagrant", - "ssh_wait_timeout": "60m", - "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", - "http_directory": ".", - "tools_upload_flavor": "linux", - "boot_command": [ - "", - "/install/vmlinuz noapic ", - "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/scripts/ubuntu-preseed.cfg ", - "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", - "hostname=photon-build-machine ", - "fb=false debconf/frontend=noninteractive ", - "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", - "keyboard-configuration/variant=USA console-setup/ask_detect=false ", - "initrd=/install/initrd.gz -- " - ] - } - ], - "provisioners": [ - { - "type": "shell", - "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", - "script": "scripts/ubuntu-vmware-tools_install.sh" - }, - { - "type": "shell", - "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", - "script": "scripts/ubuntu-puppet_install.sh" - }, - { - "type": "puppet-masterless", - "execute_command": "{{.FacterVars}}{{if .Sudo}} echo 'vagrant' | sudo -E -S {{end}} puppet apply --verbose --modulepath='{{.ModulePath}}' {{if ne .HieraConfigPath \"\"}}--hiera_config='{{.HieraConfigPath}}' {{end}} {{if ne .ManifestDir \"\"}}--manifestdir='{{.ManifestDir}}' {{end}} --detailed-exitcodes {{.ManifestFile}}", - "manifest_file": "puppet/manifests/vagrant.pp", - "manifest_dir": "puppet/manifests", - "module_paths": [ - "puppet/modules" - ] - }, - { - "type": "shell", - "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", - "script": "scripts/ubuntu-vmware-final_cleanup.sh" - } - ], - "post-processors": [ - { - "type": "vagrant", - "compression_level": 9, - "output": "{{.BuildName}}.box" - } - ] + "builders": [{ + "name": "photon-build-machine", + "vm_name": "photon-build-machine", + "vmdk_name": "photon-build-machine-disk0", + "type": "vmware-iso", + "headless": true, + "disk_size": 40960, + "disk_type_id": 0, + "guest_os_type": "ubuntu-64", + "iso_url": "http://ubuntu.bhs.mirrors.ovh.net/ftp.ubuntu.com/releases/trusty/ubuntu-14.04.3-server-amd64.iso", + "iso_checksum": "0501c446929f713eb162ae2088d8dc8b6426224a", + "iso_checksum_type": "sha1", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_wait_timeout": "60m", + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "http_directory": ".", + "tools_upload_flavor": "linux", + "boot_command": [ + "", + "/install/vmlinuz noapic ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/scripts/ubuntu-preseed.cfg ", + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", + "hostname=photon-build-machine ", + "fb=false debconf/frontend=noninteractive ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", + "keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd=/install/initrd.gz -- " + ] + }], + "provisioners": [{ + "type": "shell", + "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", + "script": "scripts/ubuntu-vmware-tools_install.sh" + }, { + "type": "shell", + "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", + "script": "scripts/ubuntu-puppet_install.sh" + }, { + "type": "puppet-masterless", + "execute_command": "{{.FacterVars}}{{if .Sudo}} echo 'vagrant' | sudo -E -S {{end}} puppet apply --verbose --modulepath='{{.ModulePath}}' {{if ne .HieraConfigPath \"\"}}--hiera_config='{{.HieraConfigPath}}' {{end}} {{if ne .ManifestDir \"\"}}--manifestdir='{{.ManifestDir}}' {{end}} --detailed-exitcodes {{.ManifestFile}}", + "manifest_file": "puppet/manifests/vagrant.pp", + "manifest_dir": "puppet/manifests", + "module_paths": [ + "puppet/modules" + ] + }, { + "type": "shell", + "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", + "script": "scripts/ubuntu-install-docker.sh" + }, { + "type": "shell", + "execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", + "script": "scripts/ubuntu-vmware-final_cleanup.sh" + }], + "post-processors": [{ + "type": "vagrant", + "compression_level": 9, + "output": "{{.BuildName}}.box" + }] } diff --git a/support/packer-templates/puppet/modules/photonbuildsetup/manifests/init.pp b/support/packer-templates/puppet/modules/photonbuildsetup/manifests/init.pp index 709ac48156..956d0c212b 100644 --- a/support/packer-templates/puppet/modules/photonbuildsetup/manifests/init.pp +++ b/support/packer-templates/puppet/modules/photonbuildsetup/manifests/init.pp @@ -19,7 +19,6 @@ 'cifs-utils', 'createrepo', 'rpm', - 'git', 'htop', 'python-aptdaemon', 'gdisk', diff --git a/support/packer-templates/scripts/ubuntu-install-docker.sh b/support/packer-templates/scripts/ubuntu-install-docker.sh new file mode 100644 index 0000000000..a962d1fc58 --- /dev/null +++ b/support/packer-templates/scripts/ubuntu-install-docker.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "==> Setting up docker from apt.dockerproject.org" +sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D +echo 'deb https://apt.dockerproject.org/repo ubuntu-trusty main' | sudo tee /etc/apt/sources.list.d/docker.list +sudo apt-get update +sudo apt-get install -y docker-engine diff --git a/support/packer-templates/scripts/ubuntu-preseed.cfg b/support/packer-templates/scripts/ubuntu-preseed.cfg index 499291f6d8..8984937fe1 100644 --- a/support/packer-templates/scripts/ubuntu-preseed.cfg +++ b/support/packer-templates/scripts/ubuntu-preseed.cfg @@ -93,7 +93,7 @@ d-i pkgsel/install-language-support boolean false # manage the VM, build tools and the kernel headers to compile VMware Tools # addons -d-i pkgsel/include string openssh-server build-essential linux-kernel-headers bc +d-i pkgsel/include string openssh-server build-essential linux-kernel-headers bc git-core unzip # Boot loader installation # ------------------------ @@ -109,4 +109,4 @@ d-i grub-installer/only_debian boolean true # Ubuntu show a final message once the installation is complete. This message is # affirmed so it doesn't block the installation process. -d-i finish-install/reboot_in_progress note \ No newline at end of file +d-i finish-install/reboot_in_progress note diff --git a/support/packer-templates/scripts/ubuntu-vmware-tools_install.sh b/support/packer-templates/scripts/ubuntu-vmware-tools_install.sh index c4a663067a..7b363a518c 100644 --- a/support/packer-templates/scripts/ubuntu-vmware-tools_install.sh +++ b/support/packer-templates/scripts/ubuntu-vmware-tools_install.sh @@ -1,12 +1,10 @@ #!/bin/bash - -sudo mount -o loop ~/linux.iso /media/cdrom -sudo cp /media/cdrom/VMwareTools*.tar.gz ~/ -tar xfz VMwareTools*.tar.gz -cd ~/vmware-tools-distrib -sudo ./vmware-install.pl -d -sudo umount /media/cdrom -cd ~ -rm -rf vmware-tools-distrib -rm -f VMwareTools*.tar.gz -rm linux.iso \ No newline at end of file + +git clone https://github.com/rasa/vmware-tools-patches.git +cd vmware-tools-patches +sudo ./download-tools.sh 8.0.2 +sudo ./untar-and-patch.sh +cd vmware-tools-distrib +sudo ./vmware-install.pl -f -d --clobber-kernel-modules=pvscsi,vmblock,vmci,vmhgfs,vmmemctl,vmsync,vmxnet,vmxnet3,vsock +cd "$HOME" +rm -rf vmware-tools-patches diff --git a/support/vagrant/photon-build-machine-init.sh b/support/vagrant/photon-build-machine-init.sh index 53a9106968..82c5cea5af 100644 --- a/support/vagrant/photon-build-machine-init.sh +++ b/support/vagrant/photon-build-machine-init.sh @@ -37,4 +37,4 @@ fi echo "Cleanup the build..." sudo make clean echo "Shutting down the photon build machine..." -sudo shutdown -h now +# sudo shutdown -h now