|
| 1 | +# -*- mode: ruby -*- |
| 2 | +# vi: set ft=ruby : |
| 3 | + |
| 4 | +VM_NAME = "dynamic-v2.4" |
| 5 | +DYNAMIC_PATH = "/opt/dynamic" |
| 6 | + |
| 7 | +# ugly hack to prevent hashicorp's bitrot. See https://github.com/hashicorp/vagrant/issues/9442 |
| 8 | +# this setting is required for pre-2.0 vagrant, but causes an error as of 2.0.3, |
| 9 | +# remove entirely when confident nobody uses vagrant 1.x for anything. |
| 10 | +unless Vagrant::DEFAULT_SERVER_URL.frozen? |
| 11 | + Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com') |
| 12 | +end |
| 13 | + |
| 14 | +# All Vagrant configuration is done below. The "2" in Vagrant.configure |
| 15 | +# configures the configuration version (we support older styles for |
| 16 | +# backwards compatibility). Please don't change it unless you know what |
| 17 | +# you're doing. |
| 18 | +Vagrant.configure("2") do |config| |
| 19 | + # The most common configuration options are documented and commented below. |
| 20 | + # For a complete reference, please see the online documentation at |
| 21 | + # https://docs.vagrantup.com. |
| 22 | + |
| 23 | + # Every Vagrant development environment requires a box. You can search for |
| 24 | + # boxes at https://vagrantcloud.com/search. |
| 25 | + # Base on the Sandstorm snapshots of the official Debian 9 (stretch) box with vboxsf support. |
| 26 | + config.vm.box = "ubuntu/bionic64" |
| 27 | + |
| 28 | + # vagrant plugin install vagrant-disksize |
| 29 | + if Vagrant.has_plugin?("vagrant-disksize") then |
| 30 | + config.disksize.size = "50GB" |
| 31 | + end |
| 32 | + |
| 33 | + |
| 34 | + # Disable automatic box update checking. If you disable this, then |
| 35 | + # boxes will only be checked for updates when the user runs |
| 36 | + # `vagrant box outdated`. This is not recommended. |
| 37 | + # config.vm.box_check_update = false |
| 38 | + |
| 39 | + if Vagrant.has_plugin?("vagrant-vbguest") then |
| 40 | + # vagrant-vbguest is a Vagrant plugin that upgrades |
| 41 | + # the version of VirtualBox Guest Additions within each |
| 42 | + # guest. If you have the vagrant-vbguest plugin, then it |
| 43 | + # needs to know how to compile kernel modules, etc., and so |
| 44 | + # we give it this hint about operating system type. |
| 45 | + config.vm.guest = "ubuntu" |
| 46 | + end |
| 47 | + |
| 48 | + # Create a forwarded port mapping which allows access to a specific port |
| 49 | + # within the machine from a port on the host machine. In the example below, |
| 50 | + # accessing "localhost:8080" will access port 80 on the guest machine. |
| 51 | + # NOTE: This will enable public access to the opened port |
| 52 | + |
| 53 | + # Main net |
| 54 | + config.vm.network "forwarded_port", guest: 33300, host: 33300 # P2P |
| 55 | + config.vm.network "forwarded_port", guest: 33350, host: 33350, host_ip: "127.0.0.1" # RPC |
| 56 | + |
| 57 | + # Test net |
| 58 | + config.vm.network "forwarded_port", guest: 33400, host: 33400 # P2P |
| 59 | + config.vm.network "forwarded_port", guest: 33450, host: 33450, host_ip: "127.0.0.1" # RPC |
| 60 | + |
| 61 | + # ReqTest net |
| 62 | + config.vm.network "forwarded_port", guest: 33500, host: 33500 # P2P |
| 63 | + config.vm.network "forwarded_port", guest: 33550, host: 33550, host_ip: "127.0.0.1" # RPC |
| 64 | + |
| 65 | + # Create a private network, which allows host-only access to the machine |
| 66 | + # using a specific IP. |
| 67 | + # config.vm.network "private_network", ip: "192.168.33.10" |
| 68 | + |
| 69 | + # Create a public network, which generally matched to bridged network. |
| 70 | + # Bridged networks make the machine appear as another physical device on |
| 71 | + # your network. |
| 72 | + # config.vm.network "public_network" |
| 73 | + |
| 74 | + # Calculate the number of CPUs and the amount of RAM the system has, |
| 75 | + # in a platform-dependent way; further logic below. |
| 76 | + cpus = nil |
| 77 | + total_kB_ram = nil |
| 78 | + |
| 79 | + host = RbConfig::CONFIG['host_os'] |
| 80 | + if host =~ /darwin/ |
| 81 | + cpus = `sysctl -n hw.ncpu`.to_i |
| 82 | + total_kB_ram = `sysctl -n hw.memsize`.to_i / 1024 |
| 83 | + elsif host =~ /linux/ |
| 84 | + cpus = `nproc`.to_i |
| 85 | + total_kB_ram = `grep MemTotal /proc/meminfo | awk '{print $2}'`.to_i |
| 86 | + elsif host =~ /mingw/ |
| 87 | + # powershell may not be available on Windows XP and Vista, so wrap this in a rescue block |
| 88 | + begin |
| 89 | + cpus = `powershell -Command "(Get-WmiObject Win32_Processor -Property NumberOfLogicalProcessors | Select-Object -Property NumberOfLogicalProcessors | Measure-Object NumberOfLogicalProcessors -Sum).Sum"`.to_i |
| 90 | + total_kB_ram = `powershell -Command "[math]::Round((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory)"`.to_i / 1024 |
| 91 | + rescue |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | + # Use the same number of CPUs within Vagrant as the system, with 1 |
| 96 | + # as a default. |
| 97 | + # |
| 98 | + # Use at least 512MB of RAM, and if the system has more than 2GB of |
| 99 | + # RAM, use 1/4 of the system RAM. This seems a reasonable compromise |
| 100 | + # between having the Vagrant guest operating system not run out of |
| 101 | + # RAM entirely (which it basically would if we went much lower than |
| 102 | + # 512MB) and also allowing it to use up a healthily large amount of |
| 103 | + # RAM so it can run faster on systems that can afford it. |
| 104 | + if cpus.nil? or cpus.zero? |
| 105 | + cpus = 1 |
| 106 | + end |
| 107 | + if total_kB_ram.nil? or total_kB_ram < 2048000 |
| 108 | + assign_ram_mb = 512 |
| 109 | + else |
| 110 | + assign_ram_mb = (total_kB_ram / 1024 / 4) |
| 111 | + end |
| 112 | + |
| 113 | + # Actually apply these CPU/memory values to the providers. |
| 114 | + config.vm.provider :virtualbox do |vb, override| |
| 115 | + vb.cpus = cpus |
| 116 | + vb.memory = assign_ram_mb |
| 117 | + vb.name = VM_NAME |
| 118 | + vb.customize ["modifyvm", :id, "--nictype1", "virtio"] |
| 119 | + |
| 120 | + # enables symlinks for windows |
| 121 | + override.vm.synced_folder ".", DYNAMIC_PATH |
| 122 | + override.vm.synced_folder ".dynamic", "/home/vagrant/.dynamic" |
| 123 | + vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{DYNAMIC_PATH}", "1"] |
| 124 | + end |
| 125 | + |
| 126 | + config.vm.provider :libvirt do |libvirt, override| |
| 127 | + libvirt.cpus = cpus |
| 128 | + libvirt.memory = assign_ram_mb |
| 129 | + libvirt.default_prefix = VM_NAME |
| 130 | + |
| 131 | + # /opt/dynamic/dynamic and /root/.dynamic are used by vagrant-spk |
| 132 | + override.vm.synced_folder ".", DYNAMIC_PATH, type: "9p", accessmode: "passthrough" |
| 133 | + override.vm.synced_folder ".dynamic", "/home/vagrant/.dynamic", type: "9p", accessmode: "passthrough" |
| 134 | + end |
| 135 | + |
| 136 | + # View the documentation for the provider you are using for more |
| 137 | + # information on available options. |
| 138 | + |
| 139 | + # Enable provisioning with a shell script. Additional provisioners such as |
| 140 | + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the |
| 141 | + # documentation for more information about their specific syntax and use. |
| 142 | + # config.vm.provision "shell", inline: "bash #{DYNAMIC_PATH}/dynamic-devenv/scripts/setup.sh", keep_color: true, env: {"VAGRANT" => "1"} |
| 143 | + config.vm.provision "shell", inline: <<-SHELL |
| 144 | + sudo add-apt-repository -y ppa:bitcoin/bitcoin |
| 145 | + sudo apt-get update |
| 146 | + sudo apt-get install -qy libdb4.8-dev libdb4.8++-dev build-essential libtool autotools-dev autoconf pkg-config libssl-dev libcrypto++-dev libevent-dev git libboost-all-dev libminiupnpc-dev libzmq3-dev |
| 147 | + sudo bash -c 'echo "Dynamic in /opt/dynamic" >/etc/motd' |
| 148 | + cd /opt/dynamic && ./autogen.sh && ./configure --without-gui --disable-gpu && make -j12 |
| 149 | + SHELL |
| 150 | + |
| 151 | +end |
0 commit comments