Skip to content

Instantly share code, notes, and snippets.

@jyates
Last active November 8, 2017 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyates/a881879f97155c0d8c8f to your computer and use it in GitHub Desktop.
Save jyates/a881879f97155c0d8c8f to your computer and use it in GitHub Desktop.
Vagrantfile for centOS docker cloudbreak instance
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Base Box
config.vm.box = "CentOS-7.1.1503_64"
config.vm.box_url = "https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box"
# Base IP address range used for VMs. Pretty sure not to be already used on the local network.
$BASE_RANGE = ENV.fetch("BASE_RANGE", "10.200.0.")
cloudbreak_ip = $BASE_RANGE + ENV.fetch("CB_IP", "3")
config.vm.define "cloudbreak", primary: true do |cb|
# Networking
#############
cb.vm.network "private_network", ip: cloudbreak_ip
# Environment
##############
# Add our custom stack to the available stacks
cb.vm.synced_folder "vagrant/", "/vagrant"
# Setup the VM system properties
cb.vm.provider "virtualbox" do |vb|
# Customize the amount of memory on the VM:
vb.name = ENV.fetch("CB_VM_NAME", "cloudbreak_host")
vb.memory = ENV.fetch("CB_MEMORY", "8192")
vb.cpus = ENV.fetch("CB_CPUS", "4")
# cap the CPU usage to 75% (3 of 4 cores)
vb.customize ["modifyvm", :id, "--cpuexecutioncap", ENV.fetch("CB_CPU_PERCENT", "75")]
end
# Provisioning
##############
# copy the docker repo file into yum repos. runs as shell because file provisioner doesn't have perms
cb.vm.provision "prepare-docker", type: "shell", inline: "sudo cp /vagrant/docker.repo /etc/yum.repos.d/docker.repo"
cb.vm.provision "install-docker", type: "shell" do |s|
s.inline = <<-SHELL
# setup firewalld (wrapper for iptables) to allow cross-docker communication
firewall-cmd --permanent --zone=trusted --change-interface=docker0
firewall-cmd --permanent --zone=trusted --add-port=4243/tcp
firewall-cmd --reload
# stuff docker actually needs
sudo yum install -y docker-engine
sudo service docker start
sudo docker run hello-world
# ensure the docker daemon is always running when we start
sudo chkconfig docker on
SHELL
end
cb.vm.provision "prepare-cloudbreak", type: "shell" do |s|
s.inline = <<-SHELL
yum install -y unzip
yum install -y net-tools
yum install -y telnet
# personal tools
yum install -y vim
SHELL
end
cb.vm.provision "install-cloudbreak", type: "shell" do |s|
s.inline = <<-SHELL
dest=/bin
hash -r > /dev/null
if (command -v cbd > /dev/null); then
existing=$(command -v cbd)
dest=${existing%/*}
else
if echo "$PATH" | grep -q '/usr/local/bin' ; then
dest=/usr/local/bin
fi
fi
cat /vagrant/cloudbreak-deployer* | tar -xz -C ${dest}
echo "---> cbd installed into ${dest}"
cbd --version
SHELL
end
cloudbreak_dir = "/vagrant/cloudbreak-deployment"
cb.vm.provision "init-cloudbreak", type: "shell" do |s|
s.inline = <<-SHELL
# Setup the profile
dir="#{cloudbreak_dir}"
if [ -d $dir ]; then
rm -rf ${dir}
fi
mkdir $dir
cd $dir
echo "export PUBLIC_IP=#{cloudbreak_ip}" > Profile
echo "export PRIVATE_IP=#{cloudbreak_ip}" >> Profile
SHELL
end
if ENV.fetch("HEADLESS", false)
cb.vm.provision "setup-cloudbreak", type: "shell" do |s|
s.inline = <<-SHELL
cd "#{cloudbreak_dir}"
cbd generate
cbd start
cbd login
SHELL
end # last provision
else
# Do the cloudbreak setup. We can get part of the way, but requires an actual login to finish
cb.vm.provision "setup-cloudbreak", type: "shell" do |s|
s.inline = <<-SHELL
cd "#{cloudbreak_dir}"
echo "You need to login and run cloubreak on an interactive shell (yes, I know):"
echo " vagrant ssh"
echo " sudo su - root"
echo " cd #{cloudbreak_dir}; cbd generate; cbd start; cbd login"
SHELL
end # last provision
end # if statement
end #the vm
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment