aboutsummaryrefslogtreecommitdiffstats
path: root/test/legal/docker_license_analysis/Vagrantfile
blob: f1123ff8f77910309198917cd4a4bb26a3a40dd9 (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
103
104
105
106
107
# -*- 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
  # TODO: currently scancode locks us to python3.6, they are currently
  # (10 Dec 2020) updating so check in a while
  add-apt-repository ppa:deadsnakes/ppa
  apt-get update
  apt-get install --yes \
    python3.6 libpython3.6-dev python3-pip python3.6-venv python3-setuptools\
    python3-apt \
    attr bzip2 xz-utils zlib1g libxml2-dev libxslt1-dev \
    findutils git gnupg2 tar util-linux
  update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
  update-alternatives --set python3 /usr/bin/python3.6
  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