Skip to content
This repository was archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
[WIP] Fixing Vagrant HGFS issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
skyzyx committed Jul 11, 2016
1 parent b952418 commit e7811e5
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 59 deletions.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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

Expand All @@ -36,7 +45,7 @@ You have two choices for installing Packer.

1. Otherwise, you can manually install it from <https://www.packer.io/downloads.html>.

## Building Boxes
## Building Vagrant Boxes

### Build everything

Expand All @@ -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
```
55 changes: 55 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions scripts/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ yum -y install \
bind-utils \
bzip2 \
ca-certificates \
cpp \
cronie \
cronie-anacron \
crontabs \
Expand All @@ -64,6 +65,7 @@ yum -y install \
iptables \
iputils \
kernel-devel-`uname -r` \
kernel-headers-`uname -r` \
libcgroup \
libselinux-python \
make \
Expand Down
15 changes: 0 additions & 15 deletions scripts/virtualbox.sh

This file was deleted.

62 changes: 62 additions & 0 deletions scripts/vmtools.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions scripts/vmware.sh

This file was deleted.

25 changes: 25 additions & 0 deletions template-docker.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
]
}
56 changes: 25 additions & 31 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,37 @@
["set", "{{.Name}}", "--memsize", "512"],
["set", "{{.Name}}", "--cpus", "1"]
]
},
{
"type": "qemu",
"boot_command": [
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
],
"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": [
Expand Down

0 comments on commit e7811e5

Please sign in to comment.