Update Vagrantfile for tern
[integration.git] / test / legal / docker_license_analysis / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4 VM_MEMORY = 2 * 1024
5 VM_CPUS = 2
6 VM_DISK = 128
7 VM_STORAGE_POOL = "default"
8 VM_USER = "vagrant"
9
10 # Dockerfile to analyse
11 DOCKER_FILE = ENV["DOCKER_FILE_ANALYSE"] || "Dockerfile.sample"
12 DOCKER_FILE_PATH = "/home/vagrant/ternvenv/Dockerfile"
13 # Docker image to analyse (in form of "debian:latest").
14 # Takes precedence over DOCKER_FILE
15 DOCKER_IMAGE = ENV['DOCKER_IMAGE_ANALYSE']
16
17 $install_docker= <<-SCRIPT
18   apt-get update
19   apt-get install --yes \
20     apt-transport-https \
21     ca-certificates \
22     curl \
23     gnupg-agent \
24     software-properties-common
25   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
26   add-apt-repository \
27    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
28    $(lsb_release -cs) \
29    stable"
30   apt-get update
31   apt-get install --yes \
32     docker-ce docker-ce-cli containerd.io
33   groupadd -f docker
34   usermod -a -G docker $USER
35 SCRIPT
36
37 $install_python = <<-SCRIPT
38   apt-get update
39   apt-get install --yes \
40     python3.8 libpython3.8-dev python3-pip python3.8-venv python3-setuptools\
41     python3-apt \
42     attr bzip2 xz-utils zlib1g libxml2-dev libxslt1-dev \
43     findutils git gnupg2 tar util-linux
44   pip3 install --upgrade pip
45 SCRIPT
46
47 $install_tern = <<-SCRIPT
48   cd /home/$USER
49   python3 -m venv ternvenv
50   cd ternvenv
51   source bin/activate
52   pip3 install --upgrade pip
53   pip3 install --no-cache-dir tern scancode-toolkit[full]
54 SCRIPT
55
56 Vagrant.configure("2") do |config|
57   config.vm.box = "generic/ubuntu2004"
58   config.vm.hostname = "vagrant"
59
60   config.vm.provider :virtualbox do |v|
61     v.name = config.vm.hostname
62     v.memory = VM_MEMORY
63     v.cpus = VM_CPUS
64   end
65
66   config.vm.provider :libvirt do |v|
67     v.memory = VM_MEMORY
68     v.cpus = VM_CPUS
69     v.machine_virtual_size = VM_DISK
70     v.storage_pool_name = VM_STORAGE_POOL
71   end
72
73   config.vm.synced_folder '.', '/vagrant', disabled: true
74
75   config.vm.provision "install_docker", type: "shell" do |s|
76     s.privileged = true
77     s.env = {"DEBIAN_FRONTEND" => "noninteractive", "USER":VM_USER}
78     s.inline = $install_docker
79     s.reset = true
80   end
81
82   config.vm.provision "install_python", type: "shell" do |s|
83     s.privileged = true
84     s.env = {"DEBIAN_FRONTEND" => "noninteractive"}
85     s.inline = $install_python
86   end
87
88   config.vm.provision "install_tern", type: "shell" do |s|
89     s.privileged = false
90     s.env = {"USER":VM_USER}
91     s.inline = $install_tern
92   end
93
94   # Add the Dockerfile for analysis to the Vagrant box
95   config.vm.provision "file", source: DOCKER_FILE, destination: DOCKER_FILE_PATH
96
97   config.vm.provision "license_analysis", type: "shell" do |s|
98     s.privileged = false
99     s.env = {"IMAGE":DOCKER_IMAGE, "FILE":DOCKER_FILE_PATH}
100     s.path = "tools/analysis.sh"
101   end
102 end