forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
221 lines (187 loc) · 7.87 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# Copyright (c) 2012-2016 Codenvy, S.A.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Codenvy, S.A. - initial API and implementation
# Set to "<proto>://<user>:<pass>@<host>:<port>"
$http_proxy = ENV['HTTP_PROXY'] || ""
$https_proxy = ENV['HTTPS_PROXY'] || ""
$no_proxy = ENV['NO_PROXY'] || "localhost,127.0.0.1"
$che_version = ENV['CHE_VERSION'] || "nightly"
$ip = ENV['CHE_IP'] || "192.168.28.100"
$hostPort = (ENV['CHE_PORT'] || 8080).to_i
$containerPort = (ENV['CHE_CONTAINER_PORT'] || ($hostPort == -1 ? 8080 : $hostPort)).to_i
$user_data = ENV['CHE_DATA'] || "."
$vm_name = ENV['CHE_VM_NAME'] || "eclipse-che-vm"
$provisionProgress = ENV['PROVISION_PROGRESS'] || "basic"
Vagrant.configure(2) do |config|
puts ("ECLIPSE CHE: VAGRANT INSTALLER")
puts ("ECLIPSE CHE: REQUIRED: VIRTUALBOX 5.x")
puts ("ECLIPSE CHE: REQUIRED: VAGRANT 1.8.x")
puts ("")
if ($http_proxy.to_s != '' || $https_proxy.to_s != '') && !Vagrant.has_plugin?("vagrant-proxyconf")
puts ("You configured a proxy, but Vagrant's proxy plugin not detected.")
puts ("Install the plugin with: vagrant plugin install vagrant-proxyconf")
Process.kill 9, Process.pid
end
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = $http_proxy
config.proxy.https = $https_proxy
config.proxy.no_proxy = $no_proxy
end
config.vm.box = "boxcutter/centos72-docker"
config.vm.box_download_insecure = true
config.ssh.insert_key = false
if $ip.to_s.downcase == "dhcp"
config.vm.network :private_network, type: "dhcp"
else
config.vm.network :private_network, ip: $ip
end
if $hostPort != -1
config.vm.network "forwarded_port", guest: $containerPort, host: $hostPort
end
config.vm.synced_folder $user_data, "/home/user/che"
config.vm.define "che" do |che|
end
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.name = $vm_name
end
$script = <<-'SHELL'
HTTP_PROXY=$1
HTTPS_PROXY=$2
NO_PROXY=$3
CHE_VERSION=$4
IP=$5
PORT=$6
PROVISION_PROGRESS=$7
if [ "${IP,,}" = "dhcp" ]; then
echo "----------------------------------------"
echo "ECLIPSE CHE: CHECKING DYNAMIC IP ADDRESS"
echo "----------------------------------------"
DEV=$(grep -l "VAGRANT-BEGIN" /etc/sysconfig/network-scripts/ifcfg-*|xargs grep "DEVICE="|sort|tail -1|cut -d "=" -f 2)
if [ -z "${DEV}" ]; then
>&2 echo "Unable to find DHCP network device"
exit 1
fi
IP=$(ip addr show dev ${DEV} | sed -r -e '/inet [0-9]/!d;s/^[[:space:]]*inet ([^[:space:]/]+).*$/\1/')
if [ -z "${IP}" ]; then
>&2 echo "Unable to find DHCP network ip"
exit 1
fi
echo "IP: ${IP}"
echo
fi
if [ -n "$HTTP_PROXY" ] || [ -n "$HTTPS_PROXY" ]; then
echo "-------------------------------------"
echo "."
echo "ECLIPSE CHE: CONFIGURING SYSTEM PROXY"
echo "."
echo "-------------------------------------"
echo 'export HTTP_PROXY="'$HTTP_PROXY'"' >> /home/vagrant/.bashrc
echo 'export HTTPS_PROXY="'$HTTPS_PROXY'"' >> /home/vagrant/.bashrc
source /home/vagrant/.bashrc
# Configuring the Che properties file - mounted into Che container when it starts
echo 'http.proxy="'$HTTP_PROXY'"' >> /home/user/che/conf/che.properties
echo 'https.proxy="'$HTTPS_PROXY'"' >> /home/user/che/conf/che.properties
echo "HTTP PROXY set to: $HTTP_PROXY"
echo "HTTPS PROXY set to: $HTTPS_PROXY"
fi
function perform
{
local progress=$1
local command=$2
shift 2
local pid=""
case "$progress" in
extended)
# simulate tty environment to get full output of progress bars and percentages
printf "set timeout -1\nspawn %s\nexpect eof" "$command $*" | expect -f -
;;
basic|*)
$command "$@" &>/dev/null &
pid=$!
while kill -0 "$pid" >/dev/null 2>&1; do
printf "#"
sleep 10
done
wait $pid # return pid's exit code
;;
esac
}
echo "------------------------------------"
echo "ECLIPSE CHE: UPGRADING DOCKER ENGINE"
echo "------------------------------------"
if [ "$PROVISION_PROGRESS" = "extended" ]; then
# we sacrifice a few seconds of additional install time for much better progress afterwards
perform basic yum -y install expect
fi
perform $PROVISION_PROGRESS sudo yum -y update docker-engine
echo $(docker --version)
# Add the 'vagrant' user to the 'docker' group
usermod -aG docker vagrant &>/dev/null
# We need write access to this file to enable Che container to create other containers
sudo chmod 777 /var/run/docker.sock &>/dev/null
# Setup the overlay storage driver to eliminate errors
#sudo sed -i '/ExecStart=\/usr\/bin\/dockerd/c\ExecStart=\/usr\/bin\/dockerd --storage-driver=overlay' /lib/systemd/system/docker.service
# Configure Docker daemon with the proxy
if [ -n "$HTTP_PROXY" ] || [ -n "$HTTPS_PROXY" ]; then
mkdir /etc/systemd/system/docker.service.d
fi
if [ -n "$HTTP_PROXY" ]; then
printf "[Service]\nEnvironment=\"HTTP_PROXY=${HTTP_PROXY}\"" > /etc/systemd/system/docker.service.d/http-proxy.conf
printf ""
fi
if [ -n "$HTTPS_PROXY" ]; then
printf "[Service]\nEnvironment=\"HTTPS_PROXY=${HTTPS_PROXY}\"" > /etc/systemd/system/docker.service.d/https-proxy.conf
fi
if [ -n "$HTTP_PROXY" ] || [ -n "$HTTPS_PROXY" ]; then
printf "[Service]\nEnvironment=\"NO_PROXY=${NO_PROXY}\"" > /etc/systemd/system/docker.service.d/no-proxy.conf
fi
systemctl daemon-reload
systemctl restart docker
echo "--------------------------------------------------"
echo "ECLIPSE CHE: DOWNLOADING ECLIPSE CHE DOCKER IMAGES"
echo "--------------------------------------------------"
perform $PROVISION_PROGRESS docker pull codenvy/che-launcher:${CHE_VERSION}
perform $PROVISION_PROGRESS docker pull codenvy/che-server:${CHE_VERSION}
curl -sL https://raw.githubusercontent.com/eclipse/che/master/che.sh | tr -d '\15\32' > /home/vagrant/che.sh
chmod +x /home/vagrant/che.sh
SHELL
config.vm.provision "shell" do |s|
s.inline = $script
s.args = [$http_proxy, $https_proxy, $no_proxy, $che_version, $ip, $containerPort, $provisionProgress]
end
$script2 = <<-'SHELL'
IP=$1
PORT=$2
MAPPED_PORT=$3
export CHE_CONF_FOLDER=/home/user/che/conf/
export CHE_PORT=${PORT}
export CHE_VERSION=${CHE_VERSION}
export CHE_HOST_IP=172.17.0.1
export CHE_HOSTNAME=${CHE_IP}
export CHE_DATA_FOLDER=${CHE_DATA}
echo "--------------------------------"
echo "ECLIPSE CHE: BOOTING ECLIPSE CHE"
echo "--------------------------------"
/home/vagrant/che.sh restart &>/dev/null
if [ "${IP,,}" = "dhcp" ]; then
DEV=$(grep -l "VAGRANT-BEGIN" /etc/sysconfig/network-scripts/ifcfg-*|xargs grep "DEVICE="|sort|tail -1|cut -d "=" -f 2)
IP=$(ip addr show dev ${DEV} | sed -r -e '/inet [0-9]/!d;s/^[[:space:]]*inet ([^[:space:]/]+).*$/\1/')
fi
rm -f /home/user/che/.che_url
rm -f /home/user/che/.che_host_port
CHE_URL="http://${IP}:${PORT}"
echo "${CHE_URL}" > /home/user/che/.che_url
echo "${MAPPED_PORT}" > /home/user/che/.che_host_port
echo "ECLIPSE CHE READY AT: ${CHE_URL}"
SHELL
config.vm.provision "shell", run: "always" do |s|
s.inline = $script2
s.args = [$ip, $containerPort, $hostPort]
end
end