Merge pull request #44 from lowescott/rkt

Finalize rkt learning environment
This commit is contained in:
Scott S. Lowe 2016-04-20 10:39:36 -06:00
commit 35af80fd60
6 changed files with 111 additions and 60 deletions

View file

@ -1,22 +1,38 @@
# Running Containers with rkt
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) quickly and relatively easily experiment with using `rkt` (pronounced "rock-it"), the CoreOS implementation of the App Container (appc) specification. The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin.
**WARNING:** These files are not yet fully functional!
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) quickly and relatively easily experiment with using `rkt` (pronounced "rock-it"), the CoreOS implementation of the App Container (appc) specification. The configuration was tested using Vagrant 1.8.1, VMware Fusion 8.1.0, and the Vagrant VMware plugin.
## Contents
* **machines.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. You may need to edit this file to ensure that the correct Vagrant box is listed.
* **provision.sh**: This shell script is called by the Vagrant shell provisioner and configures `rkt` inside the VM created by Vagrant. No changes should be needed to this file.
* **README.md**: This file you're currently reading.
* **servers.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. No changes should be necessary to use this file.
* **setup.sh**: This shell script is called by the Vagrant shell provisioner and configures `rkt` inside the VM created by Vagrant. No changes should be needed to this file.
* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file.
## Instructions
[NOT YET FUNCTIONAL]
These instructions assume you've already installed Vagrant, your virtualization provider, and any necessary Vagrant plugins. Please refer to the documentation for those products for more information on installation or configuration.
1. Use `vagrant box add` to install an Ubuntu 14.04 x64 box for the vmware_fusion provider. I have a base box you can use for this purpose; to use my Ubuntu 14.04 x64 base box, add the box with `vagrant box add slowe/ubuntu-trusty-x64`.
2. Place the files from the `rkt` directory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (using `git clone`) or just download the specific files from the the `rkt` folder.
3. Verify that the Vagrant box you added in step #1 is the box listed in `machines.yml`. Note there are separate lines for a VMware Fusion-formatted box (on the "vmw_box" line) and a VirtualBox-formatted box (on the "vb_box" line).
4. If you download the `rkt-v1.4.0.tar.gz` release from GitHub (see [https://github.com/coreos/rkt/releases](https://github.com/coreos/rkt/releases)) and place it in the same directory with the `Vagrantfile` and other files, then the Vagrant provisioning script won't download it from the Internet and will use the local copy instead.
5. Use `vagrant up` to instantiate the learning environment.
6. Use `vagrant ssh` to log into the VM created by Vagrant.
7. Use this command to launch a simple rkt container (follow the prompts as necessary):
sudo rkt run --interactive quay.io/coreos/alpine-sh
Enjoy!
## License

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

46
rkt/provision.sh Executable file
View file

@ -0,0 +1,46 @@
#!/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/
# Create working directory for rkt
sudo mkdir -p /var/lib/rkt
# Create rkt group if it doesn't already exist
[ $(getent group rkt) ] || sudo groupadd rkt
# 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