github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/devenv/Vagrantfile (about) 1 # -*- mode: ruby -*- 2 # vi: set ft=ruby : 3 4 # This vagrantfile creates a VM with the development environment 5 # configured and ready to go. 6 # 7 # The setup script (env var $script) in this file installs docker. 8 # This is not in the setup.sh file because the docker install needs 9 # to be secure when running on a real linux machine. 10 # The docker environment that is installed by this script is not secure, 11 # it depends on the host being secure. 12 # 13 # At the end of the setup script in this file, a call is made 14 # to run setup.sh to create the developer environment. 15 16 # This is the mount point for the sync_folders of the source 17 SRCMOUNT = "/hyperledger" 18 LOCALDEV = "/local-dev" 19 20 $script = <<SCRIPT 21 set -x 22 23 echo "127.0.0.1 couchdb" | tee -a /etc/hosts 24 25 export DOCKER_STORAGE_BACKEND="#{ENV['DOCKER_STORAGE_BACKEND']}" 26 27 cd #{SRCMOUNT}/devenv 28 ./setup.sh 29 30 SCRIPT 31 32 Vagrant.require_version ">= 1.7.4" 33 Vagrant.configure('2') do |config| 34 config.vm.box = "ubuntu/xenial64" 35 36 config.vm.network :forwarded_port, guest: 7050, host: 7050, id: "orderer", host_ip: "localhost", auto_correct: true # fabric orderer service 37 config.vm.network :forwarded_port, guest: 7051, host: 7051, id: "peer", host_ip: "localhost", auto_correct: true # fabric peer service 38 config.vm.network :forwarded_port, guest: 7053, host: 7053, id: "peer_event", host_ip: "localhost", auto_correct: true # fabric peer event service 39 config.vm.network :forwarded_port, guest: 7054, host: 7054, id: "ca", host_ip: "localhost", auto_correct: true # fabric-ca service 40 config.vm.network :forwarded_port, guest: 5984, host: 15984, id: "couchdb", host_ip: "localhost", auto_correct: true # CouchDB service 41 config.vm.synced_folder "..", "#{SRCMOUNT}" 42 config.vm.synced_folder "..", "/opt/gopath/src/github.com/hyperledger/fabric" 43 config.vm.synced_folder ENV.fetch('LOCALDEVDIR', ".."), "#{LOCALDEV}" 44 if File.exist?("../../fabric-ca") 45 config.vm.synced_folder "../../fabric-ca", "/opt/gopath/src/github.com/hyperledger/fabric-ca" 46 end 47 48 config.vm.provider :virtualbox do |vb| 49 vb.name = "hyperledger" 50 vb.customize ['modifyvm', :id, '--memory', '4096'] 51 vb.cpus = 2 52 53 storage_backend = ENV['DOCKER_STORAGE_BACKEND'] 54 case storage_backend 55 when nil,"","aufs","AUFS" 56 # No extra work to be done 57 when "btrfs","BTRFS" 58 # Add a second disk for the btrfs volume 59 IO.popen("VBoxManage list systemproperties") { |f| 60 61 success = false 62 while line = f.gets do 63 # Find the directory where the machine images are stored 64 machine_folder = line.sub(/^Default machine folder:\s*/,"") 65 66 if line != machine_folder 67 btrfs_disk = File.join(machine_folder, vb.name, 'btrfs.vdi') 68 69 unless File.exist?(btrfs_disk) 70 # Create the disk if it doesn't already exist 71 vb.customize ['createhd', '--filename', btrfs_disk, '--format', 'VDI', '--size', 20 * 1024] 72 end 73 74 # Add the disk to the VM 75 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', btrfs_disk] 76 success = true 77 78 break 79 end 80 end 81 raise Vagrant::Errors::VagrantError.new, "Could not provision btrfs disk" if !success 82 } 83 else 84 raise Vagrant::Errors::VagrantError.new, "Unknown storage backend type: #{storage_backend}" 85 end 86 87 end 88 89 config.vm.provision :shell, inline: $script 90 end