2 # -*- coding: utf-8 -*-
4 host_ip = "192.168.121.1"
5 synced_folder = "/vagrant"
6 houndd_bin = "${HOME}/go/bin/houndd"
7 houndd_config = "${HOME}/config.json"
8 key_file = "${HOME}/.ssh/id_rsa"
9 api_base = "https://gerrit.onap.org/r"
10 api_user = ENV.fetch('API_USER') { |user| abort("missing env: #{user}") }
11 api_key = ENV.fetch('API_KEY') { |key| abort("missing env: #{key}") }
12 onap_git = "git.onap.org"
15 $replace_dns = <<-SCRIPT
17 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
18 echo nameserver "$HOST_IP" | tee /etc/resolv.conf
21 $generate_key = <<-SCRIPT
23 echo "Generating SSH key (${KEY_FILE})"
24 ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
27 $upload_key = <<-SCRIPT
30 echo "Uploading SSH pubkey (${KEY_FILE}.pub) for user: ${API_USER}"
32 -u "${API_USER}:${API_KEY}" \
33 -d "@${KEY_FILE}.pub" \
34 -H "Content-Type: text/plain" \
35 -X POST "${API_BASE}/a/accounts/${API_USER}/sshkeys"
38 Vagrant.configure("2") do |config|
39 config.vm.box = "generic/ubuntu1804"
40 config.vm.synced_folder ".", synced_folder, type: "rsync", rsync__exclude: "Vagrantfile"
41 config.vm.network "forwarded_port", guest: 6080, host: 6080
42 config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
43 config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: key_file
44 config.vm.provision "upload_key", type: :shell do |s|
46 s.inline = $upload_key
47 s.args = [key_file, api_base]
48 s.env = {'API_USER': api_user, 'API_KEY': api_key}
50 config.vm.provision "dependencies", type: :shell, inline: <<-SHELL
51 export DEBIAN_FRONTEND=noninteractive
53 apt-get install --assume-yes --quiet golang tmux
55 config.vm.provision "binaries", type: :shell, privileged: false, inline: <<-SHELL
56 export GOPATH="${HOME}/go"
57 go get -u github.com/hound-search/hound/cmds/...
59 config.vm.provision "generate_config", type: :shell do |s|
61 s.inline = "python3 #{synced_folder}/create_config.py --ssh ${1} ${2} --git ${3} > #{houndd_config}"
62 s.args = [api_user, gerrit_port, onap_git]
64 config.vm.provision "run_codesearch", type: :shell, privileged: false, inline: <<-SHELL
65 tmux new -d -s codesearch #{houndd_bin} -conf #{houndd_config}