forked from apache/incubator-toree
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vagrantfile
201 lines (170 loc) · 6.21 KB
/
Vagrantfile
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
#
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<-SCRIPT
mkdir -p /var/lib/vagrant_dev_install_flags
function flag_is_set() {
if [ -e /var/lib/vagrant_dev_install_flags/$1 ]; then
return 0
else
return 1
fi
}
function set_flag() {
touch /var/lib/vagrant_dev_install_flags/$1
}
function unset_flag() {
rm -f /var/lib/vagrant_dev_install_flags/$1
}
function unset_all_flags() {
rm -f /var/lib/vagrant_dev_install_flags/*
}
# Set vagrant user pw
printf "vagrant:vagrant\n" | chpasswd
# Update before we go
apt-get update
# Install Java and other dependencies
if ! flag_is_set CORE_DEPS; then
apt-get -y install openjdk-7-jdk maven wget build-essential git uuid-dev && \
set_flag CORE_DEPS
fi
# Install IPython and ZeroMQ
IPYTHON_VERSION=3.2.1
if ! flag_is_set IPYTHON; then
apt-get -f -y install && \
apt-get -y install python3-pip python-dev libzmq-dev build-essential && \
cd /src && \
pip3 install ipython[notebook]==${IPYTHON_VERSION} && \
ipython profile create && \
set_flag IPYTHON
fi
if [ -z `which docker` ]; then
sudo apt-get update -y
sudo apt-get -y install apt-transport-https linux-image-extra-`uname -r`
printf "deb https://get.docker.com/ubuntu docker main\n" > /etc/apt/sources.list.d/docker.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo apt-get update -y
sudo apt-get install -y lxc-docker-1.4.1
sudo chown vagrant:vagrant /var/run/docker.sock
fi
# Installing R
if ! flag_is_set R; then
sudo sh -c 'printf "deb http://cran.cnr.Berkeley.edu/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list' && \
sudo apt-get update -y && \
sudo apt-get install r-base r-base-dev && \
sudo chmod 777 /usr/local/lib/R/site-library && \
set_flag R
fi
# Install scala and sbt (if not already installed)
cd /tmp
# If Scala is not installed, install it
if ! flag_is_set SCALA; then
apt-get install -f -y && \
apt-get install -y libjansi-java && \
apt-get install -f -y && \
wget --progress=bar:force http://www.scala-lang.org/files/archive/scala-2.10.4.deb && \
dpkg -i scala-2.10.4.deb && \
rm scala-2.10.4.deb && \
set_flag SCALA
fi
# If sbt is not installed, install it
if ! flag_is_set SBT; then
wget --progress=bar:force http://dl.bintray.com/sbt/debian/sbt-0.13.9.deb && \
dpkg -i sbt-0.13.9.deb && \
rm sbt-0.13.9.deb && \
set_flag SBT
fi
# Downloading Spark
SPARK_VERSION=1.5.1
if ! flag_is_set SPARK; then
cd /opt && \
wget http://apache.arvixe.com/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop2.3.tgz && \
tar xvzf spark-${SPARK_VERSION}-bin-hadoop2.3.tgz && \
ln -s spark-${SPARK_VERSION}-bin-hadoop2.3 spark && \
export SPARK_HOME=/opt/spark && \
set_flag SPARK
fi
# Add Spark Kernel json to IPython configuration
echo "Adding kernel.json"
mkdir -p /home/vagrant/.ipython/kernels/toree-kernel
cat << EOF > /home/vagrant/.ipython/kernels/toree-kernel/kernel.json
{
"display_name": "Toree",
"language_info": { "name": "scala" },
"argv": [
"/src/toree-kernel/dist/toree/bin/run.sh",
"--profile",
"{connection_file}"
],
"codemirror_mode": "scala",
"env": {
"SPARK_OPTS": "--conf=spark.cores.max=4 --driver-java-options='-Xms1024M -Xmx4096M -Dlog4j.logLevel=trace'",
"MAX_INTERPRETER_THREADS": "16",
"CAPTURE_STANDARD_OUT": "true",
"CAPTURE_STANDARD_ERR": "true",
"SEND_EMPTY_OUTPUT": "false",
"SPARK_HOME": "/opt/spark",
"PYTHONPATH": "/opt/spark/python:/opt/spark/python/lib/py4j-0.10.9-src.zip"
}
}
EOF
# Add Scala syntax highlighting support to custom.js of default profile
printf "Appending to profile_default custom.js\n"
(su vagrant
mkdir -p /home/vagrant/.ipython/profile_default/static/custom/
cat << EOF >> /home/vagrant/.ipython/profile_default/static/custom/custom.js
CodeMirror.requireMode('clike',function(){
"use strict";
CodeMirror.defineMode("scala", function(conf, parserConf) {
var scalaConf = {};
for (var prop in parserConf) {
if (parserConf.hasOwnProperty(prop)) {
scalaConf[prop] = parserConf[prop];
}
}
scalaConf.name = 'text/x-scala';
var mode = CodeMirror.getMode(conf, scalaConf);
return mode;
}, 'scala');
CodeMirror.defineMIME("text/x-spark", "spark", "scala");
})
EOF
)
chown -R vagrant.vagrant /home/vagrant/.ipython
SCRIPT
Vagrant.configure("2") do |config|
# Have the script install docker
config.vm.provision :shell, :inline => $script
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "trusty_ubuntu"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.hostname = "host-box"
# Mount the directory containing this file as /vagrant in the VM.
# Since this file is copied around we need to figure out where the docker files are
config.vm.synced_folder "./" , "/src/toree-kernel"
# Create a private network, which allows host-only access to the machine
# using a specific IP. Make sure this IP doesn't exist on your local network.
config.vm.network :private_network, ip: "192.168.44.44"
config.vm.network :forwarded_port, guest: 22, host: 2223
# Configure memory and cpus
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.name = "toree-kernel-vm"
end
end