aboutsummaryrefslogtreecommitdiffstats
path: root/test/legal/docker_license_analysis/Vagrantfile
blob: 5a0333942afeb71eba68beee67021c4d3c32a8ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- mode: ruby -*-
# vi: set ft=ruby :

VM_MEMORY = 2 * 1024
VM_CPUS = 2
VM_DISK = 128
VM_STORAGE_POOL = "default"
VM_USER = "vagrant"

# Dockerfile to analyse
DOCKER_FILE = ENV["DOCKER_FILE_ANALYSE"] || "Dockerfile.sample"
DOCKER_FILE_PATH = "/home/vagrant/ternvenv/Dockerfile"
# Docker image to analyse (in form of "debian:latest").
# Takes precedence over DOCKER_FILE
DOCKER_IMAGE = ENV['DOCKER_IMAGE_ANALYSE']

$install_docker= <<-SCRIPT
  apt-get update
  apt-get install --yes \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
  apt-get update
  apt-get install --yes \
    docker-ce docker-ce-cli containerd.io
  groupadd -f docker
  usermod -a -G docker $USER
SCRIPT

$install_python = <<-SCRIPT
  apt-get update
  apt-get install --yes \
    python3.8 libpython3.8-dev python3-pip python3.8-venv python3-setuptools\
    python3-apt \
    attr bzip2 xz-utils zlib1g libxml2-dev libxslt1-dev \
    findutils git gnupg2 tar util-linux
  pip3 install --upgrade pip
SCRIPT

$install_tern = <<-SCRIPT
  cd /home/$USER
  python3 -m venv ternvenv
  cd ternvenv
  source bin/activate
  pip3 install --upgrade pip
  pip3 install --no-cache-dir tern scancode-toolkit[full]
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2004"
  config.vm.hostname = "vagrant"

  config.vm.provider :virtualbox do |v|
    v.name = config.vm.hostname
    v.memory = VM_MEMORY
    v.cpus = VM_CPUS
  end

  config.vm.provider :libvirt do |v|
    v.memory = VM_MEMORY
    v.cpus = VM_CPUS
    v.machine_virtual_size = VM_DISK
    v.storage_pool_name = VM_STORAGE_POOL
  end

  config.vm.synced_folder '.', '/vagrant', disabled: true

  config.vm.provision "install_docker", type: "shell" do |s|
    s.privileged = true
    s.env = {"DEBIAN_FRONTEND" => "noninteractive", "USER":VM_USER}
    s.inline = $install_docker
    s.reset = true
  end

  config.vm.provision "install_python", type: "shell" do |s|
    s.privileged = true
    s.env = {"DEBIAN_FRONTEND" => "noninteractive"}
    s.inline = $install_python
  end

  config.vm.provision "install_tern", type: "shell" do |s|
    s.privileged = false
    s.env = {"USER":VM_USER}
    s.inline = $install_tern
  end

  # Add the Dockerfile for analysis to the Vagrant box
  config.vm.provision "file", source: DOCKER_FILE, destination: DOCKER_FILE_PATH

  config.vm.provision "license_analysis", type: "shell" do |s|
    s.privileged = false
    s.env = {"IMAGE":DOCKER_IMAGE, "FILE":DOCKER_FILE_PATH}
    s.path = "tools/analysis.sh"
  end
end