Remove no longer needed "make" target
[integration.git] / bootstrap / codesearch / Vagrantfile
1 # -*- mode: ruby -*-
2 # -*- coding: utf-8 -*-
3
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"
13 gerrit_port = "29418"
14
15 $replace_dns = <<-SCRIPT
16   HOST_IP="$1"
17   rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
18   echo nameserver "$HOST_IP" | tee /etc/resolv.conf
19 SCRIPT
20
21 $generate_key = <<-SCRIPT
22   KEY_FILE="$1"
23   echo "Generating SSH key (${KEY_FILE})"
24   ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
25 SCRIPT
26
27 $upload_key = <<-SCRIPT
28   KEY_FILE="$1"
29   API_BASE="$2"
30   echo "Uploading SSH pubkey (${KEY_FILE}.pub) for user: ${API_USER}"
31   curl -sS \
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"
36 SCRIPT
37
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|
45     s.privileged = false
46     s.inline = $upload_key
47     s.args = [key_file, api_base]
48     s.env = {'API_USER': api_user, 'API_KEY': api_key}
49   end
50   config.vm.provision "dependencies", type: :shell, inline: <<-SHELL
51     export DEBIAN_FRONTEND=noninteractive
52     apt-get update
53     apt-get install --assume-yes --quiet golang tmux
54   SHELL
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/...
58   SHELL
59   config.vm.provision "generate_config", type: :shell do |s|
60     s.privileged = false
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]
63   end
64   config.vm.provision "run_codesearch", type: :shell, privileged: false, inline: <<-SHELL
65     tmux new -d -s codesearch #{houndd_bin} -conf #{houndd_config}
66   SHELL
67 end