# -*- mode: ruby -*- VAGRANTFILE_API_VERSION = "2" def command?(name) `which #{name} > /dev/null 2>&1` $?.success? end if Vagrant::VERSION == "1.8.7" then path = `which curl` if path.include?('/opt/vagrant/embedded/bin/curl') then puts "In Vagrant 1.8.7, curl is broken. Please use Vagrant 2.0.2 "\ "or run 'sudo rm -f /opt/vagrant/embedded/bin/curl' to fix the "\ "issue before provisioning. See "\ "https://github.com/mitchellh/vagrant/issues/7997 "\ "for reference." exit end end # Workaround: Vagrant removed the atlas.hashicorp.com to # vagrantcloud.com redirect in February 2018. The value of # DEFAULT_SERVER_URL in Vagrant versions less than 1.9.3 is # atlas.hashicorp.com, which means that removal broke the fetching and # updating of boxes (since the old URL doesn't work). See # https://github.com/hashicorp/vagrant/issues/9442 if Vagrant::DEFAULT_SERVER_URL == "atlas.hashicorp.com" Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com') end # Monkey patch https://github.com/hashicorp/vagrant/pull/10879 so we # can fall back to another provider if docker is not installed. begin require Vagrant.source_root.join("plugins", "providers", "docker", "provider") rescue LoadError else VagrantPlugins::DockerProvider::Provider.class_eval do method(:usable?).owner == singleton_class or def self.usable?(raise_error=false) VagrantPlugins::DockerProvider::Driver.new.execute("docker", "version") true rescue Vagrant::Errors::CommandUnavailable, VagrantPlugins::DockerProvider::Errors::ExecuteError raise if raise_error return false end end end Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # The Zulip development environment runs on 9991 on the guest. host_port = 9991 http_proxy = https_proxy = no_proxy = nil host_ip_addr = "127.0.0.1" # System settings for the virtual machine. vm_num_cpus = "2" vm_memory = "2048" ubuntu_mirror = "" config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.synced_folder ".", "/srv/zulip" vagrant_config_file = ENV['HOME'] + "/.zulip-vagrant-config" if File.file?(vagrant_config_file) IO.foreach(vagrant_config_file) do |line| line.chomp! key, value = line.split(nil, 2) case key when /^([#;]|$)/; # ignore comments when "HTTP_PROXY"; http_proxy = value when "HTTPS_PROXY"; https_proxy = value when "NO_PROXY"; no_proxy = value when "HOST_PORT"; host_port = value.to_i when "HOST_IP_ADDR"; host_ip_addr = value when "GUEST_CPUS"; vm_num_cpus = value when "GUEST_MEMORY_MB"; vm_memory = value when "UBUNTU_MIRROR"; ubuntu_mirror = value end end end if Vagrant.has_plugin?("vagrant-proxyconf") if !http_proxy.nil? config.proxy.http = http_proxy end if !https_proxy.nil? config.proxy.https = https_proxy end if !no_proxy.nil? config.proxy.no_proxy = no_proxy end elsif !http_proxy.nil? or !https_proxy.nil? # This prints twice due to https://github.com/hashicorp/vagrant/issues/7504 # We haven't figured out a workaround. puts 'You have specified value for proxy in ~/.zulip-vagrant-config file but did not ' \ 'install the vagrant-proxyconf plugin. To install it, run `vagrant plugin install ' \ 'vagrant-proxyconf` in a terminal. This error will appear twice.' exit end config.vm.network "forwarded_port", guest: 9991, host: host_port, host_ip: host_ip_addr config.vm.network "forwarded_port", guest: 9994, host: host_port + 3, host_ip: host_ip_addr # Specify Docker provider before VirtualBox provider so it's preferred. config.vm.provider "docker" do |d, override| d.build_dir = File.join(__dir__, "tools", "setup", "dev-vagrant-docker") d.build_args = ["--build-arg", "VAGRANT_UID=#{Process.uid}"] if !ubuntu_mirror.empty? d.build_args += ["--build-arg", "UBUNTU_MIRROR=#{ubuntu_mirror}"] end d.has_ssh = true d.create_args = ["--ulimit", "nofile=1024:65536"] end config.vm.provider "virtualbox" do |vb, override| override.vm.box = "ubuntu/bionic64" # An unnecessary log file gets generated when running vagrant up for the # first time with the Ubuntu Bionic box. This looks like it is being # caused upstream by the base box containing a Vagrantfile with a similar # line to the one below. # see https://github.com/hashicorp/vagrant/issues/9425 vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] # It's possible we can get away with just 1.5GB; more testing needed vb.memory = vm_memory vb.cpus = vm_num_cpus end $provision_script = <