From d25f50f81fe15165088f2e0cb1521b880718aac3 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Sun, 27 Mar 2016 13:33:38 -0600 Subject: [PATCH 1/4] Commit initial set of files for containerd-runc environment Commit Vagrantfile, external YAML data file, Ansible configuration file, and Ansible playbook for containerd-runc environment. Environment is functional at a basic level. --- containerd-runc/Vagrantfile | 60 +++++++++++++++++++++++++++++ containerd-runc/ansible.cfg | 5 +++ containerd-runc/containerd-runc.yml | 45 ++++++++++++++++++++++ containerd-runc/machines.yml | 6 +++ 4 files changed, 116 insertions(+) create mode 100644 containerd-runc/Vagrantfile create mode 100644 containerd-runc/ansible.cfg create mode 100644 containerd-runc/containerd-runc.yml create mode 100644 containerd-runc/machines.yml diff --git a/containerd-runc/Vagrantfile b/containerd-runc/Vagrantfile new file mode 100644 index 0000000..a2cb636 --- /dev/null +++ b/containerd-runc/Vagrantfile @@ -0,0 +1,60 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Specify Vagrant version, Vagrant API version, and desired clone location +Vagrant.require_version '>= 1.8.0' +VAGRANTFILE_API_VERSION = '2' +ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion' +ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' +#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' + +# Require 'yaml' module +require 'yaml' + +# Read YAML file with VM details (box, CPU, RAM, IP addresses) +machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml')) + +# Create and configure the VMs +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # Always use Vagrant's default insecure key + config.ssh.insert_key = false + + # Iterate through entries in YAML file to create VMs + 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 = machine['name'] + srv.vm.box = machine['box'] + + # Configure default synced folder (disable by default) + if machine['sync_disabled'] != nil + srv.vm.synced_folder '.', '/vagrant', disabled: machine['sync_disabled'] + else + srv.vm.synced_folder '.', '/vagrant', disabled: true + end #if machine['sync_disabled'] + + # Configure CPU & RAM per settings in machines.yml (Fusion) + srv.vm.provider :vmware_fusion do |vmw| + vmw.vmx['memsize'] = machine['ram'] + vmw.vmx['numvcpus'] = machine['vcpu'] + if machine['nested'] == true + vmw.vmx['vhv.enable'] = 'TRUE' + end #if machine['nested'] + end # srv.vm.provider vmware_fusion + + # Configure CPU & RAM per settings in machines.yml (VirtualBox) + srv.vm.provider :virtualbox do |vb| + vb.memory = machine['ram'] + vb.cpus = machine['vcpu'] + end # srv.vm.provider virtualbox + + # Provision Docker on appropriate VMs + if machine['provision'] != nil + srv.vm.provision 'ansible', playbook: machine['provision'] + end # if machine['provision'] + end # config.vm.define + end # machines.each +end # Vagrant.configure diff --git a/containerd-runc/ansible.cfg b/containerd-runc/ansible.cfg new file mode 100644 index 0000000..b3a4567 --- /dev/null +++ b/containerd-runc/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +inventory = ./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory +private_key_file = ~/.vagrant.d/insecure_private_key +remote_user = vagrant +host_key_checking = False \ No newline at end of file diff --git a/containerd-runc/containerd-runc.yml b/containerd-runc/containerd-runc.yml new file mode 100644 index 0000000..e5d5ec3 --- /dev/null +++ b/containerd-runc/containerd-runc.yml @@ -0,0 +1,45 @@ +--- +- hosts: "all" + sudo: "yes" + remote_user: "vagrant" + gather_facts: false + + tasks: + - name: "Bootstrap node" + raw: "apt-get install -y python python2.7" + + - name: "Download containerd" + get_url: + url: "https://github.com/docker/containerd/releases/download/0.0.5/containerd" + dest: "/usr/local/bin/containerd" + mode: "0755" + + - name: "Download containerd-shim" + get_url: + url: "https://github.com/docker/containerd/releases/download/0.0.5/containerd-shim" + dest: "/usr/local/bin/containerd-shim" + mode: "0755" + + - name: "Download runc" + get_url: + url: "https://github.com/docker/containerd/releases/download/0.0.5/runc" + dest: "/usr/local/bin/runc" + mode: "0755" + + - name: "Download ctr" + get_url: + url: "https://github.com/docker/containerd/releases/download/0.0.5/ctr" + dest: "/usr/local/bin/ctr" + mode: "0755" + + - name: "Set properties for downloaded files" + file: + path: "{{ item }}" + owner: "root" + group: "root" + mode: "0755" + with_items: + - /usr/local/bin/containerd + - /usr/local/bin/runc + - /usr/local/bin/ctr + - /usr/local/bin/containerd-shim diff --git a/containerd-runc/machines.yml b/containerd-runc/machines.yml new file mode 100644 index 0000000..b622267 --- /dev/null +++ b/containerd-runc/machines.yml @@ -0,0 +1,6 @@ +--- +- name: runc-01 + box: slowe/ubuntu-15.10-server-amd64 + ram: 1024 + vcpu: 1 + provision: containerd-runc.yml From 2733fdfa3ee38e67b41ac7ab4e4efaa079a86b50 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Sun, 17 Apr 2016 19:00:43 -0600 Subject: [PATCH 2/4] Switch VM provisioning method Remove Ansible playbook. Add shell script to do provisioning. Modify Vagrantfile accordingly. --- containerd-runc/Vagrantfile | 6 ++-- containerd-runc/containerd-runc.yml | 45 -------------------------- containerd-runc/provision.sh | 50 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 containerd-runc/containerd-runc.yml create mode 100644 containerd-runc/provision.sh diff --git a/containerd-runc/Vagrantfile b/containerd-runc/Vagrantfile index a2cb636..7a39b61 100644 --- a/containerd-runc/Vagrantfile +++ b/containerd-runc/Vagrantfile @@ -51,10 +51,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| vb.cpus = machine['vcpu'] end # srv.vm.provider virtualbox - # Provision Docker on appropriate VMs - if machine['provision'] != nil - srv.vm.provision 'ansible', playbook: machine['provision'] - end # if machine['provision'] + # Provision the VMs + srv.vm.provision 'shell', path: 'provision.sh', privileged: true end # config.vm.define end # machines.each end # Vagrant.configure diff --git a/containerd-runc/containerd-runc.yml b/containerd-runc/containerd-runc.yml deleted file mode 100644 index e5d5ec3..0000000 --- a/containerd-runc/containerd-runc.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -- hosts: "all" - sudo: "yes" - remote_user: "vagrant" - gather_facts: false - - tasks: - - name: "Bootstrap node" - raw: "apt-get install -y python python2.7" - - - name: "Download containerd" - get_url: - url: "https://github.com/docker/containerd/releases/download/0.0.5/containerd" - dest: "/usr/local/bin/containerd" - mode: "0755" - - - name: "Download containerd-shim" - get_url: - url: "https://github.com/docker/containerd/releases/download/0.0.5/containerd-shim" - dest: "/usr/local/bin/containerd-shim" - mode: "0755" - - - name: "Download runc" - get_url: - url: "https://github.com/docker/containerd/releases/download/0.0.5/runc" - dest: "/usr/local/bin/runc" - mode: "0755" - - - name: "Download ctr" - get_url: - url: "https://github.com/docker/containerd/releases/download/0.0.5/ctr" - dest: "/usr/local/bin/ctr" - mode: "0755" - - - name: "Set properties for downloaded files" - file: - path: "{{ item }}" - owner: "root" - group: "root" - mode: "0755" - with_items: - - /usr/local/bin/containerd - - /usr/local/bin/runc - - /usr/local/bin/ctr - - /usr/local/bin/containerd-shim diff --git a/containerd-runc/provision.sh b/containerd-runc/provision.sh new file mode 100644 index 0000000..c50e1ea --- /dev/null +++ b/containerd-runc/provision.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Install curl if needed +if [[ ! -e /usr/bin/curl ]]; then + sudo apt-get -yqq install curl +fi + +# Download containerd, if it isn't already present on the system +if [[ ! -e /usr/local/bin/containerd ]]; then + + # Download containerd from GitHub + curl -kLO https://github.com/docker/containerd/releases/download/0.0.5/containerd + + # Move the downloaded binary to /usr/local/bin + sudo mv containerd /usr/local/bin/containerd + sudo chmod a+x /usr/local/bin/containerd +fi + +# Download containerd-shim, if it isn't already present on the system +if [[ ! -e /usr/local/bin/containerd-shim ]]; then + + # Download containerd-shim from GitHub + curl -kLO https://github.com/docker/containerd/releases/download/0.0.5/containerd-shim + + # Move the downloaded binary to /usr/local/bin + sudo mv containerd-shim /usr/local/bin/containerd-shim + sudo chmod a+x /usr/local/bin/containerd-shim +fi + +# Download ctr, if it isn't already present on the system +if [[ ! -e /usr/local/bin/ctr ]]; then + + # Download ctr from GitHub + curl -kLO https://github.com/docker/containerd/releases/download/0.0.5/ctr + + # Move the downloaded binary to /usr/local/bin + sudo mv ctr /usr/local/bin/ctr + sudo chmod a+x /usr/local/bin/ctr +fi + +# Download runc, if it isn't already present on the system +if [[ ! -e /usr/local/bin/runc ]]; then + + # Download runc from GitHub + curl -kLO https://github.com/docker/containerd/releases/download/0.0.5/runc + + # Move the downloaded binary to /usr/local/bin + sudo mv runc /usr/local/bin/runc + sudo chmod a+x /usr/local/bin/runc +fi From 6116b7e3cc9ab0442fbbb6a647e109c43990cdbb Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Sat, 10 Dec 2016 19:21:44 -0700 Subject: [PATCH 3/4] Update Vagrantfile and external data file Update Vagrantfile and external data file to use new structure Signed-off-by: Scott S. Lowe --- containerd-runc/Vagrantfile | 20 +++++++++++--------- containerd-runc/machines.yml | 15 ++++++++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/containerd-runc/Vagrantfile b/containerd-runc/Vagrantfile index 7a39b61..579dba3 100644 --- a/containerd-runc/Vagrantfile +++ b/containerd-runc/Vagrantfile @@ -1,12 +1,9 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# Specify Vagrant version, Vagrant API version, and desired clone location +# Specify minimum Vagrant version and Vagrant API version Vagrant.require_version '>= 1.8.0' VAGRANTFILE_API_VERSION = '2' -ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion' -ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' -#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' # Require 'yaml' module require 'yaml' @@ -26,8 +23,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Don't check for box updates srv.vm.box_check_update = false + + # Specify the hostname of the VM srv.vm.hostname = machine['name'] - srv.vm.box = machine['box'] + + # Specify the Vagrant box to use (use VMware box by default) + srv.vm.box = machine['box']['vmw'] # Configure default synced folder (disable by default) if machine['sync_disabled'] != nil @@ -37,19 +38,20 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end #if machine['sync_disabled'] # Configure CPU & RAM per settings in machines.yml (Fusion) - srv.vm.provider :vmware_fusion do |vmw| + srv.vm.provider 'vmware_fusion' do |vmw| vmw.vmx['memsize'] = machine['ram'] vmw.vmx['numvcpus'] = machine['vcpu'] if machine['nested'] == true vmw.vmx['vhv.enable'] = 'TRUE' end #if machine['nested'] - end # srv.vm.provider vmware_fusion + end # srv.vm.provider 'vmware_fusion' # Configure CPU & RAM per settings in machines.yml (VirtualBox) - srv.vm.provider :virtualbox do |vb| + srv.vm.provider 'virtualbox' do |vb, override| vb.memory = machine['ram'] vb.cpus = machine['vcpu'] - end # srv.vm.provider virtualbox + override.vm.box = machine['box']['vb'] + end # srv.vm.provider 'virtualbox' # Provision the VMs srv.vm.provision 'shell', path: 'provision.sh', privileged: true diff --git a/containerd-runc/machines.yml b/containerd-runc/machines.yml index b622267..4c1013e 100644 --- a/containerd-runc/machines.yml +++ b/containerd-runc/machines.yml @@ -1,6 +1,11 @@ --- -- name: runc-01 - box: slowe/ubuntu-15.10-server-amd64 - ram: 1024 - vcpu: 1 - provision: containerd-runc.yml +- box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + name: "runc-01" + nics: + - type: "private_network" + ip_addr: "192.168.100.101" + provision: "containerd-runc.yml" + ram: "512" + vcpu: "1" From f04569e98c373b060f99125e7079080eda678406 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Sat, 10 Dec 2016 19:52:29 -0700 Subject: [PATCH 4/4] Update Vagrantfile Add support for multiple NICs based on the external data file Signed-off-by: Scott S. Lowe --- containerd-runc/Vagrantfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/containerd-runc/Vagrantfile b/containerd-runc/Vagrantfile index 579dba3..ab2fa33 100644 --- a/containerd-runc/Vagrantfile +++ b/containerd-runc/Vagrantfile @@ -9,6 +9,7 @@ VAGRANTFILE_API_VERSION = '2' require 'yaml' # Read YAML file with VM details (box, CPU, RAM, IP addresses) +# Edit machines.yml to change VM configuration details machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml')) # Create and configure the VMs @@ -19,6 +20,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Iterate through entries in YAML file to create VMs machines.each do |machine| + + # Configure the VMs per details in machines.yml config.vm.define machine['name'] do |srv| # Don't check for box updates @@ -37,6 +40,15 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| srv.vm.synced_folder '.', '/vagrant', disabled: true end #if machine['sync_disabled'] + # Iterate through networks as per settings in machines.yml + machine['nics'].each do |net| + if net['ip_addr'] == 'dhcp' + srv.vm.network net['type'], type: net['ip_addr'] + else + srv.vm.network net['type'], ip: net['ip_addr'] + end # if net['ip_addr'] + end # machine['nics'].each + # Configure CPU & RAM per settings in machines.yml (Fusion) srv.vm.provider 'vmware_fusion' do |vmw| vmw.vmx['memsize'] = machine['ram']