From e7811e5f48375ea27cf5d0f2b3df6f54f2b4e204 Mon Sep 17 00:00:00 2001 From: Ryan Parman Date: Mon, 11 Jul 2016 01:56:43 -0700 Subject: [PATCH] [WIP] Fixing Vagrant HGFS issues. --- README.md | 39 +++++++++++++++++++++++---- Vagrantfile | 55 ++++++++++++++++++++++++++++++++++++++ scripts/packages.sh | 2 ++ scripts/virtualbox.sh | 15 ----------- scripts/vmtools.sh | 62 +++++++++++++++++++++++++++++++++++++++++++ scripts/vmware.sh | 8 ------ template-docker.json | 25 +++++++++++++++++ template.json | 56 +++++++++++++++++--------------------- 8 files changed, 203 insertions(+), 59 deletions(-) create mode 100644 Vagrantfile delete mode 100644 scripts/virtualbox.sh create mode 100644 scripts/vmtools.sh delete mode 100644 scripts/vmware.sh create mode 100644 template-docker.json diff --git a/README.md b/README.md index 194712f..34a05e8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CentOS 7.2 Vagrant Boxes +# CentOS 7.2 Vagrant/Docker Boxes Building Vagrant images based on CentOS 7.2 (minimal install). All instructions were tested against OS X 10.11 “El Capitan”, VMware Fusion 8, VirtualBox 5, and Parallels Desktop 11. @@ -10,14 +10,23 @@ config.vm.box = "skyzyx/centos7" ## Prerequisites -* Knowledge of the command line. * [Packer](https://www.packer.io/downloads.html) 0.10.1 or newer. * [VirtualBox](https://www.virtualbox.org/wiki/Downloads), for building the VirtualBox Vagrant box. + * [vagrant-vbguest](https://github.com/dotless-de/vagrant-vbguest) plug-in to keep VirtualBox tools up-to-date. * [VMware Fusion](http://www.vmware.com/products/fusion), for building the VMware Vagrant box. - * [Vagrant Provider for VMware](https://www.vagrantup.com/vmware/) if you want VMware to work with Vagrant. + * [Vagrant Provider for VMware](https://www.vagrantup.com/vmware/) plug-in to enable Vagrant to use VMware as a provider. * [Parallels Desktop](http://www.parallels.com/products/desktop/download/), for building the Parallels Vagrant box. * [Parallels Virtualization SDK for Mac](http://www.parallels.com/download/pvsdk/) so that your Mac can talk to Parallels through Vagrant. -* Knowledge of Bash scripting and JSON if you want to fork this repo and make changes. + * [vagrant-parallels](http://parallels.github.io/vagrant-parallels/) plug-in to enable Vagrant to use Parallels as a provider. +* [vagrant-cachier](http://fgrehm.viewdocs.io/vagrant-cachier/) plug-in to enable caching of `yum` packages. + +## Updating your Plug-Ins + +This is simply a good thing to do from time to time. + +```bash +vagrant plugin update +``` ## Installing Packer @@ -36,7 +45,7 @@ You have two choices for installing Packer. 1. Otherwise, you can manually install it from . -## Building Boxes +## Building Vagrant Boxes ### Build everything @@ -60,3 +69,23 @@ packer build --only=virtualbox-iso template.json # Parallels packer build --only=parallels-iso template.json ``` + +## Building the Docker Image + +1. Boot-up a Vagrant VM. + + ```bash + vagrant up + ``` + +2. Log into the VM. + + ```bash + vagrant ssh + ``` + +3. Run Packer from inside the VM to build the Docker image. + + ```bash + packer build template-docker.json + ``` diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..55efccb --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,55 @@ +Vagrant.require_version ">= 1.8.0" + +environment_name = "Docker builder environment" +memsize = 2048 +numvcpus = 2 + +Vagrant.configure("2") do | config | + + # Box + config.vm.box = "skyzyx/centos7" + config.vm.boot_timeout = 120 + + # Check for vbguest plugin + if Vagrant.has_plugin?("vagrant-vbguest") + config.vbguest.auto_update = true + config.vbguest.no_remote = false + end + + # Synced folders + if Vagrant::Util::Platform.windows? + config.vm.synced_folder "", "/vagrant", type: "smb" + else + config.vm.synced_folder "", "/vagrant", type: "nfs" + end + + # Oracle VirtualBox + config.vm.provider :virtualbox do | vb | + vb.name = environment_name + vb.gui = false + + vb.memory = memsize + vb.cpus = numvcpus + vb.customize ["modifyvm", :id, "--ioapic", "on"] + end + + # VMware Fusion + config.vm.provider :vmware_fusion do | vm | + vm.name = environment_name + vm.gui = false + + vm.vmx["memsize"] = memsize + vm.vmx["numvcpus"] = numvcpus + end + + # Parallels Desktop + config.vm.provider :parallels do | prl | + prl.name = environment_name + prl.update_guest_tools = true + + prl.memory = memsize + prl.cpus = numvcpus + end + + config.vm.provision :shell, inline: "yum -y install docker-engine" +end diff --git a/scripts/packages.sh b/scripts/packages.sh index e154df2..575661a 100644 --- a/scripts/packages.sh +++ b/scripts/packages.sh @@ -49,6 +49,7 @@ yum -y install \ bind-utils \ bzip2 \ ca-certificates \ + cpp \ cronie \ cronie-anacron \ crontabs \ @@ -64,6 +65,7 @@ yum -y install \ iptables \ iputils \ kernel-devel-`uname -r` \ + kernel-headers-`uname -r` \ libcgroup \ libselinux-python \ make \ diff --git a/scripts/virtualbox.sh b/scripts/virtualbox.sh deleted file mode 100644 index 4c99e01..0000000 --- a/scripts/virtualbox.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env bash - -e() { - echo -e " \e[1;32m[install] ==> $@\e[0m"; -} - -e "Get the VirtualBox version" -VBOX_VERSION=$(cat /home/vagrant/.vbox_version) - -e "Install VBoxGuestAdditions" -cd /tmp -mount -o loop /home/vagrant/VBoxGuestAdditions_$VBOX_VERSION.iso /mnt -sh /mnt/VBoxLinuxAdditions.run -umount /mnt -rm -rf /home/vagrant/VBoxGuestAdditions_*.iso diff --git a/scripts/vmtools.sh b/scripts/vmtools.sh new file mode 100644 index 0000000..43e6039 --- /dev/null +++ b/scripts/vmtools.sh @@ -0,0 +1,62 @@ +#!/bin/sh -eux +# https://github.com/chef/bento/blob/master/scripts/common/vmtools.sh + +e() { + echo -e " \e[1;32m[install] ==> $@\e[0m"; +} + +e "Set a default HOME_DIR environment variable if not set" +HOME_DIR="${HOME_DIR:-/home/vagrant}"; + +case "$PACKER_BUILDER_TYPE" in + +virtualbox-iso|virtualbox-ovf) + VER="`cat /home/vagrant/.vbox_version`"; + e "Virtualbox Tools Version: $VER"; + + yum -y install kernel-devel-`uname -r` + + mkdir -p /tmp/vbox; + mount -o loop $HOME_DIR/VBoxGuestAdditions_${VER}.iso /tmp/vbox; + sh /tmp/vbox/VBoxLinuxAdditions.run \ + || echo "VBoxLinuxAdditions.run exited $? and is suppressed." \ + "For more read https://www.virtualbox.org/ticket/12479"; + umount /tmp/vbox; + rm -rf /tmp/vbox; + rm -f $HOME_DIR/*.iso; + ;; + +vmware-iso|vmware-vmx) + e "Use open-vm-tools" + yum -y install open-vm-tools + mkdir -p /mnt/hgfs; + ;; + +parallels-iso|parallels-pvm) + mkdir -p /tmp/parallels; + mount -o loop $HOME_DIR/prl-tools-lin.iso /tmp/parallels; + VER="`cat /tmp/parallels/version`"; + + e "Parallels Tools Version: $VER"; + + /tmp/parallels/install --install-unattended-with-deps \ + || (code="$?"; \ + echo "Parallels tools installation exited $code, attempting" \ + "to output /var/log/parallels-tools-install.log"; \ + cat /var/log/parallels-tools-install.log; \ + exit $code); + umount /tmp/parallels; + rm -rf /tmp/parallels; + rm -f $HOME_DIR/*.iso; + ;; + +qemu) + echo "Don't need anything for this one" + ;; + +*) + echo "Unknown Packer Builder Type >>$PACKER_BUILDER_TYPE<< selected."; + echo "Known are virtualbox-iso|virtualbox-ovf|vmware-iso|vmware-vmx|parallels-iso|parallels-pvm."; + ;; + +esac diff --git a/scripts/vmware.sh b/scripts/vmware.sh deleted file mode 100644 index cf53c60..0000000 --- a/scripts/vmware.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env bash - -e() { - echo -e " \e[1;32m[install] ==> $@\e[0m"; -} - -e "Install VMware Tools" -yum install -y open-vm-tools diff --git a/template-docker.json b/template-docker.json new file mode 100644 index 0000000..7983d53 --- /dev/null +++ b/template-docker.json @@ -0,0 +1,25 @@ +{ + "builders": [ + { + "type": "docker", + "image": "centos:7.2.1511", + "export_path": "builds/centos7-x64-{{.Provider}}.tar" + } + ], + "provisioners": [ + { + "type": "shell", + "execute_command": "echo 'vagrant' | sudo -S sh '{{.Path}}'", + "override": { + "docker": { + "scripts": [ + "scripts/base.sh", + "scripts/configs.sh", + "scripts/packages.sh", + "scripts/cleanup.sh" + ] + } + } + } + ] +} diff --git a/template.json b/template.json index 59018ed..c6fbdb1 100644 --- a/template.json +++ b/template.json @@ -70,43 +70,37 @@ ["set", "{{.Name}}", "--memsize", "512"], ["set", "{{.Name}}", "--cpus", "1"] ] + }, + { + "type": "qemu", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" + ], + "boot_wait": "10s", + "disk_size": 20480, + "http_directory": "http", + "iso_url": "http://mirrors.kernel.org/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso", + "iso_checksum": "f90e4d28fa377669b2db16cbcb451fcb9a89d2460e3645993e30e137ac37d284", + "iso_checksum_type": "sha256", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "history -c; echo '/sbin/halt -h -p' > /tmp/shutdown.sh; echo 'vagrant' | sudo -S sh '/tmp/shutdown.sh'" } ], "provisioners": [ { "type": "shell", "execute_command": "echo 'vagrant' | sudo -S sh '{{.Path}}'", - "override": { - "virtualbox-iso": { - "scripts": [ - "scripts/base.sh", - "scripts/configs.sh", - "scripts/packages.sh", - "scripts/vagrant.sh", - "scripts/virtualbox.sh", - "scripts/cleanup.sh" - ] - }, - "vmware-iso": { - "scripts": [ - "scripts/base.sh", - "scripts/configs.sh", - "scripts/packages.sh", - "scripts/vagrant.sh", - "scripts/vmware.sh", - "scripts/cleanup.sh" - ] - }, - "parallels-iso": { - "scripts": [ - "scripts/base.sh", - "scripts/configs.sh", - "scripts/packages.sh", - "scripts/vagrant.sh", - "scripts/cleanup.sh" - ] - } - } + "scripts": [ + "scripts/base.sh", + "scripts/configs.sh", + "scripts/packages.sh", + "scripts/vagrant.sh", + "scripts/vmtools.sh", + "scripts/cleanup.sh" + ] } ], "post-processors": [