mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Re-factor Docker+Vagrat+YAML environment
Move host Vagrantfile into main directory, and refactor to use external YAML configuration file. Add multi-platform support.
This commit is contained in:
parent
be92f4dd56
commit
7e8077310d
4 changed files with 78 additions and 37 deletions
20
vagrant-docker-yaml/Vagrantfile
vendored
20
vagrant-docker-yaml/Vagrantfile
vendored
|
|
@ -2,8 +2,8 @@
|
|||
# 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_DEFAULT_PROVIDER'] = 'docker'
|
||||
|
||||
# Require 'yaml' module
|
||||
|
|
@ -19,30 +19,30 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|||
# Perform one-time configuration of Docker provider to specify
|
||||
# location of Vagrantfile for host VM; comment out this section
|
||||
# to use default boot2docker box
|
||||
config.vm.provider "docker" do |docker|
|
||||
docker.vagrant_vagrantfile = "host/Vagrantfile"
|
||||
config.vm.provider 'docker' do |docker|
|
||||
docker.vagrant_vagrantfile = 'VagrantfileHost'
|
||||
end # config.vm.provider
|
||||
|
||||
# Iterate through the entries in the YAML file
|
||||
containers.each do |container|
|
||||
config.vm.define container["name"] do |cntnr|
|
||||
config.vm.define container['name'] do |cntnr|
|
||||
|
||||
# Disable synced folders for the Docker container
|
||||
# (prevents an NFS error on "vagrant up")
|
||||
cntnr.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
cntnr.vm.synced_folder '.', '/vagrant', disabled: true
|
||||
|
||||
# Configure the Docker provider for Vagrant
|
||||
cntnr.vm.provider "docker" do |docker|
|
||||
cntnr.vm.provider 'docker' do |docker|
|
||||
|
||||
# Specify the Docker image to use, pull value from YAML file
|
||||
docker.image = container["image"]
|
||||
docker.image = container['image']
|
||||
|
||||
# Specify port mappings, pull value from YAML file
|
||||
# If omitted, no ports are mapped!
|
||||
docker.ports = container["ports"]
|
||||
docker.ports = container['ports']
|
||||
|
||||
# Specify a friendly name for the Docker container, pull from YAML file
|
||||
docker.name = container["name"]
|
||||
docker.name = container['name']
|
||||
end # contnr.vm.provider
|
||||
end # config.vm.define
|
||||
end # containers.each
|
||||
|
|
|
|||
61
vagrant-docker-yaml/VagrantfileHost
Normal file
61
vagrant-docker-yaml/VagrantfileHost
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Specify minimum Vagrant version and Vagrant API version
|
||||
Vagrant.require_version '>= 1.6.0'
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
|
||||
# Require 'yaml' module
|
||||
require 'yaml'
|
||||
|
||||
# Read YAML file with VM details (box, CPU, RAM, IP addresses)
|
||||
# Edit host.yml to change VM configuration details
|
||||
hostvms = YAML.load_file(File.join(File.dirname(__FILE__), 'hostvms.yml'))
|
||||
|
||||
# Create and configure the VM(s)
|
||||
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
|
||||
hostvms.each do |host|
|
||||
|
||||
# Configure the VMs per details in YAML file
|
||||
config.vm.define host['name'] do |srv|
|
||||
|
||||
# Don't check for box updates
|
||||
srv.vm.box_check_update = false
|
||||
|
||||
# Specify the hostname of the VM
|
||||
srv.vm.hostname = host['name']
|
||||
|
||||
# Specify the Vagrant box to use (use VMware box by default)
|
||||
srv.vm.box = host['vmw_box']
|
||||
|
||||
# Disable synced folders (prevents an NFS error on "vagrant up")
|
||||
srv.vm.synced_folder '.', '/vagrant', disabled: true
|
||||
|
||||
# Assign additional private network
|
||||
if host['ip_addr'] != nil
|
||||
srv.vm.network 'private_network', ip: host['ip_addr']
|
||||
end # if host['ip_addr']
|
||||
|
||||
# Configure CPU & RAM per settings in hostvms.yml (Fusion)
|
||||
srv.vm.provider 'vmware_fusion' do |vmw|
|
||||
vmw.vmx['memsize'] = host['ram']
|
||||
vmw.vmx['numvcpus'] = host['vcpu']
|
||||
end # srv.vm.provider 'vmware_fusion'
|
||||
|
||||
# Configure CPU & RAM per settings in hostvms.yml (VirtualBox)
|
||||
srv.vm.provider 'virtualbox' do |vb, override|
|
||||
vb.memory = host['ram']
|
||||
vb.cpus = host['vcpu']
|
||||
override.vm.box = host['vb_box']
|
||||
end # srv.vm.provider 'virtualbox'
|
||||
|
||||
# Provision the VM with Docker
|
||||
srv.vm.provision 'docker'
|
||||
end # config.vm.define
|
||||
end # hostvsm.each
|
||||
end # Vagrant.configure
|
||||
27
vagrant-docker-yaml/host/Vagrantfile
vendored
27
vagrant-docker-yaml/host/Vagrantfile
vendored
|
|
@ -1,27 +0,0 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Specify Vagrant version and Vagrant API version
|
||||
Vagrant.require_version ">= 1.6.0"
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
# Create and configure the VM(s)
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# Assign a friendly name to this host VM
|
||||
config.vm.hostname = "docker-host"
|
||||
|
||||
# Skip checking for an updated Vagrant box
|
||||
config.vm.box_check_update = false
|
||||
|
||||
# Always use Vagrant's default insecure key
|
||||
config.ssh.insert_key = false
|
||||
|
||||
# Spin up a "host box" for use with the Docker provider
|
||||
# and then provision it with Docker
|
||||
config.vm.box = "slowe/ubuntu-trusty-x64"
|
||||
config.vm.provision "docker"
|
||||
|
||||
# Disable synced folders (prevents an NFS error on "vagrant up")
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
end
|
||||
7
vagrant-docker-yaml/hostvms.yml
Normal file
7
vagrant-docker-yaml/hostvms.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
- name: "default"
|
||||
vmw_box: "slowe/ubuntu-trusty-x64"
|
||||
vb_box: "ubuntu/trusty64"
|
||||
ram: "1024"
|
||||
vcpu: "1"
|
||||
ip_addr: "192.168.100.101"
|
||||
Loading…
Reference in a new issue