#Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
	config.vm.box = "bento/ubuntu-20.04"

	# Create a forwarded port mapping which allows access to a specific port
	# within the machine from a port on the host machine. In the example below,
	# accessing "localhost:8080" will access port 80 on the guest machine.
	#config.vm.network :forwarded_port, guest: 8000, host: 8000

	# Create a private network, which allows host-only access to the machine
	# using a specific IP.
	config.vm.network :private_network, ip: "192.168.22.60"
	config.vm.hostname = "clickhouse.dev"
	#config.vm.network :forwarded_port, guest: 9000, host: 9000
	config.vm.network :forwarded_port, guest: 8123, host: 8123

	# speedup filesystem
	config.vm.synced_folder "./", "/opt/minimetrika/", :mount_options => ['nolock,vers=3,udp,noatime,actimeo=1'], :export_options => ['async,insecure,no_subtree_check,no_acl,no_root_squash'], :nfs => true
	#config.vm.synced_folder "./nginx-log/", "/var/log/nginx/", :mount_options => ['nolock,vers=3,udp,noatime,actimeo=1'], :export_options => ['async,insecure,no_subtree_check,no_acl,no_root_squash'], :nfs => true

	# ssh key
	#config.vm.provision "file", source: "~/.ssh/id_rsa", destination: "/home/vagrant/.ssh/id_rsa"
	#config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "/home/vagrant/.ssh/id_rsa.pub"

	config.vm.provider :virtualbox do |vb|
		vb.customize ["modifyvm", :id, "--memory", "2048"]
		vb.customize ["modifyvm", :id, "--cpus", "2"]
		vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
		vb.customize ["modifyvm", :id, "--nestedpaging", "on"]

		# speed up network
	    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
	end

	config.vm.provision :shell, inline:  <<-SHELL
	sudo apt-get update
	sudo apt-get install -y nginx-extras mc
	sudo cp /vagrant/conf.example/nginx.conf /etc/nginx/sites-enabled/
	sudo cp -r /vagrant/conf.example/ssl /etc/nginx/
	sudo service nginx restart

	sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E0C56BD4    # optional
    echo "deb http://repo.yandex.ru/clickhouse/deb/stable/ main/" | sudo tee /etc/apt/sources.list.d/clickhouse.list
    sudo apt-get update
    sudo apt-get install -y clickhouse-server=1.1.54378 clickhouse-client=1.1.54378 clickhouse-common-static=1.1.54378
    sudo service clickhouse-server start

  	SHELL
end