Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 1 | # -*- mode: ruby -*- |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | host_ip = "192.168.121.1" |
Pawel Wieczorek | 9ee1258 | 2020-01-07 15:26:52 +0100 | [diff] [blame] | 5 | synced_folder = "/vagrant" |
Pawel Wieczorek | 049202b | 2020-01-07 15:28:54 +0100 | [diff] [blame] | 6 | houndd_bin = "${HOME}/go/bin/houndd" |
| 7 | houndd_config = "${HOME}/config.json" |
Pawel Wieczorek | 8c7373d | 2020-01-07 15:28:55 +0100 | [diff] [blame^] | 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" |
Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 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 | |
Pawel Wieczorek | 8c7373d | 2020-01-07 15:28:55 +0100 | [diff] [blame^] | 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 | |
Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 38 | Vagrant.configure("2") do |config| |
| 39 | config.vm.box = "generic/ubuntu1804" |
Pawel Wieczorek | 9ee1258 | 2020-01-07 15:26:52 +0100 | [diff] [blame] | 40 | config.vm.synced_folder ".", synced_folder, type: "rsync", rsync__exclude: "Vagrantfile" |
Pawel Wieczorek | 049202b | 2020-01-07 15:28:54 +0100 | [diff] [blame] | 41 | config.vm.network "forwarded_port", guest: 6080, host: 6080 |
Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 42 | config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip |
Pawel Wieczorek | 8c7373d | 2020-01-07 15:28:55 +0100 | [diff] [blame^] | 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 |
Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 50 | config.vm.provision "dependencies", type: :shell, inline: <<-SHELL |
| 51 | export DEBIAN_FRONTEND=noninteractive |
| 52 | apt-get update |
Pawel Wieczorek | 049202b | 2020-01-07 15:28:54 +0100 | [diff] [blame] | 53 | apt-get install --assume-yes --quiet golang tmux |
Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 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 |
Pawel Wieczorek | 8c7373d | 2020-01-07 15:28:55 +0100 | [diff] [blame^] | 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 |
Pawel Wieczorek | 049202b | 2020-01-07 15:28:54 +0100 | [diff] [blame] | 64 | config.vm.provision "run_codesearch", type: :shell, privileged: false, inline: <<-SHELL |
| 65 | tmux new -d -s codesearch #{houndd_bin} -conf #{houndd_config} |
Pawel Wieczorek | 9ee1258 | 2020-01-07 15:26:52 +0100 | [diff] [blame] | 66 | SHELL |
Pawel Wieczorek | 09a6357 | 2019-12-17 15:33:06 +0100 | [diff] [blame] | 67 | end |