blob: 774a02134d48d374e87458929a68ff22808aee44 [file] [log] [blame]
Pawel Wieczorek09a63572019-12-17 15:33:06 +01001# -*- mode: ruby -*-
2# -*- coding: utf-8 -*-
3
4host_ip = "192.168.121.1"
Pawel Wieczorek9ee12582020-01-07 15:26:52 +01005synced_folder = "/vagrant"
Pawel Wieczorek049202b2020-01-07 15:28:54 +01006houndd_bin = "${HOME}/go/bin/houndd"
7houndd_config = "${HOME}/config.json"
Pawel Wieczorek8c7373d2020-01-07 15:28:55 +01008key_file = "${HOME}/.ssh/id_rsa"
9api_base = "https://gerrit.onap.org/r"
10api_user = ENV.fetch('API_USER') { |user| abort("missing env: #{user}") }
11api_key = ENV.fetch('API_KEY') { |key| abort("missing env: #{key}") }
12onap_git = "git.onap.org"
13gerrit_port = "29418"
Pawel Wieczorek09a63572019-12-17 15:33:06 +010014
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
19SCRIPT
20
Pawel Wieczorek8c7373d2020-01-07 15:28:55 +010021$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 ""
25SCRIPT
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"
36SCRIPT
37
Pawel Wieczorek09a63572019-12-17 15:33:06 +010038Vagrant.configure("2") do |config|
39 config.vm.box = "generic/ubuntu1804"
Pawel Wieczorek9ee12582020-01-07 15:26:52 +010040 config.vm.synced_folder ".", synced_folder, type: "rsync", rsync__exclude: "Vagrantfile"
Pawel Wieczorek049202b2020-01-07 15:28:54 +010041 config.vm.network "forwarded_port", guest: 6080, host: 6080
Pawel Wieczorek09a63572019-12-17 15:33:06 +010042 config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
Pawel Wieczorek8c7373d2020-01-07 15:28:55 +010043 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
Pawel Wieczorek09a63572019-12-17 15:33:06 +010050 config.vm.provision "dependencies", type: :shell, inline: <<-SHELL
51 export DEBIAN_FRONTEND=noninteractive
52 apt-get update
Pawel Wieczorek049202b2020-01-07 15:28:54 +010053 apt-get install --assume-yes --quiet golang tmux
Pawel Wieczorek09a63572019-12-17 15:33:06 +010054 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
Pawel Wieczorek8c7373d2020-01-07 15:28:55 +010059 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
Pawel Wieczorek049202b2020-01-07 15:28:54 +010064 config.vm.provision "run_codesearch", type: :shell, privileged: false, inline: <<-SHELL
65 tmux new -d -s codesearch #{houndd_bin} -conf #{houndd_config}
Pawel Wieczorek9ee12582020-01-07 15:26:52 +010066 SHELL
Pawel Wieczorek09a63572019-12-17 15:33:06 +010067end