Update rkt environment

Add new shell script for configuring VMs with CoreOS rkt. Modify Vagrantfile to "pre-download" files if they exist in current directory. Add new multi-platform code to Vagrantfile. Change filenames to adhere to new naming convention.
This commit is contained in:
Scott S. Lowe 2016-04-20 09:44:50 -06:00
parent 0b31969984
commit 30262d7b3c
5 changed files with 81 additions and 52 deletions

55
rkt/Vagrantfile vendored
View file

@ -2,15 +2,15 @@
# vi: set ft=ruby :
# Specify Vagrant version, Vagrant API version, and Vagrant clone location
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version '>= 1.6.0'
VAGRANTFILE_API_VERSION = '2'
ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant'
# Require 'yaml' module
require 'yaml'
# Read YAML file with VM details (box, CPU, and RAM)
servers = YAML.load_file(File.join(File.dirname(__FILE__), 'servers.yml'))
machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml'))
# Create and configure the VMs
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
@ -19,25 +19,40 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
# Iterate through entries in YAML file to create VMs
servers.each do |servers|
config.vm.define servers["name"] do |srv|
machines.each do |machine|
config.vm.define machine['name'] do |srv|
# Don't check for box updates
srv.vm.box_check_update = false
srv.vm.hostname = servers["name"]
srv.vm.box = servers["box"]
# Enable default synced folder
srv.vm.synced_folder ".", "/vagrant"
# Perform final provisioning activities
#srv.vm.provision "shell", path: "config.sh", privileged: true
#srv.vm.provision "file", source: "adminrc", destination: "/home/vagrant/adminrc"
# Set VM hostname and Vagrant box to use (default to VMware box)
srv.vm.hostname = machine['name']
srv.vm.box = machine['vmw_box']
# Configure VMs with RAM and CPUs per settings in servers.yml
srv.vm.provider :vmware_fusion do |vmw|
vmw.vmx["memsize"] = servers["ram"]
vmw.vmx["numvcpus"] = servers["vcpu"]
end
end
end
end
# Disable default synced folder
srv.vm.synced_folder '.', '/vagrant', disabled: true
# If it exists, copy the rkt download into the Vagrant VM
if File.file?(File.join(File.dirname(__FILE__), 'rkt-v1.4.0.tar.gz'))
srv.vm.provision 'file', source: 'rkt-v1.4.0.tar.gz',
destination: '/home/vagrant/rkt-v1.4.0.tar.gz'
end # if File.file?(rkt)
# Run the provisioning shell script
srv.vm.provision 'shell', path: 'provision.sh'
# Configure VMs with RAM and CPUs per machines.yml (Fusion)
srv.vm.provider 'vmware_fusion' do |vmw|
vmw.vmx['memsize'] = machine['ram']
vmw.vmx['numvcpus'] = machine['vcpu']
end # srv.vm.provider 'vmware_fusion'
# Configure the VM with RAM and CPUs per machines.yml (VirtualBox)
srv.vm.provider 'virtualbox' do |vb, override|
vb.memory = machine['ram']
vb.cpus = machine['vcpu']
override.vm.box = machine['vb_box']
end # srv.vm.provider 'virtualbox'
end # config.vm.define
end # machines.each
end # Vagrant.configure

6
rkt/machines.yml Normal file
View file

@ -0,0 +1,6 @@
---
- name: rkt-01
vmw_box: slowe/ubuntu-trusty-x64
vb_box: ubuntu/trusty64
ram: 512
vcpu: 1

40
rkt/provision.sh Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
# Set some variables for later
VER="1.4.0"
URL="https://github.com/coreos/rkt/releases/download"
FILE="rkt-v$VER.tar.gz"
DIR="rkt-v$VER"
# Install curl if needed
if [[ ! -e /usr/bin/curl ]]; then
apt-get update
apt-get -yqq install curl
fi
# Download the rkt tarball if it doesn't already exist
if [[ ! -e /home/vagrant/$FILE ]]; then
# Download files for rkt
curl -LO $URL/v$VER/rkt-v$VER.tar.gz
fi
# If the rkt binary is in /usr/local/bin, assume the system is provisioned
if [[ ! -e /usr/local/bin/rkt ]]; then
# Unpack the downloaded file
tar xzvf $FILE
# Move rkt to /usr/local/bin and ensure it is executable
cd $DIR
sudo mv rkt /usr/local/bin/
sudo chmod a+x /usr/local/bin/rkt
# Move ACI files to /usr/local/bin
sudo mv stage1-coreos.aci /usr/local/bin/
sudo mv stage1-fly.aci /usr/local/bin/
sudo mv stage1-kvm.aci /usr/local/bin/
# Remove directory created by unpacking tarball
# Leave tarball in place (indicates provisioned system)
cd ..
rm -rf rkt-v$VER
fi

View file

@ -1,5 +0,0 @@
---
- name: rkt-01
box: slowe/ubuntu-trusty-x64
ram: 512
vcpu: 1

View file

@ -1,27 +0,0 @@
#!/bin/bash
# Download rkt from GitHub
wget https://github.com/coreos/rkt/releases/download/v0.5.5/rkt-v0.5.5.tar.gz
# Unpack the rkt files and move to final destination
tar xzvf rkt-v0.5.5.tar.gz
cd rkt-v0.5.5
sudo mv rkt /usr/local/bin/
sudo mv stage1.aci /usr/local/bin/
rm -rf rkt-v0.5.5
# Create a rkt user and group
sudo useradd -M -d /var/lib/rkt -r -s /usr/bin/nologin rkt
# Add default vagrant user to rkt group
sudo usermod -G rkt -a vagrant
# Set up directories for rkt
sudo mkdir -p /var/lib/rkt
sudo chown -R rkt:rkt /var/lib/rkt
sudo chmod -R 0775 /var/lib/rkt
sudo chmod -R g+s /var/lib/rkt
sudo mkdir -p /etc/rkt
sudo chown -R rkt:rkt /etc/rkt
sudo chmod -R 0775 /etc/rkt
sudo chmod -R g+s /etc/rkt