Revisions
-
cariandrum22 revised this gist
Aug 17, 2016 . 1 changed file with 21 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,31 +17,31 @@ sudo /usr/local/etc/init.d/nfs-client start sudo mount -t nfs -o noacl,async <%= ip %>:/Users /Users EOL .freeze class DockerMachineNfs def initialize(machine_name, driver) @bootlocal = BOOTLOCAL_SH_TEMPLATE case driver when 'virtualbox' then @uid = `id -u`.chomp @gid = `id -g`.chomp @dmachine_name = machine_name @dmachine_ip = `docker-machine ip #{machine_name}`.chomp @vboxnet_ip = VirtualBox.get_vboxnet_ip(VirtualBox.get_hostonly_adapter(machine_name)) else raise 'This script dose not support selected driver: ' + driver end yield self if block_given? end def setup_nfs_server # create record in local /etc/exports and restart nsfd puts 'Update /etc/exports ...' `echo '\n/Users #{@dmachine_ip} -alldirs -mapall=#{@uid}:#{@gid}\n' | sudo tee -a /etc/exports` `awk '!a[$0]++' /etc/exports | sudo tee /etc/exports` # removes duplicate lines `sudo nfsd restart` sleep 2 checkexports = `sudo nfsd checkexports 2>&1` if checkexports == '' puts ' > Done.' @@ -69,19 +69,17 @@ def setup_nfs_client end def check puts "Check if NFS is mounted on docker-machine \"#{@dmachine_name}\"." sleep 2 result = <<-EOS > failed: Try `docker-machine ssh #{@dmachine_name} df`. Output should include something like this: '#{@vboxnet_ip}:/Users [...] /Users' EOS `docker-machine ssh #{@dmachine_name} df`.each_line do |l| result = ' > Done.' if %r{^#{@vboxnet_ip}:/Users.*/Users$} =~ l.chomp end puts result end end module VirtualBox @@ -91,12 +89,9 @@ def get_hostonly_adapter(machine_name) puts 'Get vbox hostonly adapter name ...' vboxnet_name = `VBoxManage showvminfo #{machine_name} --machinereadable | grep hostonlyadapter` .scan(/"(.*)"/).flatten.first.chomp raise 'error: unable to find name of vboxnet' if vboxnet_name == '' puts ' > ' + vboxnet_name vboxnet_name end def get_vboxnet_ip(vboxnet_name) @@ -106,17 +101,18 @@ def get_vboxnet_ip(vboxnet_name) vboxip = vboxnet.scan(/IPAddress: *(.*)\n/).flatten.first.chomp puts ' > ' + vboxip return vboxip else next end end end end end def main options = { driver: 'virtualbox' } OptionParser.new do |op| op.on('-d', '--driver "virtualbox"', 'docker-machine driver (default:virtualbox)') { |v| options[:driver] = v } op.parse!(ARGV) end @@ -133,7 +129,6 @@ def main d.setup_nfs_client d.check end end main -
cariandrum22 revised this gist
Aug 17, 2016 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,6 @@ # fork from https://gist.github.com/mattes/4d7f435d759ca2581347 # I owe you a lot, mattes. require 'erb' require 'optparse' @@ -22,7 +21,7 @@ class DockerMachineNfs def initialize(machine_name, driver) @bootlocal = BOOTLOCAL_SH_TEMPLATE case driver when 'virtualbox' then -
cariandrum22 revised this gist
Aug 17, 2016 . 1 changed file with 120 additions and 55 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,74 +2,139 @@ # Usage # $ docker-machine create my-machine123 -d virtualbox # $ ruby <(curl -L https://git.io/v6r1A) my-machine123 # https://gist.github.com/cariandrum22/278973172442d6f54a0c3ab83a86469f # fork from https://gist.github.com/mattes/4d7f435d759ca2581347 # I owe you a lot, mattes. require 'erb' require 'optparse' BOOTLOCAL_SH_TEMPLATE = <<EOL #/bin/bash sudo umount /Users sudo /usr/local/etc/init.d/nfs-client start sudo mount -t nfs -o noacl,async <%= ip %>:/Users /Users EOL BOOTLOCAL_SH_TEMPLATE.freeze class DockerMachineNfs def initialize(machine_name, driver='') @bootlocal = BOOTLOCAL_SH_TEMPLATE case driver when 'virtualbox' then @uid = `id -u`.chomp @gid = `id -g`.chomp @dmachine_name = machine_name @dmachine_ip = `docker-machine ip #{machine_name}`.chomp @vboxnet_ip = VirtualBox::get_vboxnet_ip(VirtualBox::get_hostonly_adapter(machine_name)) else raise 'This script dose not support selected driver: ' + driver end yield self if block_given? end def setup_nfs_server # create record in local /etc/exports and restart nsfd puts "Update /etc/exports ..." `echo '\n/Users #{@dmachine_ip} -alldirs -mapall=#{@uid}:#{@gid}\n' | sudo tee -a /etc/exports` `awk '!a[$0]++' /etc/exports | sudo tee /etc/exports` # removes duplicate lines `sudo nfsd restart`; sleep 2 checkexports = `sudo nfsd checkexports 2>&1` if checkexports == '' puts ' > Done.' else raise 'exec `sudo nfsd checkexports`: ' + checkexports end end def setup_nfs_client # render bootlocal.sh and copy bootlocal.sh over to boot2docker # (this will override an existing /var/lib/boot2docker/bootlocal.sh) puts 'Update boot2docker virtual machine ...' ip = @vboxnet_ip first = true ERB.new(@bootlocal).result(binding).split("\n").each do |l| `docker-machine ssh #{@dmachine_name} 'echo \"#{l}\" | sudo tee #{first ? '' : '-a'} /var/lib/boot2docker/bootlocal.sh'` first = false end `docker-machine ssh #{@dmachine_name} 'sudo chmod +x /var/lib/boot2docker/bootlocal.sh'` `docker-machine ssh #{@dmachine_name} 'sudo sync'` puts "Restart #{@dmachine_name} ..." `docker-machine restart #{@dmachine_name}` puts ' > Done.' end def check puts "Check if NFS is mounted on docker-machine \"#{@dmachine_name}\"."; sleep 2 result = <<-EOS > failed: Try `docker-machine ssh #{@dmachine_name} df`. Output should include something like this: '#{@vboxnet_ip}:/Users [...] /Users' EOS `docker-machine ssh #{@dmachine_name} df`.each_line do |l| if l.chomp.match(/^#{@vboxnet_ip}:\/Users.*\/Users$/) result = ' > Done.' end end puts result end end module VirtualBox class << self def get_hostonly_adapter(machine_name) puts 'Get vbox hostonly adapter name ...' vboxnet_name = `VBoxManage showvminfo #{machine_name} --machinereadable | grep hostonlyadapter` .scan(/"(.*)"/).flatten.first.chomp unless vboxnet_name == '' puts ' > ' + vboxnet_name vboxnet_name else raise 'error: unable to find name of vboxnet' end end def get_vboxnet_ip(vboxnet_name) puts 'Get vbox net ip address ...' `VBoxManage list hostonlyifs`.split("\n\n").each do |vboxnet| if vboxnet.scan(/Name: *(.+?)\n/).flatten.first.chomp == vboxnet_name vboxip = vboxnet.scan(/IPAddress: *(.*)\n/).flatten.first.chomp puts ' > ' + vboxip return vboxip end end end end end def main options = { driver: 'virtualbox' } OptionParser.new do |op| op.on('-d', '--driver "virtualbox"', 'docker-machine driver (default:virtualbox)') {|v| options[:driver] = v } op.parse!(ARGV) end if ARGV.length != 1 puts "Usage: #{File.basename(__FILE__)} machine_name" exit 1 end machine_name = ARGV[0] driver = options[:driver] DockerMachineNfs.new(machine_name, driver) do |d| d.setup_nfs_server d.setup_nfs_client d.check end end main -
mattes revised this gist
Apr 14, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ `echo '\n/Users #{machine_ip} -alldirs -maproot=root\n' | sudo tee -a /etc/exports` `awk '!a[$0]++' /etc/exports | sudo tee /etc/exports` # removes duplicate lines `sudo nfsd restart`; sleep 2 puts `sudo nfsd checkexports` # render bootlocal.sh and copy bootlocal.sh over to boot2docker # (this will override an existing /var/lib/boot2docker/bootlocal.sh) -
mattes revised this gist
Apr 14, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ bootlocalsh = %Q(#/bin/bash sudo umount /Users sudo /usr/local/etc/init.d/nfs-client start sudo mount -t nfs -o noacl,async <%= vboxnet_ip %>:/Users /Users ) if ARGV.length != 1 -
mattes revised this gist
Apr 13, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,8 +49,7 @@ # create record in local /etc/exports and restart nsfd machine_ip = `docker-machine ip #{machine_name}`.chomp puts "Update /etc/exports ..." `echo '\n/Users #{machine_ip} -alldirs -maproot=root\n' | sudo tee -a /etc/exports` `awk '!a[$0]++' /etc/exports | sudo tee /etc/exports` # removes duplicate lines `sudo nfsd restart`; sleep 2 `sudo nfsd checkexports` -
mattes revised this gist
Apr 11, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # Usage # $ docker-machine create my-machine123 -d virtualbox # $ ruby <(curl -L https://git.io/vvvco) my-machine123 # https://gist.github.com/mattes/4d7f435d759ca2581347 require 'erb' -
mattes revised this gist
Apr 11, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ # Usage # $ docker-machine create my-machine123 -d virtualbox # $ ruby <(curl -L https://git.io/vvvsH) my-machine123 # https://gist.github.com/mattes/4d7f435d759ca2581347 require 'erb' -
mattes revised this gist
Apr 11, 2015 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,9 @@ #!/usr/bin/env ruby # Usage # $ docker-machine create my-machine123 -d virtualbox # $ ruby <(curl -L https://git.io/vvvsH) my-machine123 require 'erb' bootlocalsh = %Q(#/bin/bash -
mattes created this gist
Apr 11, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ #!/usr/bin/env ruby require 'erb' bootlocalsh = %Q(#/bin/bash sudo umount /Users sudo /usr/local/etc/init.d/nfs-client start sudo mount -t nfs <%= vboxnet_ip %>:/Users /Users ) if ARGV.length != 1 puts "usage: #{__FILE__} machine-name" exit 1 end machine_name = ARGV[0] print "Get vboxnet ip addres ..." # get host only adapter vboxnet_name = `VBoxManage showvminfo #{machine_name} --machinereadable | grep hostonlyadapter` vboxnet_name = vboxnet_name.scan(/"(.*)"/).flatten.first.chomp if vboxnet_name == '' puts "error: unable to find name of vboxnet" exit 1 end # get ip addr for vboxnet vboxnet_ip = '' vboxnets = `VBoxManage list hostonlyifs`.split("\n\n") vboxnets.each do |vboxnet| if vboxnet.scan(/Name: *(.+?)\n/).flatten.first.chomp == vboxnet_name vboxnet_ip = vboxnet.scan(/IPAddress: *(.*)\n/).flatten.first.chomp break end end if vboxnet_ip == '' puts "error: unable to find ip of vboxnet #{vboxnet_name}" exit 1 end print " #{vboxnet_ip}\n" # create record in local /etc/exports and restart nsfd machine_ip = `docker-machine ip #{machine_name}`.chomp puts "Update /etc/exports ..." # TODO why 501:20 in -mapall ?! `echo '\n/Users #{machine_ip} -alldirs -mapall=501:20\n' | sudo tee -a /etc/exports` `awk '!a[$0]++' /etc/exports | sudo tee /etc/exports` # removes duplicate lines `sudo nfsd restart`; sleep 2 `sudo nfsd checkexports` # render bootlocal.sh and copy bootlocal.sh over to boot2docker # (this will override an existing /var/lib/boot2docker/bootlocal.sh) puts "Update boot2docker virtual machine ..." bootlocalsh_rendered = ERB.new(bootlocalsh).result() first = true bootlocalsh_rendered.split("\n").each do |l| `docker-machine ssh #{machine_name} 'echo "#{l}" | sudo tee #{first ? '' : '-a'} /var/lib/boot2docker/bootlocal.sh'` first = false end `docker-machine ssh #{machine_name} 'sudo chmod +x /var/lib/boot2docker/bootlocal.sh'` puts "Restart #{machine_name} ..." `docker-machine restart #{machine_name}` puts "Done." puts puts "Run `docker-machine ssh #{machine_name} df` to check if NFS is mounted." puts "Output should include something like this: '#{vboxnet_ip}:/Users [...] /Users'"